writeObjectsBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation
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::functionObjects::writeObjectsBase
26 
27 Description
28  FunctionObject base class for writing a list of objects registered to the
29  database, on behalf of the inheriting function object, on when those should
30  be written to disk.
31 
32  FunctionObjects that inherit this class will receive the additional
33  dictionary option \c objects which allows selecting which fields of the
34  inherited function should be written to disk when \c write() is called.
35 
36  Example of function object specification:
37  \verbatim
38  <functionObjectName>
39  {
40  ...
41  objects (obj1 obj2);
42  ...
43  }
44  \endverbatim
45 
46 Usage
47  \table
48  Property | Description | Required | Default value
49  objects | List of objects to be written | yes |
50  regExp | Switch for regular expression support | no | true
51  \endtable
52 
53  Note: Regular expressions can also be used in \c objects.
54 
55 See also
56  Foam::functionObject
57  Foam::functionObjects::writeObjects
58  Foam::functionObjects::writeLocalObjects
59 
60 SourceFiles
61  writeObjectsBase.C
62 
63 \*---------------------------------------------------------------------------*/
64 
65 #ifndef functionObjects_writeObjectsBase_H
66 #define functionObjects_writeObjectsBase_H
67 
68 #include "wordList.H"
69 #include "wordReList.H"
70 #include "Switch.H"
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
74 namespace Foam
75 {
76 
77 // Forward declaration of classes
78 class objectRegistry;
79 class regIOobject;
80 class Switch;
81 
82 namespace functionObjects
83 {
84 
85 /*---------------------------------------------------------------------------*\
86  Class writeObjectsBase Declaration
87 \*---------------------------------------------------------------------------*/
88 
89 class writeObjectsBase
90 {
91 
92 protected:
93 
94  // Protected data
95 
96  //- Reference to the region objectRegistry
97  const objectRegistry& writeObr_;
98 
99  //- False switch to which log_ defaults
100  static const Switch logFalse;
101 
102  //- Reference to the inheriting function object's log variable
103  const Switch& log_;
104 
105  //- Optional switch for regular expression support
106  // Defaults to true
107  Switch regExp_;
108 
109  //- Object names requested by the user to be written
111 
112 
113  // Protected Member Functions
114 
115  //- Reset the list of object names to be written to a single regular
116  // expression
118 
119  //- Reset the list of object names to be written
120  void resetWriteObjectNames(const wordReList& names);
121 
122  //- Get the list of field names to be written
123  virtual wordList objectNames();
124 
125  //- Write the requested registered IO object
126  virtual void writeObject(const regIOobject& obj);
127 
128 
129 public:
130 
131  // Constructors
132 
133  //- Construct from objectRegistry and inheriting function object
135  (
136  const objectRegistry& obr,
137  const Switch& logRef = logFalse
138  );
139 
140  //- Disallow default bitwise copy construction
141  writeObjectsBase(const writeObjectsBase&) = delete;
142 
143 
144  //- Destructor
145  virtual ~writeObjectsBase();
146 
147 
148  // Member Functions
149 
150  //- Return const access to the object names requested to be written
151  const wordReList& writeObjectNames() const;
152 
153  //- Read the list of objects to be written
154  virtual bool read(const dictionary&);
155 
156  //- Write function
157  virtual bool write();
158 
159 
160  // Member Operators
161 
162  //- Disallow default bitwise assignment
163  void operator=(const writeObjectsBase&) = delete;
164 };
165 
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 } // End namespace functionObjects
170 } // End namespace Foam
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 #endif
175 
176 // ************************************************************************* //
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
FunctionObject base class for writing a list of objects registered to the database,...
wordReList writeObjectNames_
Object names requested by the user to be written.
writeObjectsBase(const objectRegistry &obr, const Switch &logRef=logFalse)
Construct from objectRegistry and inheriting function object.
Switch regExp_
Optional switch for regular expression support.
const objectRegistry & writeObr_
Reference to the region objectRegistry.
virtual void writeObject(const regIOobject &obj)
Write the requested registered IO object.
void resetWriteObjectNames(const wordReList &names)
Reset the list of object names to be written.
void operator=(const writeObjectsBase &)=delete
Disallow default bitwise assignment.
const Switch & log_
Reference to the inheriting function object's log variable.
const wordReList & writeObjectNames() const
Return const access to the object names requested to be written.
void resetWriteObjectName(const wordRe &name)
Reset the list of object names to be written to a single regular.
virtual wordList objectNames()
Get the list of field names to be written.
static const Switch logFalse
False switch to which log_ defaults.
virtual bool write()
Write function.
virtual bool read(const dictionary &)
Read the list of objects to be written.
Registry of regIOobjects.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:77
Namespace for OpenFOAM.
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39