1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh 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 3 of the License, or (at your
14 option) any later version.
16 cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
28 A dynamic list is a 1-D vector of objects of type T which resizes
29 itself as necessary to accept the new objects. Internal storage
30 is a 2-D graph with a fixed size of the chunks used to store the data.
31 This way the data does not get copied every time array is resized, but
32 only the pointers to the chunks of data.
38 \*---------------------------------------------------------------------------*/
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
54 template<class T, label Offset>
57 template<class T, label Offset>
61 const LongList<T, Offset>&
63 template<class T, label Offset>
70 /*---------------------------------------------------------------------------*\
71 Class LongList Declaration
72 \*---------------------------------------------------------------------------*/
74 template<class T, label Offset = 19>
78 //- number of allocated elements
81 //- number of elements in the list
84 //- number of used blocks of data
87 //- maximum number of blocks that can be allocated
88 //- without reallocating the list containing pointers
89 //- to the chunks of data
90 label numAllocatedBlocks_;
92 //- size of blocks is calculated by powers of 2
93 //- and therefore the access can be done using shift and mask
97 //- array of pointers to the blocks of data, each of the size WIDTH
100 // Private member functions
102 void checkIndex(label const i) const;
104 //- initialize width and mask
105 void initializeParameters();
107 //- Allocate memory for the list
108 void allocateSize(const label);
110 //- delete all elements
120 //- Construct given size
121 explicit inline LongList(const label size);
123 //- Construct to given size and initialize
124 explicit inline LongList(const label size, const T& t);
127 inline LongList(const LongList<T, Offset>&);
137 //- Size of the active part of the list.
138 inline label size() const;
140 //- Return the binary size in number of characters of the UList
141 // if the element is a primitive type
142 // i.e. contiguous<T>() == true
143 inline label byteSize() const;
147 //- Reset size of List.
148 void setSize(const label);
150 //- Clear the list, i.e. set next free to zero.
151 // Allocated size does not change
154 //- Shrink the list to the number of elements used
155 inline LongList<T, Offset>& shrink();
157 //- transfer the list from another one without allocating it
158 inline void transfer(LongList<T, Offset>&);
163 //- Append an element at the end of the list
164 inline void append(const T& e);
166 //- Append an element at the end of the list if it is not yet
167 //- present in the list (takes linear time)
168 inline void appendIfNotIn(const T& e);
170 //- check if the element is in the list (takes linear time)
171 inline bool contains(const T& e) const;
172 inline label containsAtPosition(const T& e) const;
174 //- Return and remove the element
175 inline T remove(const label i);
176 inline T removeLastElement();
178 //- get and set operators
179 inline const T& operator[](const label i) const;
180 inline T& operator[](const label i);
182 //- Return non-const access to an element,
183 // resizing the list if necessary
184 inline T& operator()(const label);
186 //- return a non-const access to an element,
187 // resize the list if necessary
188 inline T& newElmt(const label);
190 //- Assignment of all entries to the given value
191 inline void operator=(const T&);
193 //- Assignment operator
194 inline void operator=(const LongList<T, Offset>&);
197 // IOstream operators
198 //- Read from stream and append to the current content
199 void appendFromStream(Istream&);
201 //- Write as a dictionary entry.
202 void writeEntry(Ostream& os) const;
204 //- Write as a dictionary entry with keyword.
205 void writeEntry(const word& keyword, Ostream& os) const;
207 // Write LongList to Ostream.
208 friend Ostream& operator<< <T, Offset>
211 const LongList<T, Offset>&
214 //- Read from Istream, discarding contents of existing LongList.
215 friend Istream& operator>> <T, Offset>
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 } // End namespace Foam
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 #include "LongListI.H"
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 # include "LongList.C"
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 // ************************************************************************* //