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