OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Class for handling debugging switches.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "debug.H"
00031 #include "dictionary.H"
00032 #include "IFstream.H"
00033 #include "OSspecific.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039 namespace debug
00040 {
00041 
00043 dictionary* controlDictPtr_(NULL);
00044 dictionary* debugSwitchesPtr_(NULL);
00045 dictionary* infoSwitchesPtr_(NULL);
00046 dictionary* optimisationSwitchesPtr_(NULL);
00047 
00048 // to ensure controlDictPtr_ is deleted at the end of the run
00049 class deleteControlDictPtr
00050 {
00051 public:
00052 
00053     deleteControlDictPtr()
00054     {}
00055 
00056     ~deleteControlDictPtr()
00057     {
00058         if (controlDictPtr_)
00059         {
00060             delete controlDictPtr_;
00061             controlDictPtr_ = 0;
00062         }
00063     }
00064 };
00065 
00066 deleteControlDictPtr deleteControlDictPtr_;
00068 
00069 
00070 } // End namespace debug
00071 } // End namespace Foam
00072 
00073 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00074 
00075 Foam::dictionary& Foam::debug::controlDict()
00076 {
00077     if (!controlDictPtr_)
00078     {
00079         controlDictPtr_ = new dictionary
00080         (
00081             IFstream(findEtcFile("controlDict", true))()
00082         );
00083     }
00084 
00085     return *controlDictPtr_;
00086 }
00087 
00088 
00089 Foam::dictionary& Foam::debug::switchSet
00090 (
00091     const char* subDictName,
00092     dictionary*& subDictPtr
00093 )
00094 {
00095     if (!subDictPtr)
00096     {
00097         entry* ePtr = controlDict().lookupEntryPtr
00098         (
00099             subDictName, false, false
00100         );
00101 
00102         if (!ePtr || !ePtr->isDict())
00103         {
00104             cerr<< "debug::switchSet(const char*, dictionary*&):\n"
00105                 << "    Cannot find " <<  subDictName << " in dictionary "
00106                 << controlDict().name().c_str()
00107                 << std::endl << std::endl;
00108 
00109             ::exit(1);
00110         }
00111 
00112         subDictPtr = &ePtr->dict();
00113     }
00114 
00115     return *subDictPtr;
00116 }
00117 
00118 
00119 Foam::dictionary& Foam::debug::debugSwitches()
00120 {
00121     return switchSet("DebugSwitches", debugSwitchesPtr_);
00122 }
00123 
00124 
00125 Foam::dictionary& Foam::debug::infoSwitches()
00126 {
00127     return switchSet("InfoSwitches", infoSwitchesPtr_);
00128 }
00129 
00130 
00131 Foam::dictionary& Foam::debug::optimisationSwitches()
00132 {
00133     return switchSet("OptimisationSwitches", optimisationSwitchesPtr_);
00134 }
00135 
00136 
00137 int Foam::debug::debugSwitch(const char* name, const int defaultValue)
00138 {
00139     return debugSwitches().lookupOrAddDefault
00140     (
00141         name, defaultValue, false, false
00142     );
00143 }
00144 
00145 
00146 int Foam::debug::infoSwitch(const char* name, const int defaultValue)
00147 {
00148     return infoSwitches().lookupOrAddDefault
00149     (
00150         name, defaultValue, false, false
00151     );
00152 }
00153 
00154 
00155 int Foam::debug::optimisationSwitch(const char* name, const int defaultValue)
00156 {
00157     return optimisationSwitches().lookupOrAddDefault
00158     (
00159         name, defaultValue, false, false
00160     );
00161 }
00162 
00163 
00164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00165 
00166 
00167 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd