1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Class for handling debugging switches.
28 \*---------------------------------------------------------------------------*/
31 #include "dictionary.H"
33 #include "OSspecific.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 dictionary* controlDictPtr_(NULL);
46 dictionary* debugSwitchesPtr_(NULL);
47 dictionary* infoSwitchesPtr_(NULL);
48 dictionary* optimisationSwitchesPtr_(NULL);
50 //- Class to ensure controlDictPtr_ is deleted at the end of the run
51 // @cond ignore documentation for this class
52 class deleteControlDictPtr
56 deleteControlDictPtr()
59 ~deleteControlDictPtr()
63 delete controlDictPtr_;
69 deleteControlDictPtr deleteControlDictPtr_;
72 dictionary& switchSet(const char* switchSetName, dictionary* switchSetPtr)
76 if (!controlDict().found(switchSetName))
78 cerr<< "debug::switchSet(const char*, dictionary*): " << std::endl
79 << " Cannot find " << switchSetName
80 << " in dictionary " << controlDictPtr_->name().c_str()
81 << std::endl << std::endl;
87 const_cast<dictionary*>(&(controlDict().subDict(switchSetName)));
96 dictionary& switchSet,
97 const char* switchName,
98 const int defaultValue
101 if (switchSet.found(switchName))
103 return readInt(switchSet.lookup(switchName));
107 switchSet.add(switchName, defaultValue);
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 dictionary& debug::controlDict()
119 if (!controlDictPtr_)
121 fileName controlDictFileName(dotFoam("controlDict"));
123 IFstream dictFile(controlDictFileName);
125 if (!dictFile.good())
127 cerr<< "debug::controlDict(): "
128 << "Cannot open essential file " << controlDictFileName.c_str()
129 << std::endl << std::endl;
133 controlDictPtr_ = new dictionary(dictFile);
136 return *controlDictPtr_;
140 dictionary& debug::debugSwitches()
142 return switchSet("DebugSwitches", debugSwitchesPtr_);
146 int debug::debugSwitch(const char* switchName, const int defaultValue)
157 dictionary& debug::infoSwitches()
159 return switchSet("InfoSwitches", infoSwitchesPtr_);
163 int debug::infoSwitch(const char* switchName, const int defaultValue)
174 dictionary& debug::optimisationSwitches()
176 return switchSet("OptimisationSwitches", optimisationSwitchesPtr_);
180 int debug::optimisationSwitch(const char* switchName, const int defaultValue)
184 optimisationSwitches(),
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 } // End namespace Foam
195 // ************************************************************************* //