![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 FixedList<T, Size> 00027 00028 Description 00029 FixedList<T, Size> is a 1D vector of objects of type T of size Size. 00030 00031 SourceFiles 00032 FixedList.C 00033 FixedListI.H 00034 FixedListIO.C 00035 00036 \*---------------------------------------------------------------------------*/ 00037 00038 #ifndef FixedList_H 00039 #define FixedList_H 00040 00041 #include "label.H" 00042 #include "Hash.H" 00043 #include "autoPtr.H" 00044 00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00046 00047 namespace Foam 00048 { 00049 00050 // * * * * * * Forward declaration of template friend fuctions * * * * * * * // 00051 00052 template<class T, label Size> class FixedList; 00053 00054 template<class T, label Size> 00055 Istream& operator>>(Istream&, FixedList<T, Size>&); 00056 00057 template<class T, label Size> 00058 Ostream& operator<<(Ostream&, const FixedList<T, Size>&); 00059 00060 template<class T> class UList; 00061 template<class T> class SLList; 00062 00063 00064 /*---------------------------------------------------------------------------*\ 00065 Class FixedList Declaration 00066 \*---------------------------------------------------------------------------*/ 00067 00068 template<class T, label Size> 00069 class FixedList 00070 { 00071 // Private data 00072 00073 //- Vector of values of type T of size Size. 00074 T v_[Size]; 00075 00076 00077 public: 00078 00079 //- Hashing function class 00080 template<class HashT=Hash<T> > 00081 class Hash 00082 : 00083 public Foam::Hash<FixedList<T, Size> > 00084 { 00085 00086 public: 00087 00088 inline Hash(); 00089 00090 //- Rotating Hash. From http://burtleburtle.net/bob/hash/doobs.html. 00091 label operator()(const FixedList<T, Size>& fl) const; 00092 00093 label operator() 00094 ( 00095 const FixedList<T, Size>& fl, 00096 const label tableSize 00097 ) const; 00098 }; 00099 00100 00101 // Constructors 00102 00103 //- Null constructor. 00104 inline FixedList(); 00105 00106 //- Construct from components 00107 inline FixedList(const T v[Size]); 00108 00109 //- Construct from value 00110 inline FixedList(const T&); 00111 00112 //- Construct from UList. 00113 inline FixedList(const UList<T>&); 00114 00115 //- Construct from SLList. 00116 inline FixedList(const SLList<T>&); 00117 00118 //- Copy constructor. 00119 inline FixedList(const FixedList<T, Size>&); 00120 00121 //- Construct from Istream. 00122 FixedList(Istream&); 00123 00124 //- Clone 00125 inline autoPtr<FixedList<T, Size> > clone() const; 00126 00127 00128 // Member functions 00129 00130 //- Return a null FixedList 00131 static FixedList<T, Size>& null(); 00132 00133 00134 // Access 00135 00136 //- Return the forward circular index, i.e. the next index 00137 // which returns to the first at the end of the list 00138 inline label fcIndex(const label i) const; 00139 00140 //- Return the reverse circular index, i.e. the previous index 00141 // which returns to the last at the begining of the list 00142 inline label rcIndex(const label i) const; 00143 00144 00145 // Check 00146 00147 //- Check start is within valid range (0 ... size-1). 00148 inline void checkStart(const label start) const; 00149 00150 //- Check size is within valid range (0 ... size). 00151 inline void checkSize(const label size) const; 00152 00153 //- Check index i is within valid range (0 ... size-1). 00154 inline void checkIndex(const label i) const; 00155 00156 00157 // Edit 00158 00159 //- Dummy setSize function 00160 // needed to make FixedList consistent with List 00161 inline void setSize(const label); 00162 00163 00164 //- Write the FixedList as a dictionary entry 00165 void writeEntry(Ostream& os) const; 00166 00167 //- Write the FixedList as a dictionary entry with keyword 00168 void writeEntry(const word& keyword, Ostream& os) const; 00169 00170 00171 // Member operators 00172 00173 //- Return subscript-checked element of FixedList. 00174 inline T& operator[](const label); 00175 00176 //- Return subscript-checked element of constant FixedList. 00177 inline const T& operator[](const label) const; 00178 00179 //- Assignment from array operator. Takes linear time. 00180 inline void operator=(const T v[Size]); 00181 00182 //- Assignment from UList operator. Takes linear time. 00183 inline void operator=(const UList<T>&); 00184 00185 //- Assignment from SLList operator. Takes linear time. 00186 inline void operator=(const SLList<T>&); 00187 00188 //- Assignment of all entries to the given value 00189 inline void operator=(const T&); 00190 00191 00192 // STL type definitions 00193 00194 //- Type of values the FixedList contains. 00195 typedef T value_type; 00196 00197 //- Type that can be used for storing into 00198 // FixedList::value_type objects. 00199 typedef T& reference; 00200 00201 //- Type that can be used for storing into 00202 // constant FixedList::value_type objects 00203 typedef const T& const_reference; 00204 00205 //- The type that can represent the difference between any two 00206 // FixedList iterator objects. 00207 typedef label difference_type; 00208 00209 //- The type that can represent the size of a FixedList. 00210 typedef label size_type; 00211 00212 00213 // STL iterator 00214 00215 //- Random access iterator for traversing FixedList. 00216 typedef T* iterator; 00217 00218 //- Return an iterator to begin traversing the FixedList. 00219 inline iterator begin(); 00220 00221 //- Return an iterator to end traversing the FixedList. 00222 inline iterator end(); 00223 00224 00225 // STL const_iterator 00226 00227 //- Random access iterator for traversing FixedList. 00228 typedef const T* const_iterator; 00229 00230 //- Return a const_iterator to begin traversing the 00231 // constant FixedList. 00232 inline const_iterator begin() const; 00233 00234 //- Return a const_iterator to end traversing the 00235 // constant FixedList. 00236 inline const_iterator end() const; 00237 00238 00239 // STL reverse_iterator 00240 00241 //- Reverse iterator for reverse traversal of FixedList. 00242 typedef T* reverse_iterator; 00243 00244 //- Return a reverse_iterator to begin reverse traversing the 00245 // FixedList. 00246 inline reverse_iterator rbegin(); 00247 00248 //- Return a reverse_iterator to end reverse traversing the 00249 // FixedList. 00250 inline reverse_iterator rend(); 00251 00252 00253 // STL const_reverse_iterator 00254 00255 //- Reverse iterator for reverse traversal of constant FixedList. 00256 typedef const T* const_reverse_iterator; 00257 00258 //- Return a const_reverse_iterator to begin reverse traversing the 00259 // FixedList. 00260 inline const_reverse_iterator rbegin() const; 00261 00262 //- Return a const_reverse_iterator to end reverse traversing the 00263 // FixedList. 00264 inline const_reverse_iterator rend() const; 00265 00266 00267 // STL member functions 00268 00269 //- Return the number of elements in the FixedList. 00270 inline label size() const; 00271 00272 //- Return size of the largest possible FixedList. 00273 inline label max_size() const; 00274 00275 //- Return true if the FixedList is empty (i.e., if size() == 0). 00276 inline bool empty() const; 00277 00278 //- Swap two FixedLists of the same type in constant time. 00279 void swap(FixedList<T, Size>&); 00280 00281 00282 // STL member operators 00283 00284 //- Equality operation on FixedLists of the same type. 00285 // Returns true when the FixedLists are elementwise equal 00286 // (using FixedList::value_type::operator==). Takes linear time. 00287 bool operator==(const FixedList<T, Size>&) const; 00288 00289 //- The opposite of the equality operation. Takes linear time. 00290 bool operator!=(const FixedList<T, Size>&) const; 00291 00292 //- Compare two FixedLists lexicographically. Takes linear time. 00293 bool operator<(const FixedList<T, Size>&) const; 00294 00295 //- Compare two FixedLists lexicographically. Takes linear time. 00296 bool operator>(const FixedList<T, Size>&) const; 00297 00298 //- Return true if !(a > b). Takes linear time. 00299 bool operator<=(const FixedList<T, Size>&) const; 00300 00301 //- Return true if !(a < b). Takes linear time. 00302 bool operator>=(const FixedList<T, Size>&) const; 00303 00304 00305 // IOstream operators 00306 00307 //- Read List from Istream, discarding contents of existing List. 00308 friend Istream& operator>> <T>(Istream&, FixedList<T, Size>&); 00309 00310 // Write FixedList to Ostream. 00311 friend Ostream& operator<< <T, Size> 00312 ( 00313 Ostream&, 00314 const FixedList<T, Size>& 00315 ); 00316 }; 00317 00318 00319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00320 00321 } // End namespace Foam 00322 00323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00324 00325 # include "FixedListI.H" 00326 00327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00328 00329 #ifdef NoRepository 00330 # include "FixedList.C" 00331 #endif 00332 00333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00334 00335 #endif 00336 00337 // ************************************************************************* //