1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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>
74 //- Size must be positive (non-zero) and also fit as a signed value
75 StaticAssert(Size && Size <= INT_MAX);
79 //- Vector of values of type T of size Size.
85 //- Hashing function class.
86 // Use Hasher directly for contiguous data. Otherwise hash incrementally.
87 template< class HashT=Hash<T> >
94 inline unsigned operator()
96 const FixedList<T, Size>&,
101 // Static Member Functions
103 //- Return a null FixedList
104 inline static const FixedList<T, Size>& null();
109 //- Null constructor.
112 //- Construct from components
113 inline FixedList(const T v[Size]);
115 //- Construct from value
116 inline FixedList(const T&);
118 //- Construct from UList.
119 inline FixedList(const UList<T>&);
121 //- Construct from SLList.
122 inline FixedList(const SLList<T>&);
124 //- Copy constructor.
125 inline FixedList(const FixedList<T, Size>&);
127 //- Construct from Istream.
131 inline autoPtr< FixedList<T, Size> > clone() const;
138 //- Return the forward circular index, i.e. the next index
139 // which returns to the first at the end of the list
140 inline label fcIndex(const label i) const;
142 //- Return the reverse circular index, i.e. the previous index
143 // which returns to the last at the beginning of the list
144 inline label rcIndex(const label i) const;
147 //- Return a const pointer to the first data element,
148 // similar to the STL front() method and the string::data() method
149 // This can be used (with caution) when interfacing with C code.
150 inline const T* cdata() const;
152 //- Return a pointer to the first data element,
153 // similar to the STL front() method and the string::data() method
154 // This can be used (with caution) when interfacing with C code.
160 //- Check start is within valid range (0 ... size-1).
161 inline void checkStart(const label start) const;
163 //- Check size is within valid range (0 ... size).
164 inline void checkSize(const label size) const;
166 //- Check index i is within valid range (0 ... size-1).
167 inline void checkIndex(const label i) const;
172 //- Dummy resize function
173 // needed to make FixedList consistent with List
174 inline void resize(const label);
176 //- Dummy setSize function
177 // needed to make FixedList consistent with List
178 inline void setSize(const label);
180 //- Copy (not transfer) the argument contents
181 // needed to make FixedList consistent with List
182 void transfer(const FixedList<T, Size>&);
184 //- Write the FixedList as a dictionary entry
185 void writeEntry(Ostream&) const;
187 //- Write the FixedList as a dictionary entry with keyword
188 void writeEntry(const word& keyword, Ostream&) const;
193 //- Return element of FixedList.
194 inline T& operator[](const label);
196 //- Return element of constant FixedList.
197 inline const T& operator[](const label) const;
199 //- Assignment from array operator. Takes linear time.
200 inline void operator=(const T v[Size]);
202 //- Assignment from UList operator. Takes linear time.
203 inline void operator=(const UList<T>&);
205 //- Assignment from SLList operator. Takes linear time.
206 inline void operator=(const SLList<T>&);
208 //- Assignment of all entries to the given value
209 inline void operator=(const T&);
212 // STL type definitions
214 //- Type of values the FixedList contains.
215 typedef T value_type;
217 //- Type that can be used for storing into
218 // FixedList::value_type objects.
219 typedef T& reference;
221 //- Type that can be used for storing into
222 // constant FixedList::value_type objects
223 typedef const T& const_reference;
225 //- The type that can represent the difference between any two
226 // FixedList iterator objects.
227 typedef label difference_type;
229 //- The type that can represent the size of a FixedList.
230 typedef label size_type;
235 //- Random access iterator for traversing FixedList.
238 //- Return an iterator to begin traversing the FixedList.
239 inline iterator begin();
241 //- Return an iterator to end traversing the FixedList.
242 inline iterator end();
245 // STL const_iterator
247 //- Random access iterator for traversing FixedList.
248 typedef const T* const_iterator;
250 //- Return const_iterator to begin traversing the constant FixedList.
251 inline const_iterator cbegin() const;
253 //- Return const_iterator to end traversing the constant FixedList.
254 inline const_iterator cend() const;
256 //- Return const_iterator to begin traversing the constant FixedList.
257 inline const_iterator begin() const;
259 //- Return const_iterator to end traversing the constant FixedList.
260 inline const_iterator end() const;
263 // STL reverse_iterator
265 //- Reverse iterator for reverse traversal of FixedList.
266 typedef T* reverse_iterator;
268 //- Return reverse_iterator to begin reverse traversing the FixedList.
269 inline reverse_iterator rbegin();
271 //- Return reverse_iterator to end reverse traversing the FixedList.
272 inline reverse_iterator rend();
275 // STL const_reverse_iterator
277 //- Reverse iterator for reverse traversal of constant FixedList.
278 typedef const T* const_reverse_iterator;
280 //- Return const_reverse_iterator to begin reverse traversing FixedList.
281 inline const_reverse_iterator crbegin() const;
283 //- Return const_reverse_iterator to end reverse traversing FixedList.
284 inline const_reverse_iterator crend() const;
286 //- Return const_reverse_iterator to begin reverse traversing FixedList.
287 inline const_reverse_iterator rbegin() const;
289 //- Return const_reverse_iterator to end reverse traversing FixedList.
290 inline const_reverse_iterator rend() const;
293 // STL member functions
295 //- Return the number of elements in the FixedList.
296 inline label size() const;
298 //- Return size of the largest possible FixedList.
299 inline label max_size() const;
301 //- Return true if the FixedList is empty (ie, size() is zero).
302 inline bool empty() const;
304 //- Swap two FixedLists of the same type in constant time.
305 void swap(FixedList<T, Size>&);
308 // STL member operators
310 //- Equality operation on FixedLists of the same type.
311 // Returns true when the FixedLists are elementwise equal
312 // (using FixedList::value_type::operator==). Takes linear time.
313 bool operator==(const FixedList<T, Size>&) const;
315 //- The opposite of the equality operation. Takes linear time.
316 bool operator!=(const FixedList<T, Size>&) const;
318 //- Compare two FixedLists lexicographically. Takes linear time.
319 bool operator<(const FixedList<T, Size>&) const;
321 //- Compare two FixedLists lexicographically. Takes linear time.
322 bool operator>(const FixedList<T, Size>&) const;
324 //- Return true if !(a > b). Takes linear time.
325 bool operator<=(const FixedList<T, Size>&) const;
327 //- Return true if !(a < b). Takes linear time.
328 bool operator>=(const FixedList<T, Size>&) const;
331 // IOstream operators
333 //- Read List from Istream, discarding contents of existing List.
334 friend Istream& operator>> <T, Size>
335 (Istream&, FixedList<T, Size>&);
337 // Write FixedList to Ostream.
338 friend Ostream& operator<< <T, Size>
341 const FixedList<T, Size>&
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 } // End namespace Foam
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 #include "FixedListI.H"
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 # include "FixedList.C"
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 // ************************************************************************* //