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-2020 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 CompactIOList_H
43 #define CompactIOList_H
44 
45 #include "IOList.H"
46 #include "regIOobject.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declarations
54 class Istream;
55 class Ostream;
56 template<class T, class BaseType> class CompactIOList;
57 
58 template<class T, class BaseType> Istream& operator>>
59 (
60  Istream&,
62 );
63 template<class T, class BaseType> Ostream& operator<<
64 (
65  Ostream&,
67 );
68 
69 /*---------------------------------------------------------------------------*\
70  Class CompactIOList Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 template<class T, class BaseType>
74 class CompactIOList
75 :
76  public regIOobject,
77  public List<T>
78 {
79  // Private Member Functions
80 
81  //- Read according to header type
82  void readFromStream();
83 
84  //- Has too many elements in it?
85  bool overflows() const;
86 
87 public:
88 
89  //- Runtime type information
90  TypeName("CompactList");
91 
92 
93  // Constructors
94 
95  //- Default copy construct
96  CompactIOList(const CompactIOList&) = default;
97 
98  //- Construct from IOobject
99  explicit CompactIOList(const IOobject& io);
100 
101  //- Construct from IOobject and default length of CompactIOList
102  CompactIOList(const IOobject& io, const label len);
103 
104  //- Construct from IOobject and List content
105  CompactIOList(const IOobject& io, const UList<T>& content);
106 
107  //- Construct by transferring the List content
108  CompactIOList(const IOobject& io, List<T>&& content);
109 
110  // Destructor
111 
112  virtual ~CompactIOList() = default;
113 
114 
115  // Member Functions
116 
117  //- Write using stream options. Checks for overflow in binary
118  virtual bool writeObject
119  (
120  IOstreamOption streamOpt,
121  const bool valid
122  ) const;
123 
124  virtual bool writeData(Ostream&) const;
125 
126 
127  // Member Operators
128 
129  //- Copy assignment of entries
130  void operator=(const CompactIOList<T, BaseType>& rhs);
131 
132  //- Copy or move assignment of entries
133  using List<T>::operator=;
134 
135 
136  // IOstream operators
137 
138  //- Read List from Istream, discarding contents of existing List.
139  friend Istream& operator>> <T, BaseType>
140  (
141  Istream&,
143  );
144 
145  // Write List to Ostream.
146  friend Ostream& operator<< <T, BaseType>
147  (
148  Ostream&,
150  );
151 };
152 
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 } // End namespace Foam
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #ifdef NoRepository
161  #include "CompactIOList.C"
162 #endif
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #endif
167 
168 // ************************************************************************* //
regIOobject.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::CompactIOList::operator=
void operator=(const CompactIOList< T, BaseType > &rhs)
Copy assignment of entries.
Definition: CompactIOList.C:219
IOList.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::CompactIOList::~CompactIOList
virtual ~CompactIOList()=default
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::CompactIOList::CompactIOList
CompactIOList(const CompactIOList &)=default
Default copy construct.
Foam::CompactIOList
A List of objects of type <T> with automated input and output using a compact storage....
Definition: CompactIOList.H:55
Foam::CompactIOList::writeData
virtual bool writeData(Ostream &) const
Definition: CompactIOList.C:209
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
CompactIOList.C
Foam::CompactIOList::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options. Checks for overflow in binary.
Definition: CompactIOList.C:170
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:71
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList
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:103
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::CompactIOList::TypeName
TypeName("CompactList")
Runtime type information.