1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A 1D vector of objects of type \<T\> with a fixed size \<Size\>.
36 \*---------------------------------------------------------------------------*/
46 #include "StaticAssert.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 // Forward declaration of friend functions and operators
55 template<class T, unsigned Size> class FixedList;
57 template<class T, unsigned Size>
58 Istream& operator>>(Istream&, FixedList<T, Size>&);
60 template<class T, unsigned Size>
61 Ostream& operator<<(Ostream&, const FixedList<T, Size>&);
63 template<class T> class UList;
64 template<class T> class SLList;
67 /*---------------------------------------------------------------------------*\
68 Class FixedList Declaration
69 \*---------------------------------------------------------------------------*/
71 template<class T, unsigned Size>
75 //- Size must be positive (non-zero) and also fit as a signed value
76 StaticAssert(Size && Size <= INT_MAX);
82 //- Vector of values of type T of size Size.
88 //- Hashing function class.
89 // Use Hasher directly for contiguous data. Otherwise hash incrementally.
90 template< class HashT=Hash<T> >
98 inline unsigned operator()
100 const FixedList<T, Size>&,
105 // Static Member Functions
107 //- Return a null FixedList
108 inline static const FixedList<T, Size>& null();
113 //- Null constructor.
116 //- Construct from components
117 inline FixedList(const T v[Size]);
119 //- Construct from value
120 explicit inline FixedList(const T&);
122 //- Construct from UList.
123 inline FixedList(const UList<T>&);
125 //- Construct from SLList.
126 inline FixedList(const SLList<T>&);
128 //- Copy constructor.
129 inline FixedList(const FixedList<T, Size>&);
131 //- Construct from Istream.
135 inline autoPtr< FixedList<T, Size> > clone() const;
142 //- Return the forward circular index, i.e. the next index
143 // which returns to the first at the end of the list
144 inline label fcIndex(const label i) const;
146 //- Return the reverse circular index, i.e. the previous index
147 // which returns to the last at the beginning of the list
148 inline label rcIndex(const label i) const;
151 //- Return a const pointer to the first data element,
152 // similar to the STL front() method and the string::data() method
153 // This can be used (with caution) when interfacing with C code.
154 inline const T* cdata() const;
156 //- Return a pointer to the first data element,
157 // similar to the STL front() method and the string::data() method
158 // This can be used (with caution) when interfacing with C code.
164 //- Check start is within valid range (0 ... size-1).
165 inline void checkStart(const label start) const;
167 //- Check size is within valid range (0 ... size).
168 inline void checkSize(const label size) const;
170 //- Check index i is within valid range (0 ... size-1).
171 inline void checkIndex(const label i) const;
176 //- Dummy resize function
177 // needed to make FixedList consistent with List
178 inline void resize(const label);
180 //- Dummy setSize function
181 // needed to make FixedList consistent with List
182 inline void setSize(const label);
184 //- Copy (not transfer) the argument contents
185 // needed to make FixedList consistent with List
186 void transfer(const FixedList<T, Size>&);
188 //- Write the FixedList as a dictionary entry
189 void writeEntry(Ostream&) const;
191 //- Write the FixedList as a dictionary entry with keyword
192 void writeEntry(const word& keyword, Ostream&) const;
197 //- Return element of FixedList.
198 inline T& operator[](const label);
200 //- Return element of constant FixedList.
201 inline const T& operator[](const label) const;
203 //- Assignment from array operator. Takes linear time.
204 inline void operator=(const T v[Size]);
206 //- Assignment from UList operator. Takes linear time.
207 inline void operator=(const UList<T>&);
209 //- Assignment from SLList operator. Takes linear time.
210 inline void operator=(const SLList<T>&);
212 //- Assignment of all entries to the given value
213 inline void operator=(const T&);
216 // STL type definitions
218 //- Type of values the FixedList contains.
219 typedef T value_type;
221 //- Type that can be used for storing into
222 // FixedList::value_type objects.
223 typedef T& reference;
225 //- Type that can be used for storing into
226 // constant FixedList::value_type objects
227 typedef const T& const_reference;
229 //- The type that can represent the difference between any two
230 // FixedList iterator objects.
231 typedef label difference_type;
233 //- The type that can represent the size of a FixedList.
234 typedef label size_type;
239 //- Random access iterator for traversing FixedList.
242 //- Return an iterator to begin traversing the FixedList.
243 inline iterator begin();
245 //- Return an iterator to end traversing the FixedList.
246 inline iterator end();
249 // STL const_iterator
251 //- Random access iterator for traversing FixedList.
252 typedef const T* const_iterator;
254 //- Return const_iterator to begin traversing the constant FixedList.
255 inline const_iterator cbegin() const;
257 //- Return const_iterator to end traversing the constant FixedList.
258 inline const_iterator cend() const;
260 //- Return const_iterator to begin traversing the constant FixedList.
261 inline const_iterator begin() const;
263 //- Return const_iterator to end traversing the constant FixedList.
264 inline const_iterator end() const;
267 // STL reverse_iterator
269 //- Reverse iterator for reverse traversal of FixedList.
270 typedef T* reverse_iterator;
272 //- Return reverse_iterator to begin reverse traversing the FixedList.
273 inline reverse_iterator rbegin();
275 //- Return reverse_iterator to end reverse traversing the FixedList.
276 inline reverse_iterator rend();
279 // STL const_reverse_iterator
281 //- Reverse iterator for reverse traversal of constant FixedList.
282 typedef const T* const_reverse_iterator;
284 //- Return const_reverse_iterator to begin reverse traversing FixedList.
285 inline const_reverse_iterator crbegin() const;
287 //- Return const_reverse_iterator to end reverse traversing FixedList.
288 inline const_reverse_iterator crend() const;
290 //- Return const_reverse_iterator to begin reverse traversing FixedList.
291 inline const_reverse_iterator rbegin() const;
293 //- Return const_reverse_iterator to end reverse traversing FixedList.
294 inline const_reverse_iterator rend() const;
297 // STL member functions
299 //- Return the number of elements in the FixedList.
300 inline label size() const;
302 //- Return size of the largest possible FixedList.
303 inline label max_size() const;
305 //- Return true if the FixedList is empty (ie, size() is zero).
306 inline bool empty() const;
308 //- Swap two FixedLists of the same type in constant time.
309 void swap(FixedList<T, Size>&);
312 // STL member operators
314 //- Equality operation on FixedLists of the same type.
315 // Returns true when the FixedLists are elementwise equal
316 // (using FixedList::value_type::operator==). Takes linear time.
317 bool operator==(const FixedList<T, Size>&) const;
319 //- The opposite of the equality operation. Takes linear time.
320 bool operator!=(const FixedList<T, Size>&) const;
322 //- Compare two FixedLists lexicographically. Takes linear time.
323 bool operator<(const FixedList<T, Size>&) const;
325 //- Compare two FixedLists lexicographically. Takes linear time.
326 bool operator>(const FixedList<T, Size>&) const;
328 //- Return true if !(a > b). Takes linear time.
329 bool operator<=(const FixedList<T, Size>&) const;
331 //- Return true if !(a < b). Takes linear time.
332 bool operator>=(const FixedList<T, Size>&) const;
335 // IOstream operators
337 //- Read List from Istream, discarding contents of existing List.
340 friend Istream& operator>> <T, Size>
341 (Istream&, FixedList<T, Size>&);
343 // Write FixedList to Ostream.
344 friend Ostream& operator<< <T, Size>
347 const FixedList<T, Size>&
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 } // End namespace Foam
357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 #include "FixedListI.H"
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 # include "FixedList.C"
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 // ************************************************************************* //