|
|
|
FixedList.HGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2009 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 Foam::FixedList 00027 00028 Description 00029 A 1D vector of objects of type <T> with a fixed 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 "bool.H" 00042 #include "label.H" 00043 #include "uLabel.H" 00044 #include "Hash.H" 00045 #include "autoPtr.H" 00046 #include "StaticAssert.H" 00047 00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00049 00050 namespace Foam 00051 { 00052 00053 // Forward declaration of friend functions and operators 00054 00055 template<class T, unsigned Size> class FixedList; 00056 00057 template<class T, unsigned Size> 00058 Istream& operator>>(Istream&, FixedList<T, Size>&); 00059 00060 template<class T, unsigned Size> 00061 Ostream& operator<<(Ostream&, const FixedList<T, Size>&); 00062 00063 template<class T> class UList; 00064 template<class T> class SLList; 00065 00066 00067 /*---------------------------------------------------------------------------*\ 00068 Class FixedList Declaration 00069 \*---------------------------------------------------------------------------*/ 00070 00071 template<class T, unsigned Size> 00072 class FixedList 00073 { 00074 //- Size must be positive (non-zero) and also fit as a signed value 00075 StaticAssert(Size && Size <= INT_MAX); 00076 00077 // Private data 00078 00079 //- Vector of values of type T of size Size. 00080 T v_[Size]; 00081 00082 00083 public: 00084 00085 //- Hashing function class. 00086 // Use Hasher directly for contiguous data. Otherwise hash incrementally. 00087 template< class HashT=Hash<T> > 00088 class Hash 00089 { 00090 public: 00091 Hash() 00092 {} 00093 00094 inline unsigned operator() 00095 ( 00096 const FixedList<T, Size>&, 00097 unsigned seed = 0 00098 ) const; 00099 }; 00100 00101 // Static Member Functions 00102 00103 //- Return a null FixedList 00104 inline static const FixedList<T, Size>& null(); 00105 00106 00107 // Constructors 00108 00109 //- Null constructor. 00110 inline FixedList(); 00111 00112 //- Construct from components 00113 inline FixedList(const T v[Size]); 00114 00115 //- Construct from value 00116 inline FixedList(const T&); 00117 00118 //- Construct from UList. 00119 inline FixedList(const UList<T>&); 00120 00121 //- Construct from SLList. 00122 inline FixedList(const SLList<T>&); 00123 00124 //- Copy constructor. 00125 inline FixedList(const FixedList<T, Size>&); 00126 00127 //- Construct from Istream. 00128 FixedList(Istream&); 00129 00130 //- Clone 00131 inline autoPtr< FixedList<T, Size> > clone() const; 00132 00133 00134 // Member Functions 00135 00136 // Access 00137 00138 //- Return the forward circular index, i.e. the next index 00139 // which returns to the first at the end of the list 00140 inline label fcIndex(const label i) const; 00141 00142 //- Return the reverse circular index, i.e. the previous index 00143 // which returns to the last at the beginning of the list 00144 inline label rcIndex(const label i) const; 00145 00146 00147 //- Return a const pointer to the first data element, 00148 // similar to the STL front() method and the string::data() method 00149 // This can be used (with caution) when interfacing with C code. 00150 inline const T* cdata() const; 00151 00152 //- Return a pointer to the first data element, 00153 // similar to the STL front() method and the string::data() method 00154 // This can be used (with caution) when interfacing with C code. 00155 inline T* data(); 00156 00157 00158 // Check 00159 00160 //- Check start is within valid range (0 ... size-1). 00161 inline void checkStart(const label start) const; 00162 00163 //- Check size is within valid range (0 ... size). 00164 inline void checkSize(const label size) const; 00165 00166 //- Check index i is within valid range (0 ... size-1). 00167 inline void checkIndex(const label i) const; 00168 00169 00170 // Edit 00171 00172 //- Dummy resize function 00173 // needed to make FixedList consistent with List 00174 inline void resize(const label); 00175 00176 //- Dummy setSize function 00177 // needed to make FixedList consistent with List 00178 inline void setSize(const label); 00179 00180 //- Copy (not transfer) the argument contents 00181 // needed to make FixedList consistent with List 00182 void transfer(const FixedList<T, Size>&); 00183 00184 //- Write the FixedList as a dictionary entry 00185 void writeEntry(Ostream&) const; 00186 00187 //- Write the FixedList as a dictionary entry with keyword 00188 void writeEntry(const word& keyword, Ostream&) const; 00189 00190 00191 // Member operators 00192 00193 //- Return element of FixedList. 00194 inline T& operator[](const label); 00195 00196 //- Return element of constant FixedList. 00197 inline const T& operator[](const label) const; 00198 00199 //- Assignment from array operator. Takes linear time. 00200 inline void operator=(const T v[Size]); 00201 00202 //- Assignment from UList operator. Takes linear time. 00203 inline void operator=(const UList<T>&); 00204 00205 //- Assignment from SLList operator. Takes linear time. 00206 inline void operator=(const SLList<T>&); 00207 00208 //- Assignment of all entries to the given value 00209 inline void operator=(const T&); 00210 00211 00212 // STL type definitions 00213 00214 //- Type of values the FixedList contains. 00215 typedef T value_type; 00216 00217 //- Type that can be used for storing into 00218 // FixedList::value_type objects. 00219 typedef T& reference; 00220 00221 //- Type that can be used for storing into 00222 // constant FixedList::value_type objects 00223 typedef const T& const_reference; 00224 00225 //- The type that can represent the difference between any two 00226 // FixedList iterator objects. 00227 typedef label difference_type; 00228 00229 //- The type that can represent the size of a FixedList. 00230 typedef label size_type; 00231 00232 00233 // STL iterator 00234 00235 //- Random access iterator for traversing FixedList. 00236 typedef T* iterator; 00237 00238 //- Return an iterator to begin traversing the FixedList. 00239 inline iterator begin(); 00240 00241 //- Return an iterator to end traversing the FixedList. 00242 inline iterator end(); 00243 00244 00245 // STL const_iterator 00246 00247 //- Random access iterator for traversing FixedList. 00248 typedef const T* const_iterator; 00249 00250 //- Return const_iterator to begin traversing the constant FixedList. 00251 inline const_iterator cbegin() const; 00252 00253 //- Return const_iterator to end traversing the constant FixedList. 00254 inline const_iterator cend() const; 00255 00256 //- Return const_iterator to begin traversing the constant FixedList. 00257 inline const_iterator begin() const; 00258 00259 //- Return const_iterator to end traversing the constant FixedList. 00260 inline const_iterator end() const; 00261 00262 00263 // STL reverse_iterator 00264 00265 //- Reverse iterator for reverse traversal of FixedList. 00266 typedef T* reverse_iterator; 00267 00268 //- Return reverse_iterator to begin reverse traversing the FixedList. 00269 inline reverse_iterator rbegin(); 00270 00271 //- Return reverse_iterator to end reverse traversing the FixedList. 00272 inline reverse_iterator rend(); 00273 00274 00275 // STL const_reverse_iterator 00276 00277 //- Reverse iterator for reverse traversal of constant FixedList. 00278 typedef const T* const_reverse_iterator; 00279 00280 //- Return const_reverse_iterator to begin reverse traversing FixedList. 00281 inline const_reverse_iterator crbegin() const; 00282 00283 //- Return const_reverse_iterator to end reverse traversing FixedList. 00284 inline const_reverse_iterator crend() const; 00285 00286 //- Return const_reverse_iterator to begin reverse traversing FixedList. 00287 inline const_reverse_iterator rbegin() const; 00288 00289 //- Return const_reverse_iterator to end reverse traversing FixedList. 00290 inline const_reverse_iterator rend() const; 00291 00292 00293 // STL member functions 00294 00295 //- Return the number of elements in the FixedList. 00296 inline label size() const; 00297 00298 //- Return size of the largest possible FixedList. 00299 inline label max_size() const; 00300 00301 //- Return true if the FixedList is empty (ie, size() is zero). 00302 inline bool empty() const; 00303 00304 //- Swap two FixedLists of the same type in constant time. 00305 void swap(FixedList<T, Size>&); 00306 00307 00308 // STL member operators 00309 00310 //- Equality operation on FixedLists of the same type. 00311 // Returns true when the FixedLists are elementwise equal 00312 // (using FixedList::value_type::operator==). Takes linear time. 00313 bool operator==(const FixedList<T, Size>&) const; 00314 00315 //- The opposite of the equality operation. Takes linear time. 00316 bool operator!=(const FixedList<T, Size>&) const; 00317 00318 //- Compare two FixedLists lexicographically. Takes linear time. 00319 bool operator<(const FixedList<T, Size>&) const; 00320 00321 //- Compare two FixedLists lexicographically. Takes linear time. 00322 bool operator>(const FixedList<T, Size>&) const; 00323 00324 //- Return true if !(a > b). Takes linear time. 00325 bool operator<=(const FixedList<T, Size>&) const; 00326 00327 //- Return true if !(a < b). Takes linear time. 00328 bool operator>=(const FixedList<T, Size>&) const; 00329 00330 00331 // IOstream operators 00332 00333 //- Read List from Istream, discarding contents of existing List. 00334 friend Istream& operator>> <T, Size> 00335 (Istream&, FixedList<T, Size>&); 00336 00337 // Write FixedList to Ostream. 00338 friend Ostream& operator<< <T, Size> 00339 ( 00340 Ostream&, 00341 const FixedList<T, Size>& 00342 ); 00343 }; 00344 00345 00346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00347 00348 } // End namespace Foam 00349 00350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00351 00352 #include "FixedListI.H" 00353 00354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00355 00356 #ifdef NoRepository 00357 # include "FixedList.C" 00358 #endif 00359 00360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00361 00362 #endif 00363 00364 // ************************************************************************* // |