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 | Copyright (C) 2015 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 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 /*---------------------------------------------------------------------------*\
44  Class RegisterSwitch Declaration
45 \*---------------------------------------------------------------------------*/
46 
47 template<class Type>
48 class RegisterSwitch
49 :
50  public simpleRegIOobject
51 {
52  Type& optSwitch_;
53 
54 public:
55 
57  (
58  void (*registryFn)(const char* name, simpleRegIOobject*),
59  const char* name,
60  Type& optSwitch
61  )
62  :
63  simpleRegIOobject(registryFn, name),
64  optSwitch_(optSwitch)
65  {}
66 
67  virtual ~RegisterSwitch()
68  {}
69 
70  virtual void readData(Foam::Istream& is)
71  {
72  is >> optSwitch_;
73  }
74 
75  virtual void writeData(Foam::Ostream& os) const
76  {
77  os << optSwitch_;
78  }
79 };
80 
81 
82 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
83 
84 } // End namespace Foam
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 
88 #define CONCAT(x, y) x ## y
89 #define CONCAT2(x, y) CONCAT(x, y)
90 #define FILE_UNIQUE(x) CONCAT2(x, __LINE__)
91 
92 #define registerOptSwitch(Name, Type, Switch) \
93  static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
94  (Foam::debug::addOptimisationObject, Name, Switch)
95 
96 
97 #define registerInfoSwitch(Name, Type, Switch) \
98  static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
99  (Foam::debug::addInfoObject, Name, Switch)
100 
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 #endif
105 
106 // ************************************************************************* //
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)
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.