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 | Copyright (C) 2012-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 Description
25  Macro definitions for debug switches.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #ifndef defineDebugSwitch_H
30 #define defineDebugSwitch_H
31 
32 #include "simpleRegIOobject.H"
33 #include "debug.H"
34 #include "label.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39 // definitions (debug information only)
40 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41 
42 namespace Foam
43 {
44 
45 //- Define the debug information, lookup as \a Name
46 template<class Type>
48 :
50 {
51 public:
52 
53  //- The unique RegisterDebugSwitch object
55 
57  :
58  ::Foam::simpleRegIOobject(Foam::debug::addDebugObject, name)
59  {}
60 
62  {}
63 
64  virtual void readData(Foam::Istream& is)
65  {
66  Type::debug = readLabel(is);
67  }
68 
69  virtual void writeData(Foam::Ostream& os) const
70  {
71  os << Type::debug;
72  }
73 };
74 
75 } // End namespace Foam
76 
77 #define registerTemplateDebugSwitchWithName(Type,Name) \
78  template<> \
79  const Foam::RegisterDebugSwitch<Type> \
80  Foam::RegisterDebugSwitch<Type>::registerDebugSwitch(Name)
81 
82 
83 //- Define the debug information, lookup as \a Name
84 #define registerDebugSwitchWithName(Type,Tag,Name) \
85  class add##Tag##ToDebug \
86  : \
87  public ::Foam::simpleRegIOobject \
88  { \
89  public: \
90  add##Tag##ToDebug(const char* name) \
91  : \
92  ::Foam::simpleRegIOobject(Foam::debug::addDebugObject, name) \
93  {} \
94  virtual ~add##Tag##ToDebug() \
95  {} \
96  virtual void readData(Foam::Istream& is) \
97  { \
98  Type::debug = readLabel(is); \
99  } \
100  virtual void writeData(Foam::Ostream& os) const \
101  { \
102  os << Type::debug; \
103  } \
104  }; \
105  add##Tag##ToDebug add##Tag##ToDebug_(Name)
106 
107 
108 //- Define the debug information, lookup as \a Name
109 #define defineDebugSwitchWithName(Type, Name, DebugSwitch) \
110  int Type::debug(::Foam::debug::debugSwitch(Name, DebugSwitch))
111 
112 //- Define the debug information
113 #define defineDebugSwitch(Type, DebugSwitch) \
114  defineDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch); \
115  registerDebugSwitchWithName(Type, Type, Type::typeName_())
116 
117 //- Define the debug information for templates, lookup as \a Name
118 # define defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch) \
119  template<> \
120  defineDebugSwitchWithName(Type, Name, DebugSwitch); \
121  registerTemplateDebugSwitchWithName(Type, Name)
122 //- Define the debug information for templates sub-classes, lookup as \a Name
123 # define defineTemplate2DebugSwitchWithName(Type, Name, DebugSwitch) \
124  template<> \
125  defineDebugSwitchWithName(Type, Name, DebugSwitch); \
126  registerTemplateDebugSwitchWithName(Type, Name)
127 
128 //- Define the debug information for templates
129 // Useful with typedefs
130 #define defineTemplateDebugSwitch(Type, DebugSwitch) \
131  defineTemplateDebugSwitchWithName(Type, #Type, DebugSwitch)
132 
133 //- Define the debug information directly for templates
134 #define defineNamedTemplateDebugSwitch(Type, DebugSwitch) \
135  defineTemplateDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
136 
137 
138 // For templated sub-classes
139 
140 //- Define the debug information for templates
141 // Useful with typedefs
142 #define defineTemplate2DebugSwitch(Type, DebugSwitch) \
143  defineTemplate2DebugSwitchWithName(Type, #Type, DebugSwitch)
144 
145 //- Define the debug information directly for templates
146 #define defineNamedTemplate2DebugSwitch(Type, DebugSwitch) \
147  defineTemplate2DebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
148 
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 #endif
153 
154 // ************************************************************************* //
static const RegisterDebugSwitch registerDebugSwitch
The unique RegisterDebugSwitch object.
virtual void readData(Foam::Istream &is)
Read.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
RegisterDebugSwitch(const char *name)
Define the debug information, lookup as Name.
Namespace for OpenFOAM.
label readLabel(Istream &is)
Definition: label.H:64
Abstract base class for registered object with I/O. Used in debug symbol registration.
virtual void writeData(Foam::Ostream &os) const
Write.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void addDebugObject(const char *name, simpleRegIOobject *obj)
Register debug switch read/write object.
Definition: debug.C:192