FreeFOAM The Cross-Platform CFD Toolkit
debug.C
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) 1991-2010 OpenCFD Ltd.
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  Class for handling debugging switches.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "debug.H"
30 #include <OpenFOAM/dictionary.H>
31 #include <OpenFOAM/IFstream.H>
32 #include <OpenFOAM/OSspecific.H>
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace debug
39 {
40 
42 dictionary* controlDictPtr_(NULL);
43 dictionary* debugSwitchesPtr_(NULL);
44 dictionary* infoSwitchesPtr_(NULL);
45 dictionary* optimisationSwitchesPtr_(NULL);
46 
47 // to ensure controlDictPtr_ is deleted at the end of the run
48 class deleteControlDictPtr
49 {
50 public:
51 
52  deleteControlDictPtr()
53  {}
54 
55  ~deleteControlDictPtr()
56  {
57  if (controlDictPtr_)
58  {
59  delete controlDictPtr_;
60  controlDictPtr_ = 0;
61  }
62  }
63 };
64 
65 deleteControlDictPtr deleteControlDictPtr_;
67 
68 
69 } // End namespace debug
70 } // End namespace Foam
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
75 {
76  if (!controlDictPtr_)
77  {
78  controlDictPtr_ = new dictionary
79  (
80  IFstream(findEtcFile("controlDict", true))()
81  );
82  }
83 
84  return *controlDictPtr_;
85 }
86 
87 
89 (
90  const char* subDictName,
91  dictionary*& subDictPtr
92 )
93 {
94  if (!subDictPtr)
95  {
97  (
98  subDictName, false, false
99  );
100 
101  if (!ePtr || !ePtr->isDict())
102  {
103  cerr<< "debug::switchSet(const char*, dictionary*&):\n"
104  << " Cannot find " << subDictName << " in dictionary "
105  << controlDict().name().c_str()
106  << std::endl << std::endl;
107 
108  ::exit(1);
109  }
110 
111  subDictPtr = &ePtr->dict();
112  }
113 
114  return *subDictPtr;
115 }
116 
117 
119 {
120  return switchSet("DebugSwitches", debugSwitchesPtr_);
121 }
122 
123 
125 {
126  return switchSet("InfoSwitches", infoSwitchesPtr_);
127 }
128 
129 
131 {
132  return switchSet("OptimisationSwitches", optimisationSwitchesPtr_);
133 }
134 
135 
136 int Foam::debug::debugSwitch(const char* name, const int defaultValue)
137 {
139  (
140  name, defaultValue, false, false
141  );
142 }
143 
144 
145 int Foam::debug::infoSwitch(const char* name, const int defaultValue)
146 {
148  (
149  name, defaultValue, false, false
150  );
151 }
152 
153 
154 int Foam::debug::optimisationSwitch(const char* name, const int defaultValue)
155 {
157  (
158  name, defaultValue, false, false
159  );
160 }
161 
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 
166 // ************************ vim: set sw=4 sts=4 et: ************************ //