IOList.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-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2025 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::IOList
29 
30 Description
31  A List of objects of type <T> with automated input and output.
32 
33 SourceFiles
34  IOList.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_IOList_H
39 #define Foam_IOList_H
40 
41 #include "List.H"
42 #include "regIOobject.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class IOList Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 template<class T>
54 class IOList
55 :
56  public regIOobject,
57  public List<T>
58 {
59  // Private Member Functions
60 
61  //- Read if IOobject flags set. Return true if read.
62  bool readIOcontents();
63 
64 public:
65 
66  //- The underlying content type
67  typedef List<T> content_type;
68 
69  //- Runtime type information
70  TypeName("List");
71 
72 
73  // Constructors
74 
75  //- Default copy construct
76  IOList(const IOList&) = default;
77 
78  //- Construct from IOobject
79  explicit IOList(const IOobject& io);
80 
81  //- Construct from IOobject and zero size (if not read)
82  IOList(const IOobject& io, Foam::zero);
83 
84  //- Construct from IOobject and list size (if not read)
85  IOList(const IOobject& io, const label len);
86 
87  //- Construct from IOobject and a copy of content
88  IOList(const IOobject& io, const UList<T>& content);
89 
90  //- Construct by transferring the content
91  IOList(const IOobject& io, List<T>&& content);
92 
93 
94  // Factory Methods
95 
96  //- Read and return contents. The IOobject is never registered
97  static List<T> readContents(const IOobject& io);
98 
99  //- Write contents. The IOobject is never registered.
100  // Uses IOListRef internally.
101  static void writeContents(const IOobject& io, const UList<T>& content);
102 
103 
104  //- Destructor
105  virtual ~IOList() = default;
106 
107 
108  // Member Functions
109 
110  //- The writeData method for regIOobject write operation
111  virtual bool writeData(Ostream& os) const;
112 
113 
114  // Member Operators
115 
116  //- Copy assignment of entries
117  void operator=(const IOList<T>& rhs);
118 
119  //- Copy or move assignment of entries
120  using List<T>::operator=;
121 };
122 
123 
124 /*---------------------------------------------------------------------------*\
125  Class IOListRef Declaration
126 \*---------------------------------------------------------------------------*/
127 
128 //- A IOList wrapper for writing external List data
129 template<class T>
130 class IOListRef
131 :
132  public regIOobject
133 {
134  // Private Data
135 
136  //- Reference to the external content
137  UList<T> contentRef_;
138 
139 
140 public:
141 
142  //- The underlying content type
143  typedef List<T> content_type;
144 
145 
146  //- Type is identical to IOList
147  virtual const word& type() const
148  {
149  return IOList<T>::typeName;
150  }
151 
152 
153  // Generated Methods
154 
155  //- No default construct
156  IOListRef() = delete;
157 
158  //- No copy construct
159  IOListRef(const IOListRef&) = delete;
160 
161  //- No copy assignment
162  void operator=(const IOListRef&) = delete;
163 
164 
165  // Constructors
166 
167  //- Construct from IOobject and const data reference
168  IOListRef(const IOobject& io, const UList<T>& content);
169 
170 
171  //- Destructor
172  virtual ~IOListRef() = default;
173 
174 
175  // Member Functions
176 
177  //- Allow cast to const content
178  operator const UList<T>&() const
179  {
180  return contentRef_;
181  }
182 
183  //- The writeData method for regIOobject write operation
184  // Fatal if content is not set
185  virtual bool writeData(Ostream& os) const;
186 };
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #ifdef NoRepository
196  #include "IOList.C"
197 #endif
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 #endif
202 
203 // ************************************************************************* //
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
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOList.C:167
A List of objects of type <T> with automated input and output.
Definition: IOList.H:49
virtual ~IOList()=default
Destructor.
static void writeContents(const IOobject &io, const UList< T > &content)
Write contents. The IOobject is never registered.
Definition: IOList.C:141
List< T > content_type
The underlying content type.
Definition: IOList.H:66
static List< T > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
Definition: IOList.C:125
A class for handling words, derived from Foam::string.
Definition: word.H:63
IOListRef()=delete
No default construct.
void operator=(const IOList< T > &rhs)
Copy assignment of entries.
Definition: IOList.C:177
TypeName("List")
Runtime type information.
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 writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOList.C:159
virtual const word & type() const
Type is identical to IOList.
Definition: IOList.H:181
IOList(const IOList &)=default
Default copy construct.
OBJstream os(runTime.globalPath()/outputName)
virtual ~IOListRef()=default
Destructor.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
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)
A IOList wrapper for writing external List data.
Definition: IOList.H:158
List< T > content_type
The underlying content type.
Definition: IOList.H:175
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
void operator=(const IOListRef &)=delete
No copy assignment.
Namespace for OpenFOAM.