registerSwitch.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) 2015-2016 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::RegisterSwitch
29
30Description
31 Class and registration macros for InfoSwitches and OptimisationSwitches
32 to support reading from system/controlDict and dynamic update.
33
34\*---------------------------------------------------------------------------*/
35
36#ifndef registerSwitch_H
37#define registerSwitch_H
38
39#include "simpleRegIOobject.H"
40#include "macros.H"
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
45{
46
47/*---------------------------------------------------------------------------*\
48 Class RegisterSwitch Declaration
49\*---------------------------------------------------------------------------*/
50
51template<class Type>
53:
55{
56public:
57
58 //- Reference to the switch variable that has been registered
59 Type& value;
62 (
63 void (*registryFn)(const char* name, simpleRegIOobject*),
64 const char* name,
65 Type& switchVar
66 )
67 :
68 simpleRegIOobject(registryFn, name),
69 value(switchVar)
70 {}
72 virtual ~RegisterSwitch() = default;
74 virtual void readData(Istream& is)
75 {
76 is >> value;
77 }
79 virtual void writeData(Ostream& os) const
80 {
81 os << value;
82 }
83};
84
85
86// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87
88} // End namespace Foam
89
90// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92#define registerOptSwitch(Name, Type, SwitchVar) \
93 static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
94 (Foam::debug::addOptimisationObject, Name, SwitchVar)
95
97#define registerInfoSwitch(Name, Type, SwitchVar) \
98 static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
99 (Foam::debug::addInfoObject, Name, SwitchVar)
100
101
102// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103
104#endif
105
106// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Class and registration macros for InfoSwitches and OptimisationSwitches to support reading from syste...
virtual ~RegisterSwitch()=default
Type & value
Reference to the switch variable that has been registered.
RegisterSwitch(void(*registryFn)(const char *name, simpleRegIOobject *), const char *name, Type &switchVar)
virtual void readData(Istream &is)
Read.
virtual void writeData(Ostream &os) const
Write.
Abstract base class for registered object with I/O. Used in debug symbol registration.
OBJstream os(runTime.globalPath()/outputName)
General C-preprocessor macros.
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59