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 compact array and the list can be shrunk to compact storage.
31 The increase of list size is controlled by three template parameters,
32 which allows the list storage to either increase by the given increment
33 or the given multiplier and divider (allowing non-integer multiples).
39 \*---------------------------------------------------------------------------*/
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
53 template<class T, label staticSize>
56 template<class T, label staticSize>
60 const DynList<T, staticSize>&
62 template<class T, label staticSize>
66 DynList<T, staticSize>&
70 /*---------------------------------------------------------------------------*\
71 Class DynList Declaration
72 \*---------------------------------------------------------------------------*/
74 template<class T, label staticSize = 16>
80 //- statically allocated data (used for short lists)
81 T staticData_[staticSize];
83 //- Number of next free element
86 // Private member functions
87 //- allocate list size
88 inline void allocateSize(const label);
90 //- check if index is inside the scope (used for debugging only)
91 inline void checkIndex(const label) const;
100 //- Construct given size
101 explicit inline DynList(const label);
103 //- Construct from given size and defualt value
104 explicit inline DynList(const label, const T&);
106 //- Construct from UList. nextFree_ set to size().
107 explicit inline DynList(const UList<T>&);
109 //- Construct from other ListType
110 template<class ListType>
111 inline DynList(const ListType&);
114 inline DynList(const DynList<T, staticSize>&);
116 //- Construct from Istream. nextFree_ set to size().
117 explicit DynList(Istream&);
128 //- Size of the active part of the list.
129 //- Direct over-ride of list size member function
130 inline label size() const;
132 //- Number of bytes used by the active part of the list
133 //- Direct over-ride of list byteSize member function
134 inline label byteSize() const;
139 //- Reset size of List.
140 void setSize(const label);
142 //- Clear the list, i.e. set next free to zero.
143 // Allocated size does not change
146 //- Shrink the List<T> to the number of elements used
152 //- Append an element at the end of the list
153 inline void append(const T& e);
155 //- Append an element at the end of the list if it is not yet
156 //- present in the list (takes linear time)
157 inline void appendIfNotIn(const T& e);
159 //- check if the element is in the list (takes linear time)
160 inline bool contains(const T& e) const;
161 inline label containsAtPosition(const T& e) const;
163 //- return a const reference to the last element
164 inline const T& lastElement() const;
166 //- Return and remove the last element
167 inline T removeLastElement();
168 inline T removeElement(const label i);
170 //- return a refence to the element. Resize the list if necessary
171 inline T& newElmt(const label);
173 //- Return non-const access to an element,
174 //- resizing the list if necessary
175 inline T& operator()(const label);
177 //- return access to an element
178 inline const T& operator[](const label) const;
179 inline T& operator[](const label);
181 //- return forward and reverse circular indices
182 inline label fcIndex(const label index, const label offset = 1) const;
183 inline label rcIndex(const label index, const label offset = 1) const;
185 //- return forward and reverse circular elements
186 inline const T& fcElement
189 const label offset = 1
192 inline const T& rcElement
195 const label offset = 1
198 //- Assignment of all entries to the given value
199 inline void operator=(const T&);
201 //- Copy of another list
202 inline void operator=(const DynList<T, staticSize>&);
204 //- Copy of another list type
205 template<class ListType>
206 inline void operator=(const ListType&);
209 // IOstream operators
211 // Write DynList to Ostream.
212 friend Ostream& operator<< <T, staticSize>
215 const DynList<T, staticSize>&
218 //- Read from Istream, discarding contents of existing DynList.
219 friend Istream& operator>> <T, staticSize>
222 DynList<T, staticSize>&
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 } // End namespace Foam
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233 #include "DynListI.H"
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 # include "DynList.C"
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 // ************************************************************************* //