registerSwitch.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) 2015-2018 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::RegisterSwitch
26 
27 Description
28  Class and registration macros for InfoSwitches and OptimisationSwitches
29  to support reading from system/controlDict and dynamic update.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #ifndef registerSwitch_H
34 #define registerSwitch_H
35 
36 #include "simpleRegIOobject.H"
37 #include "macros.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 /*---------------------------------------------------------------------------*\
45  Class RegisterSwitch Declaration
46 \*---------------------------------------------------------------------------*/
47 
48 template<class Type>
49 class RegisterSwitch
50 :
51  public simpleRegIOobject
52 {
53  Type& optSwitch_;
54 
55 public:
56 
58  (
59  void (*registryFn)(const char* name, simpleRegIOobject*),
60  const char* name,
61  Type& optSwitch
62  )
63  :
64  simpleRegIOobject(registryFn, name),
65  optSwitch_(optSwitch)
66  {}
67 
68  virtual ~RegisterSwitch()
69  {}
70 
71  virtual void readData(Foam::Istream& is)
72  {
73  is >> optSwitch_;
74  }
75 
76  virtual void writeData(Foam::Ostream& os) const
77  {
78  os << optSwitch_;
79  }
80 };
81 
82 
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 
85 } // End namespace Foam
86 
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 
89 #define registerOptSwitch(Name, Type, Switch) \
90  static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
91  (Foam::debug::addOptimisationObject, Name, Switch)
92 
93 
94 #define registerInfoSwitch(Name, Type, Switch) \
95  static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
96  (Foam::debug::addInfoObject, Name, Switch)
97 
98 
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
100 
101 #endif
102 
103 // ************************************************************************* //
Abstract base class for registered object with I/O. Used in debug symbol registration.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void readData(Foam::Istream &is)
Read.
virtual void writeData(Foam::Ostream &os) const
Write.
RegisterSwitch(void(*registryFn)(const char *name, simpleRegIOobject *), const char *name, Type &optSwitch)
General C-preprocessor macros.
Class and registration macros for InfoSwitches and OptimisationSwitches to support reading from syste...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Namespace for OpenFOAM.