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