CompactIOList.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::CompactIOList
29 
30 Description
31  A List of objects of type <T> with automated input and output using
32  a compact storage. Behaves like IOList except when binary output in
33  case it writes a CompactListList.
34 
35  Useful for lists of small sublists e.g. faceList, cellList.
36 
37 SourceFiles
38  CompactIOList.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_CompactIOList_H
43 #define Foam_CompactIOList_H
44 
45 #include "IOList.H"
46 #include "regIOobject.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 template<class T, class BaseType> class CompactIOList;
55 
56 template<class T, class BaseType> Istream& operator>>
57 (
58  Istream&,
60 );
61 template<class T, class BaseType> Ostream& operator<<
62 (
63  Ostream&,
65 );
66 
67 /*---------------------------------------------------------------------------*\
68  Class CompactIOList Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 template<class T, class BaseType>
72 class CompactIOList
73 :
74  public regIOobject,
75  public List<T>
76 {
77  // Private Member Functions
78 
79  //- Read according to header type
80  void readFromStream();
81 
82  //- Read if IOobject flags set. Return true if read.
83  // Reads according to the header type
84  bool readContents();
85 
86  //- Has too many elements in it?
87  bool overflows() const;
88 
89 
90 public:
91 
92  //- The underlying content type
93  typedef List<T> content_type;
94 
95  //- Runtime type information
96  TypeName("CompactList");
97 
98 
99  // Constructors
100 
101  //- Default copy construct
102  CompactIOList(const CompactIOList&) = default;
103 
104  //- Construct from IOobject
105  explicit CompactIOList(const IOobject& io);
106 
107  //- Construct from IOobject and zero size (if not read)
109 
110  //- Construct from IOobject and default length of CompactIOList
111  CompactIOList(const IOobject& io, const label len);
112 
113  //- Construct from IOobject and List content
114  CompactIOList(const IOobject& io, const UList<T>& content);
115 
116  //- Construct by transferring the List content
117  CompactIOList(const IOobject& io, List<T>&& content);
118 
119 
120  //- Destructor
121  virtual ~CompactIOList() = default;
122 
123 
124  // Member Functions
125 
126  //- Write using stream options. Checks for overflow in binary
127  virtual bool writeObject
128  (
129  IOstreamOption streamOpt,
130  const bool writeOnProc
131  ) const;
132 
133  virtual bool writeData(Ostream&) const;
134 
135 
136  // Member Operators
137 
138  //- Copy assignment of entries
139  void operator=(const CompactIOList<T, BaseType>& rhs);
140 
141  //- Copy or move assignment of entries
142  using List<T>::operator=;
143 
144 
145  // IOstream operators
146 
147  //- Read List from Istream, discarding contents of existing List.
148  friend Istream& operator>> <T, BaseType>
149  (
150  Istream&,
152  );
153 
154  // Write List to Ostream.
155  friend Ostream& operator<< <T, BaseType>
156  (
157  Ostream&,
159  );
160 };
161 
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 } // End namespace Foam
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 #ifdef NoRepository
170  #include "CompactIOList.C"
171 #endif
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 #endif
176 
177 // ************************************************************************* //
List< T > content_type
The underlying content type.
Definition: CompactIOList.H:97
CompactIOList(const CompactIOList &)=default
Default copy construct.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A simple container for options an IOstream can normally have.
void operator=(const CompactIOList< T, BaseType > &rhs)
Copy assignment of entries.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options. Checks for overflow in binary.
A List of objects of type <T> with automated input and output using a compact storage. Behaves like IOList except when binary output in case it writes a CompactListList.
Definition: CompactIOList.H:49
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
virtual ~CompactIOList()=default
Destructor.
TypeName("CompactList")
Runtime type information.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
virtual bool writeData(Ostream &) const
Pure virtual writeData function.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Namespace for OpenFOAM.