FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

debug.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     Class for handling debugging switches.
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "debug.H"
00030 #include <OpenFOAM/dictionary.H>
00031 #include <OpenFOAM/IFstream.H>
00032 #include <OpenFOAM/OSspecific.H>
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 namespace debug
00039 {
00040 
00042 dictionary* controlDictPtr_(NULL);
00043 dictionary* debugSwitchesPtr_(NULL);
00044 dictionary* infoSwitchesPtr_(NULL);
00045 dictionary* optimisationSwitchesPtr_(NULL);
00046 
00047 // to ensure controlDictPtr_ is deleted at the end of the run
00048 class deleteControlDictPtr
00049 {
00050 public:
00051 
00052     deleteControlDictPtr()
00053     {}
00054 
00055     ~deleteControlDictPtr()
00056     {
00057         if (controlDictPtr_)
00058         {
00059             delete controlDictPtr_;
00060             controlDictPtr_ = 0;
00061         }
00062     }
00063 };
00064 
00065 deleteControlDictPtr deleteControlDictPtr_;
00067 
00068 
00069 } // End namespace debug
00070 } // End namespace Foam
00071 
00072 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00073 
00074 Foam::dictionary& Foam::debug::controlDict()
00075 {
00076     if (!controlDictPtr_)
00077     {
00078         controlDictPtr_ = new dictionary
00079         (
00080             IFstream(findEtcFile("controlDict", true))()
00081         );
00082     }
00083 
00084     return *controlDictPtr_;
00085 }
00086 
00087 
00088 Foam::dictionary& Foam::debug::switchSet
00089 (
00090     const char* subDictName,
00091     dictionary*& subDictPtr
00092 )
00093 {
00094     if (!subDictPtr)
00095     {
00096         entry* ePtr = controlDict().lookupEntryPtr
00097         (
00098             subDictName, false, false
00099         );
00100 
00101         if (!ePtr || !ePtr->isDict())
00102         {
00103             cerr<< "debug::switchSet(const char*, dictionary*&):\n"
00104                 << "    Cannot find " <<  subDictName << " in dictionary "
00105                 << controlDict().name().c_str()
00106                 << std::endl << std::endl;
00107 
00108             ::exit(1);
00109         }
00110 
00111         subDictPtr = &ePtr->dict();
00112     }
00113 
00114     return *subDictPtr;
00115 }
00116 
00117 
00118 Foam::dictionary& Foam::debug::debugSwitches()
00119 {
00120     return switchSet("DebugSwitches", debugSwitchesPtr_);
00121 }
00122 
00123 
00124 Foam::dictionary& Foam::debug::infoSwitches()
00125 {
00126     return switchSet("InfoSwitches", infoSwitchesPtr_);
00127 }
00128 
00129 
00130 Foam::dictionary& Foam::debug::optimisationSwitches()
00131 {
00132     return switchSet("OptimisationSwitches", optimisationSwitchesPtr_);
00133 }
00134 
00135 
00136 int Foam::debug::debugSwitch(const char* name, const int defaultValue)
00137 {
00138     return debugSwitches().lookupOrAddDefault
00139     (
00140         name, defaultValue, false, false
00141     );
00142 }
00143 
00144 
00145 int Foam::debug::infoSwitch(const char* name, const int defaultValue)
00146 {
00147     return infoSwitches().lookupOrAddDefault
00148     (
00149         name, defaultValue, false, false
00150     );
00151 }
00152 
00153 
00154 int Foam::debug::optimisationSwitch(const char* name, const int defaultValue)
00155 {
00156     return optimisationSwitches().lookupOrAddDefault
00157     (
00158         name, defaultValue, false, false
00159     );
00160 }
00161 
00162 
00163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00164 
00165 
00166 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines