Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
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 
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 } 
00070 } 
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