initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / global / debug / debug.C
blob89db274de5fc766f23a5a2667ee12d232d033709
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Description
26     Class for handling debugging switches.
28 \*---------------------------------------------------------------------------*/
30 #include "debug.H"
31 #include "dictionary.H"
32 #include "IFstream.H"
33 #include "OSspecific.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace Foam
39 namespace debug
42 //! @cond ignoreDocumentation - local scope
43 dictionary* controlDictPtr_(NULL);
44 dictionary* debugSwitchesPtr_(NULL);
45 dictionary* infoSwitchesPtr_(NULL);
46 dictionary* optimisationSwitchesPtr_(NULL);
48 // to ensure controlDictPtr_ is deleted at the end of the run
49 class deleteControlDictPtr
51 public:
53     deleteControlDictPtr()
54     {}
56     ~deleteControlDictPtr()
57     {
58         if (controlDictPtr_)
59         {
60             delete controlDictPtr_;
61             controlDictPtr_ = 0;
62         }
63     }
66 deleteControlDictPtr deleteControlDictPtr_;
67 //! @endcond ignoreDocumentation
70 } // End namespace debug
71 } // End namespace Foam
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 Foam::dictionary& Foam::debug::controlDict()
77     if (!controlDictPtr_)
78     {
79         controlDictPtr_ = new dictionary
80         (
81             IFstream(findEtcFile("controlDict", true))()
82         );
83     }
85     return *controlDictPtr_;
89 Foam::dictionary& Foam::debug::switchSet
91     const char* subDictName,
92     dictionary*& subDictPtr
95     if (!subDictPtr)
96     {
97         entry* ePtr = controlDict().lookupEntryPtr
98         (
99             subDictName, false, false
100         );
102         if (!ePtr || !ePtr->isDict())
103         {
104             cerr<< "debug::switchSet(const char*, dictionary*&):\n"
105                 << "    Cannot find " <<  subDictName << " in dictionary "
106                 << controlDict().name().c_str()
107                 << std::endl << std::endl;
109             ::exit(1);
110         }
112         subDictPtr = &ePtr->dict();
113     }
115     return *subDictPtr;
119 Foam::dictionary& Foam::debug::debugSwitches()
121     return switchSet("DebugSwitches", debugSwitchesPtr_);
125 Foam::dictionary& Foam::debug::infoSwitches()
127     return switchSet("InfoSwitches", infoSwitchesPtr_);
131 Foam::dictionary& Foam::debug::optimisationSwitches()
133     return switchSet("OptimisationSwitches", optimisationSwitchesPtr_);
137 int Foam::debug::debugSwitch(const char* name, const int defaultValue)
139     return debugSwitches().lookupOrAddDefault
140     (
141         name, defaultValue, false, false
142     );
146 int Foam::debug::infoSwitch(const char* name, const int defaultValue)
148     return infoSwitches().lookupOrAddDefault
149     (
150         name, defaultValue, false, false
151     );
155 int Foam::debug::optimisationSwitch(const char* name, const int defaultValue)
157     return optimisationSwitches().lookupOrAddDefault
158     (
159         name, defaultValue, false, false
160     );
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 // ************************************************************************* //