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 \*---------------------------------------------------------------------------*/
45 #include "IOstreams.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
55 template<class T, label Offset>
58 template<class T, label Offset>
62 const LongList<T, Offset>&
64 template<class T, label Offset>
71 /*---------------------------------------------------------------------------*\
72 Class LongList Declaration
73 \*---------------------------------------------------------------------------*/
75 template<class T, label Offset = 19>
79 //- number of allocated elements
82 //- number of elements in the list
85 //- number of used blocks of data
88 //- maximum number of blocks that can be allocated
89 //- without reallocating the list containing pointers
90 //- to the chunks of data
91 label numAllocatedBlocks_;
93 //- size of blocks is calculated by powers of 2
94 //- and therefore the access can be done using shift and mask
98 //- array of pointers to the blocks of data, each of the size WIDTH
101 // Private member functions
103 void checkIndex(const label i) const;
105 //- initialize width and mask
106 void initializeParameters();
108 //- Allocate memory for the list
109 void allocateSize(const label);
111 //- delete all elements
121 //- Construct given size
122 explicit inline LongList(const label size);
124 //- Construct to given size and initialize
125 explicit inline LongList(const label size, const T& t);
128 inline LongList(const LongList<T, Offset>&);
138 //- Size of the active part of the list.
139 inline label size() const;
141 //- Return the binary size in number of characters of the UList
142 // if the element is a primitive type
143 // i.e. contiguous<T>() == true
144 inline label byteSize() const;
148 //- Reset size of List.
149 void setSize(const label);
151 //- Clear the list, i.e. set next free to zero.
152 // Allocated size does not change
155 //- Shrink the list to the number of elements used
156 inline LongList<T, Offset>& shrink();
158 //- transfer the list from another one without allocating it
159 inline void transfer(LongList<T, Offset>&);
164 //- Append an element at the end of the list
165 inline void append(const T& e);
167 //- Append an element at the end of the list if it is not yet
168 //- present in the list (takes linear time)
169 inline void appendIfNotIn(const T& e);
171 //- check if the element is in the list (takes linear time)
172 inline bool contains(const T& e) const;
173 inline label containsAtPosition(const T& e) const;
175 //- Return and remove the element
176 inline T remove(const label i);
177 inline T removeLastElement();
179 //- get and set operators
180 inline const T& operator[](const label i) const;
181 inline T& operator[](const label i);
183 //- Return non-const access to an element,
184 // resizing the list if necessary
185 inline T& operator()(const label);
187 //- return a non-const access to an element,
188 // resize the list if necessary
189 inline T& newElmt(const label);
191 //- Assignment of all entries to the given value
192 inline void operator=(const T&);
194 //- Assignment operator
195 inline void operator=(const LongList<T, Offset>&);
198 // IOstream operators
199 //- Read from stream and append to the current content
200 void appendFromStream(Istream&);
202 //- Write as a dictionary entry.
203 void writeEntry(Ostream& os) const;
205 //- Write as a dictionary entry with keyword.
206 void writeEntry(const word& keyword, Ostream& os) const;
208 // Write LongList to Ostream.
209 friend Ostream& operator<< <T, Offset>
212 const LongList<T, Offset>&
215 //- Read from Istream, discarding contents of existing LongList.
216 friend Istream& operator>> <T, Offset>
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 } // End namespace Foam
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 #include "LongListI.H"
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 # include "LongList.C"
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 // ************************************************************************* //