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 -------------------------------------------------------------------------------
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::RegisterSwitch
29 
30 Description
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 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class RegisterSwitch Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class Type>
52 class RegisterSwitch
53 :
54  public simpleRegIOobject
55 {
56 public:
57 
58  //- Reference to the switch variable that has been registered
59  Type& value;
60 
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  {}
71 
72  virtual ~RegisterSwitch() = default;
73 
74  virtual void readData(Istream& is)
75  {
76  is >> value;
77  }
78 
79  virtual void writeData(Ostream& os) const
80  {
81  os << value;
82  }
83 };
84 
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 
88 } // End namespace Foam
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 #define registerOptSwitch(Name, Type, SwitchVar) \
93  static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
94  (Foam::debug::addOptimisationObject, Name, SwitchVar)
95 
96 
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 // ************************************************************************* //
macros.H
General C-preprocessor macros.
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::RegisterSwitch::value
Type & value
Reference to the switch variable that has been registered.
Definition: registerSwitch.H:58
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::RegisterSwitch
Class and registration macros for InfoSwitches and OptimisationSwitches to support reading from syste...
Definition: registerSwitch.H:51
Foam::RegisterSwitch::writeData
virtual void writeData(Ostream &os) const
Write.
Definition: registerSwitch.H:78
Foam::RegisterSwitch::RegisterSwitch
RegisterSwitch(void(*registryFn)(const char *name, simpleRegIOobject *), const char *name, Type &switchVar)
Definition: registerSwitch.H:61
simpleRegIOobject.H
Foam::RegisterSwitch::readData
virtual void readData(Istream &is)
Read.
Definition: registerSwitch.H:73
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::RegisterSwitch::~RegisterSwitch
virtual ~RegisterSwitch()=default
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::simpleRegIOobject::simpleRegIOobject
simpleRegIOobject(void(*fn)(const char *name, simpleRegIOobject *), const char *name)
Construct from objectregistry inserter and name.
Definition: simpleRegIOobject.H:60
Foam::simpleRegIOobject
Abstract base class for registered object with I/O. Used in debug symbol registration.
Definition: simpleRegIOobject.H:52