FreeFOAM The Cross-Platform CFD Toolkit
DynamicList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::DynamicList
26 
27 Description
28  A 1D vector of objects of type <T> that resizes itself as necessary to
29  accept the new objects.
30 
31  Internal storage is a compact array and the list can be shrunk to compact
32  storage. The increase of list size is controlled by three template
33  parameters, which allows the list storage to either increase by the given
34  increment or by the given multiplier and divider (allowing non-integer
35  multiples).
36 
37 SourceFiles
38  DynamicListI.H
39  DynamicList.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef DynamicList_H
44 #define DynamicList_H
45 
46 #include <OpenFOAM/List.H>
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declaration of friend functions and operators
54 
55 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
56 class DynamicList;
57 
58 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
59 Ostream& operator<<
60 (
61  Ostream&,
62  const DynamicList<T, SizeInc, SizeMult, SizeDiv>&
63 );
64 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
65 Istream& operator>>
66 (
67  Istream&,
68  DynamicList<T, SizeInc, SizeMult, SizeDiv>&
69 );
70 
71 
72 /*---------------------------------------------------------------------------*\
73  Class DynamicList Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 template<class T, unsigned SizeInc=0, unsigned SizeMult=2, unsigned SizeDiv=1>
78 :
79  public List<T>
80 {
81  // Private data
82 
83  //- The capacity (allocated size) of the underlying list.
84  label capacity_;
85 
86  // Private Member Functions
87 
88 public:
89 
90  // Related types
91 
92  //- Declare friendship with the List class
93  friend class List<T>;
94 
95  // Constructors
96 
97  //- Construct null
98  inline DynamicList();
99 
100  //- Construct given size.
101  explicit inline DynamicList(const label);
102 
103  //- Construct copy.
104  explicit inline DynamicList
105  (
107  );
108 
109  //- Construct from UList. Size set to UList size.
110  // Also constructs from DynamicList with different sizing parameters.
111  explicit inline DynamicList(const UList<T>&);
112 
113  //- Construct from UIndirectList. Size set to UIndirectList size.
114  explicit inline DynamicList(const UIndirectList<T>&);
115 
116  //- Construct by transferring the parameter contents
117  explicit inline DynamicList(const Xfer< List<T> >&);
118 
119  //- Construct from Istream. Size set to size of read list.
120  explicit DynamicList(Istream&);
121 
122 
123  // Member Functions
124 
125  // Access
126 
127  //- Size of the underlying storage.
128  inline label capacity() const;
129 
130  // Edit
131 
132  //- Alter the size of the underlying storage.
133  // The addressed size will be truncated if needed to fit, but will
134  // remain otherwise untouched.
135  // Use this or reserve() in combination with append().
136  inline void setCapacity(const label);
137 
138  //- Alter the addressed list size.
139  // New space will be allocated if required.
140  // Use this to resize the list prior to using the operator[] for
141  // setting values (as per List usage).
142  inline void setSize(const label);
143 
144  //- Alter the addressed list size and fill new space with a constant.
145  inline void setSize(const label, const T&);
146 
147  //- Alter the addressed list size.
148  // New space will be allocated if required.
149  // Use this to resize the list prior to using the operator[] for
150  // setting values (as per List usage).
151  inline void resize(const label);
152 
153  //- Alter the addressed list size and fill new space with a constant.
154  inline void resize(const label, const T&);
155 
156  //- Reserve allocation space for at least this size.
157  // Never shrinks the allocated size, use setCapacity() for that.
158  inline void reserve(const label);
159 
160  //- Clear the addressed list, i.e. set the size to zero.
161  // Allocated size does not change
162  inline void clear();
163 
164  //- Clear the list and delete storage.
165  inline void clearStorage();
166 
167  //- Shrink the allocated space to the number of elements used.
168  // Returns a reference to the DynamicList.
170 
171  //- Transfer contents of the argument List into this DynamicList
172  inline void transfer(List<T>&);
173 
174  //- Transfer contents of the argument DynamicList into this DynamicList
176 
177  //- Transfer contents to the Xfer container as a plain List
178  inline Xfer< List<T> > xfer();
179 
180  // Member Operators
181 
182  //- Append an element at the end of the list
183  inline void append(const T&);
184 
185  //- Append a List at the end of this list
186  inline void append(const UList<T>&);
187 
188  //- Append a UIndirectList at the end of this list
189  inline void append(const UIndirectList<T>&);
190 
191  //- Remove and return the top element
192  inline T remove();
193 
194  //- Return non-const access to an element, resizing list if necessary
195  inline T& operator()(const label);
196 
197  //- Assignment of all addressed entries to the given value
198  inline void operator=(const T&);
199 
200  //- Assignment from DynamicList
201  inline void operator=
202  (
204  );
205 
206  //- Assignment from UList
207  inline void operator=(const UList<T>&);
208 
209  // IOstream operators
210 
211  // Write DynamicList to Ostream.
212  friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv>
213  (
214  Ostream&,
216  );
217 
218  //- Read from Istream, discarding contents of existing DynamicList.
219  friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv>
220  (
221  Istream&,
223  );
224 };
225 
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 } // End namespace Foam
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 #include <OpenFOAM/DynamicListI.H>
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #ifdef NoRepository
238 # include <OpenFOAM/DynamicList.C>
239 #endif
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 #endif
244 
245 // ************************ vim: set sw=4 sts=4 et: ************************ //