initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / containers / Lists / FixedList / FixedList.H
blob6e5df0a7676ffdd27f54a60f225940b62832bfae
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::FixedList
28 Description
29     A 1D vector of objects of type \<T\> with a fixed size \<Size\>.
31 SourceFiles
32     FixedList.C
33     FixedListI.H
34     FixedListIO.C
36 \*---------------------------------------------------------------------------*/
38 #ifndef FixedList_H
39 #define FixedList_H
41 #include "label.H"
42 #include "Hash.H"
43 #include "autoPtr.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 namespace Foam
50 // Forward declaration of friend functions and operators
52 template<class T, label Size> class FixedList;
54 template<class T, label Size>
55 Istream& operator>>(Istream&, FixedList<T, Size>&);
57 template<class T, label Size>
58 Ostream& operator<<(Ostream&, const FixedList<T, Size>&);
60 template<class T> class UList;
61 template<class T> class SLList;
64 /*---------------------------------------------------------------------------*\
65                            Class FixedList Declaration
66 \*---------------------------------------------------------------------------*/
68 template<class T, label Size>
69 class FixedList
71     // Private data
73         //- Vector of values of type T of size Size.
74         T v_[Size];
77 public:
79     //- Hashing function class
80     template<class HashT=Hash<T> >
81     class Hash
82     :
83         public Foam::Hash<FixedList<T, Size> >
84     {
86     public:
88         inline Hash();
90         //- Rotating Hash. From http://burtleburtle.net/bob/hash/doobs.html.
91         label operator()(const FixedList<T, Size>& fl) const;
93         label operator()
94         (
95             const FixedList<T, Size>& fl,
96             const label tableSize
97         ) const;
98     };
101     // Constructors
103         //- Null constructor.
104         inline FixedList();
106         //- Construct from components
107         inline FixedList(const T v[Size]);
109         //- Construct from value
110         inline FixedList(const T&);
112         //- Construct from UList.
113         inline FixedList(const UList<T>&);
115         //- Construct from SLList.
116         inline FixedList(const SLList<T>&);
118         //- Copy constructor.
119         inline FixedList(const FixedList<T, Size>&);
121         //- Construct from Istream.
122         FixedList(Istream&);
124         //- Clone
125         inline autoPtr<FixedList<T, Size> > clone() const;
128     // Member functions
130         //- Return a null FixedList
131         static const FixedList<T, Size>& null();
134         // Access
136             //- Return the forward circular index, i.e. the next index
137             //  which returns to the first at the end of the list
138             inline label fcIndex(const label i) const;
140             //- Return the reverse circular index, i.e. the previous index
141             //  which returns to the last at the begining of the list
142             inline label rcIndex(const label i) const;
145         // Check
147             //- Check start is within valid range (0 ... size-1).
148             inline void checkStart(const label start) const;
150             //- Check size is within valid range (0 ... size).
151             inline void checkSize(const label size) const;
153             //- Check index i is within valid range (0 ... size-1).
154             inline void checkIndex(const label i) const;
157         // Edit
159             //- Dummy setSize function
160             //  needed to make FixedList consistent with List
161             inline void setSize(const label);
164         //- Write the FixedList as a dictionary entry
165         void writeEntry(Ostream& os) const;
167         //- Write the FixedList as a dictionary entry with keyword
168         void writeEntry(const word& keyword, Ostream& os) const;
171     // Member operators
173         //- Return subscript-checked element of FixedList.
174         inline T& operator[](const label);
176         //- Return subscript-checked element of constant FixedList.
177         inline const T& operator[](const label) const;
179         //- Assignment from array operator. Takes linear time.
180         inline void operator=(const T v[Size]);
182         //- Assignment from UList operator. Takes linear time.
183         inline void operator=(const UList<T>&);
185         //- Assignment from SLList operator. Takes linear time.
186         inline void operator=(const SLList<T>&);
188         //- Assignment of all entries to the given value
189         inline void operator=(const T&);
192     // STL type definitions
194         //- Type of values the FixedList contains.
195         typedef T value_type;
197         //- Type that can be used for storing into
198         //  FixedList::value_type objects.
199         typedef T& reference;
201         //- Type that can be used for storing into
202         //  constant FixedList::value_type objects
203         typedef const T& const_reference;
205         //- The type that can represent the difference between any two
206         //  FixedList iterator objects.
207         typedef label difference_type;
209         //- The type that can represent the size of a FixedList.
210         typedef label size_type;
213     // STL iterator
215         //- Random access iterator for traversing FixedList.
216         typedef T* iterator;
218         //- Return an iterator to begin traversing the FixedList.
219         inline iterator begin();
221         //- Return an iterator to end traversing the FixedList.
222         inline iterator end();
225     // STL const_iterator
227         //- Random access iterator for traversing FixedList.
228         typedef const T* const_iterator;
230         //- Return a const_iterator to begin traversing the
231         //  constant FixedList.
232         inline const_iterator begin() const;
234         //- Return a const_iterator to end traversing the
235         //  constant FixedList.
236         inline const_iterator end() const;
239     // STL reverse_iterator
241         //- Reverse iterator for reverse traversal of FixedList.
242         typedef T* reverse_iterator;
244         //- Return a reverse_iterator to begin reverse traversing the
245         //  FixedList.
246         inline reverse_iterator rbegin();
248         //- Return a reverse_iterator to end reverse traversing the
249         //  FixedList.
250         inline reverse_iterator rend();
253     // STL const_reverse_iterator
255         //- Reverse iterator for reverse traversal of constant FixedList.
256         typedef const T* const_reverse_iterator;
258         //- Return a const_reverse_iterator to begin reverse traversing the
259         //  FixedList.
260         inline const_reverse_iterator rbegin() const;
262         //- Return a const_reverse_iterator to end reverse traversing the
263         //  FixedList.
264         inline const_reverse_iterator rend() const;
267     // STL member functions
269         //- Return the number of elements in the FixedList.
270         inline label size() const;
272         //- Return size of the largest possible FixedList.
273         inline label max_size() const;
275         //- Return true if the FixedList is empty (i.e., if size() == 0).
276         inline bool empty() const;
278         //- Swap two FixedLists of the same type in constant time.
279         void swap(FixedList<T, Size>&);
282     // STL member operators
284         //- Equality operation on FixedLists of the same type.
285         //  Returns true when the FixedLists are elementwise equal
286         //  (using FixedList::value_type::operator==).  Takes linear time.
287         bool operator==(const FixedList<T, Size>&) const;
289         //- The opposite of the equality operation. Takes linear time.
290         bool operator!=(const FixedList<T, Size>&) const;
292         //- Compare two FixedLists lexicographically. Takes linear time.
293         bool operator<(const FixedList<T, Size>&) const;
295         //- Compare two FixedLists lexicographically. Takes linear time.
296         bool operator>(const FixedList<T, Size>&) const;
298         //- Return true if !(a > b). Takes linear time.
299         bool operator<=(const FixedList<T, Size>&) const;
301         //- Return true if !(a < b). Takes linear time.
302         bool operator>=(const FixedList<T, Size>&) const;
305     // IOstream operators
307         //- Read List from Istream, discarding contents of existing List.
308         friend Istream& operator>>
309         #ifndef __CINT__
310         <T, Size>
311         #endif
312         (Istream&, FixedList<T, Size>&);
314         // Write FixedList to Ostream.
315         friend Ostream& operator<<
316         #ifndef __CINT__
317         <T, Size>
318         #endif
319         (
320             Ostream&,
321             const FixedList<T, Size>&
322         );
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 } // End namespace Foam
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
332 #include "FixedListI.H"
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
336 #ifdef NoRepository
337 #   include "FixedList.C"
338 #endif
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
342 #endif
344 // ************************************************************************* //