defineDebugSwitch.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) 2012-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 Description
28  Macro definitions for debug switches.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef Foam_defineDebugSwitch_H
33 #define Foam_defineDebugSwitch_H
34 
35 #include "simpleRegIOobject.H"
36 #include "debug.H"
37 #include "label.H" // Also for defining Foam::word etc.
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 //- Define the debug information, lookup as \a name
45 template<class Type>
47 :
49 {
50 public:
51 
52  //- The unique RegisterDebugSwitch object
54 
55  //- Construct with given registered name
56  explicit RegisterDebugSwitch(const char* name)
57  :
59  {}
60 
61  virtual ~RegisterDebugSwitch() = default;
62 
63  virtual void readData(::Foam::Istream& is)
64  {
65  is >> Type::debug;
66  }
67 
68  virtual void writeData(::Foam::Ostream& os) const
69  {
70  os << Type::debug;
71  }
72 
74  void operator=(const RegisterDebugSwitch<Type>&) = delete;
75 };
76 
77 } // End namespace Foam
78 
79 
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 
82 //- Define the debug information, lookup as \a Name
83 #define registerTemplateDebugSwitchWithName(Type, Name) \
84  \
85  template<> const Foam::RegisterDebugSwitch<Type> \
86  Foam::RegisterDebugSwitch<Type>::registerDebugSwitch(Name)
87 
88 
89 //- Define the debug information, lookup as \a Name
90 #define registerDebugSwitchWithName(Type, Tag, Name) \
91  \
92  class add##Tag##ToDebug \
93  : \
94  public ::Foam::simpleRegIOobject \
95  { \
96  public: \
97  \
98  /* Construct with given registered name */ \
99  explicit add##Tag##ToDebug(const char* name) \
100  : \
101  ::Foam::simpleRegIOobject(::Foam::debug::addDebugObject, name) \
102  {} \
103  \
104  virtual ~add##Tag##ToDebug() = default; \
105  \
106  virtual void readData(::Foam::Istream& is) \
107  { \
108  is >> Type::debug; \
109  } \
110  \
111  virtual void writeData(::Foam::Ostream& os) const \
112  { \
113  os << Type::debug; \
114  } \
115  \
116  add##Tag##ToDebug(const add##Tag##ToDebug&) = delete; \
117  void operator=(const add##Tag##ToDebug&) = delete; \
118  }; \
119  add##Tag##ToDebug add##Tag##ToDebug_(Name)
120 
121 
122 //- Define the debug information, lookup as \a Name
123 #define defineDebugSwitchWithName(Type, Name, Value) \
124  int Type::debug(::Foam::debug::debugSwitch(Name, Value))
125 
126 //- Define the debug information
127 #define defineDebugSwitch(Type, Value) \
128  defineDebugSwitchWithName(Type, Type::typeName_(), Value); \
129  registerDebugSwitchWithName(Type, Type, Type::typeName_())
130 
131 //- Define the debug information for templates, lookup as \a Name
132 #define defineTemplateDebugSwitchWithName(Type, Name, Value) \
133  template<> defineDebugSwitchWithName(Type, Name, Value); \
134  registerTemplateDebugSwitchWithName(Type, Name)
136 //- Define the debug information for templates
137 // Useful with typedefs
138 #define defineTemplateDebugSwitch(Type, Value) \
139  defineTemplateDebugSwitchWithName(Type, #Type, Value)
140 
141 //- Define the debug information directly for templates
142 #define defineNamedTemplateDebugSwitch(Type, Value) \
143  defineTemplateDebugSwitchWithName(Type, Type::typeName_(), Value)
144 
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 // Old names
148 
149 // Same as defineTemplateDebugSwitchWithName
150 #define defineTemplate2DebugSwitchWithName(Type, Name, Value) \
151  defineTemplateDebugSwitchWithName(Type, Name, Value)
152 
153 // Same as defineTemplateDebugSwitch
154 #define defineTemplate2DebugSwitch(Type, Value) \
155  defineTemplateDebugSwitch(Type, Value)
156 
157 // Same as defineNamedTemplateDebugSwitch
158 #define defineNamedTemplate2DebugSwitch(Type, Value) \
159  defineNamedTemplateDebugSwitch(Type, Value)
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #endif
166 // ************************************************************************* //
Abstract base class for registered object with I/O. Used in debug symbol registration.
static const RegisterDebugSwitch registerDebugSwitch
The unique RegisterDebugSwitch object.
Define the debug information, lookup as name.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual void writeData(::Foam::Ostream &os) const
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
int debug
Static debugging option.
RegisterDebugSwitch(const char *name)
Construct with given registered name.
OBJstream os(runTime.globalPath()/outputName)
virtual ~RegisterDebugSwitch()=default
virtual void readData(::Foam::Istream &is)
void addDebugObject(const char *name, simpleRegIOobject *obj)
Register debug switch read/write object.
Definition: debug.C:246
void operator=(const RegisterDebugSwitch< Type > &)=delete
Namespace for OpenFOAM.