BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / global / debug / debug.C
blobcd2a0b2486c557dace472cd64531c8f603f36f5b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Description
25     Class for handling debugging switches.
27 \*---------------------------------------------------------------------------*/
29 #include "debug.H"
30 #include "dictionary.H"
31 #include "IFstream.H"
32 #include "OSspecific.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
38 namespace debug
41 //! \cond ignoreDocumentation - local scope
42 dictionary* controlDictPtr_(NULL);
43 dictionary* debugSwitchesPtr_(NULL);
44 dictionary* infoSwitchesPtr_(NULL);
45 dictionary* optimisationSwitchesPtr_(NULL);
47 // to ensure controlDictPtr_ is deleted at the end of the run
48 class deleteControlDictPtr
50 public:
52     deleteControlDictPtr()
53     {}
55     ~deleteControlDictPtr()
56     {
57         if (controlDictPtr_)
58         {
59             delete controlDictPtr_;
60             controlDictPtr_ = 0;
61         }
62     }
65 deleteControlDictPtr deleteControlDictPtr_;
66 //! \endcond
69 } // End namespace debug
70 } // End namespace Foam
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 Foam::dictionary& Foam::debug::controlDict()
76     if (!controlDictPtr_)
77     {
78         fileNameList controlDictFiles = findEtcFiles("controlDict", true);
79         controlDictPtr_ = new dictionary();
80         forAllReverse(controlDictFiles, cdfi)
81         {
82             controlDictPtr_->merge
83             (
84                 dictionary(IFstream(controlDictFiles[cdfi])())
85             );
86         }
87     }
89     return *controlDictPtr_;
93 Foam::dictionary& Foam::debug::switchSet
95     const char* subDictName,
96     dictionary*& subDictPtr
99     if (!subDictPtr)
100     {
101         entry* ePtr = controlDict().lookupEntryPtr
102         (
103             subDictName, false, false
104         );
106         if (!ePtr || !ePtr->isDict())
107         {
108             cerr<< "debug::switchSet(const char*, dictionary*&):\n"
109                 << "    Cannot find " <<  subDictName << " in dictionary "
110                 << controlDict().name().c_str()
111                 << std::endl << std::endl;
113             ::exit(1);
114         }
116         subDictPtr = &ePtr->dict();
117     }
119     return *subDictPtr;
123 Foam::dictionary& Foam::debug::debugSwitches()
125     return switchSet("DebugSwitches", debugSwitchesPtr_);
129 Foam::dictionary& Foam::debug::infoSwitches()
131     return switchSet("InfoSwitches", infoSwitchesPtr_);
135 Foam::dictionary& Foam::debug::optimisationSwitches()
137     return switchSet("OptimisationSwitches", optimisationSwitchesPtr_);
141 int Foam::debug::debugSwitch(const char* name, const int defaultValue)
143     return debugSwitches().lookupOrAddDefault
144     (
145         name, defaultValue, false, false
146     );
150 int Foam::debug::infoSwitch(const char* name, const int defaultValue)
152     return infoSwitches().lookupOrAddDefault
153     (
154         name, defaultValue, false, false
155     );
159 int Foam::debug::optimisationSwitch(const char* name, const int defaultValue)
161     return optimisationSwitches().lookupOrAddDefault
162     (
163         name, defaultValue, false, false
164     );
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 // ************************************************************************* //