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-------------------------------------------------------------------------------
11License
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
27Description
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
41namespace Foam
42{
43
44//- Define the debug information, lookup as \a name
45template<class Type>
47:
49{
50public:
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 :
63 ::Foam::simpleRegIOobject(::Foam::debug::addDebugObject, name)
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// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Define the debug information, lookup as name.
virtual ~RegisterDebugSwitch()=default
RegisterDebugSwitch(const char *name)
RegisterDebugSwitch(const RegisterDebugSwitch< Type > &)=delete
No copy construct.
void operator=(const RegisterDebugSwitch< Type > &)=delete
No copy assignment.
virtual void readData(Istream &is)
Read.
static const RegisterDebugSwitch registerDebugSwitch
The unique RegisterDebugSwitch object.
virtual void writeData(Ostream &os) const
Write.
Abstract base class for registered object with I/O. Used in debug symbol registration.
#define defineTemplateDebugSwitch(Type, Value)
Define the debug information for templates.
#define defineTemplate2DebugSwitch(Type, Value)
Define the debug information for templates.
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59