Intrepid
Intrepid_MiniTensor_Storage.i.h
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions: Alejandro Mota (amota@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #if !defined(Intrepid_MiniTensor_Storage_i_h)
43 #define Intrepid_MiniTensor_Storage_i_h
44 
45 namespace Intrepid {
46 namespace MiniTensor {
47 
48 //
49 // Raw pointer storage
50 //
51 template<typename T>
52 inline
54  size_(0),
55  pointer_(NULL)
56 {
57  return;
58 }
59 
60 template<typename T>
61 inline
62 StorageRaw<T>::StorageRaw(Index const number_entries) :
63  size_(number_entries),
64  pointer_(NULL)
65 {
66  resize(number_entries);
67  return;
68 }
69 
70 template<typename T>
71 inline
73 {
74  clear();
75  return;
76 }
77 
78 template<typename T>
79 inline
80 T const &
81 StorageRaw<T>::operator[](Index const i) const
82 {
83  assert(i < size());
84  return pointer_[i];
85 }
86 
87 template<typename T>
88 inline
89 T &
91 {
92  assert(i < size());
93  return pointer_[i];
94 }
95 
96 template<typename T>
97 inline
98 Index
100 {
101  return size_;
102 }
103 
104 template<typename T>
105 inline
106 void
107 StorageRaw<T>::resize(Index const number_entries)
108 {
109  if (number_entries == size()) {
110  return;
111  }
112 
113  clear();
114 
115  pointer_ = new T[number_entries];
116 
117  size_ = number_entries;
118 
119  return;
120 }
121 
122 template<typename T>
123 inline
124 void
126 {
127  if (pointer_ != NULL) {
128  delete [] pointer_;
129  pointer_ = NULL;
130  size_ = 0;
131  }
132  return;
133 }
134 
135 //
136 // STL vector storage
137 //
138 template<typename T>
139 inline
141 {
142  return;
143 }
144 
145 template<typename T>
146 inline
147 StorageSTLVector<T>::StorageSTLVector(Index const number_entries)
148 {
149  resize(number_entries);
150  return;
151 }
152 
153 template<typename T>
154 inline
156 {
157  return;
158 }
159 
160 template<typename T>
161 inline
162 T const &
164 {
165  assert(i < size());
166  return storage_[i];
167 }
168 
169 template<typename T>
170 inline
171 T &
173 {
174  assert(i < size());
175  return storage_[i];
176 }
177 
178 template<typename T>
179 inline
180 Index
182 {
183  return storage_.size();
184 }
185 
186 template<typename T>
187 inline
188 void
189 StorageSTLVector<T>::resize(Index const number_entries)
190 {
191  storage_.resize(number_entries);
192  return;
193 }
194 
195 template<typename T>
196 inline
197 void
199 {
200  storage_.clear();
201  return;
202 }
203 
204 //
205 // Teuchos RCP array storage
206 //
207 template<typename T>
208 inline
210  storage_(Teuchos::null)
211 {
212  return;
213 }
214 
215 template<typename T>
216 inline
217 StorageRCPArray<T>::StorageRCPArray(Index const number_entries) :
218  storage_(Teuchos::null)
219 {
220  resize(number_entries);
221  return;
222 }
223 
224 template<typename T>
225 inline
227 {
228  return;
229 }
230 
231 template<typename T>
232 inline
233 T const &
234 StorageRCPArray<T>::operator[](Index const i) const
235 {
236  assert(i < size());
237  return storage_[i];
238 }
239 
240 template<typename T>
241 inline
242 T &
244 {
245  assert(i < size());
246  return storage_[i];
247 }
248 
249 template<typename T>
250 inline
251 Index
253 {
254  return storage_.size();
255 }
256 
257 template<typename T>
258 inline
259 void
260 StorageRCPArray<T>::resize(Index const number_entries)
261 {
262  storage_.resize(number_entries);
263  return;
264 }
265 
266 template<typename T>
267 inline
268 void
270 {
271  storage_.clear();
272  return;
273 }
274 
275 } // namespace MiniTensor
276 } // namespace Intrepid
277 
278 #endif // Intrepid_MiniTensor_Storage_i_h
T const & operator[](Index const i) const
void resize(Index const number_entries)