diff --git a/src/OpenFOAM/dimensionSet/dimensionSets.C b/src/OpenFOAM/dimensionSet/dimensionSets.C index 7486781df8..10b424a576 100644 --- a/src/OpenFOAM/dimensionSet/dimensionSets.C +++ b/src/OpenFOAM/dimensionSet/dimensionSets.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,15 +35,29 @@ namespace Foam /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ -dictionary* dimensionSystemsPtr_(NULL); +//- Since dimensionSystems() can be reread we actually store a copy of +// the controlDict subDict (v.s. a reference to the subDict for e.g. +// dimensionedConstants) +autoPtr dimensionSystemsPtr_(NULL); dictionary& dimensionSystems() { - return debug::switchSet - ( - "DimensionSets", - dimensionSystemsPtr_ - ); + if (!dimensionSystemsPtr_.valid()) + { + dictionary* cachedPtr = NULL; + dimensionSystemsPtr_.reset + ( + new dictionary + ( + debug::switchSet + ( + "DimensionSets", + cachedPtr + ) + ) + ); + } + return dimensionSystemsPtr_(); } @@ -63,10 +77,9 @@ public: {} virtual void readData(Foam::Istream& is) { - deleteDemandDrivenData(dimensionSystemsPtr_); unitSetPtr_.clear(); writeUnitSetPtr_.clear(); - dimensionSystemsPtr_ = new dictionary(is); + dimensionSystemsPtr_.reset(new dictionary(is)); } virtual void writeData(Foam::Ostream& os) const { diff --git a/src/OpenFOAM/global/debug/debug.C b/src/OpenFOAM/global/debug/debug.C index 999b4cb292..c7cfcc7186 100644 --- a/src/OpenFOAM/global/debug/debug.C +++ b/src/OpenFOAM/global/debug/debug.C @@ -47,6 +47,14 @@ dictionary* debugSwitchesPtr_(NULL); dictionary* infoSwitchesPtr_(NULL); dictionary* optimisationSwitchesPtr_(NULL); +// Debug switch read and write callback tables. +simpleObjectRegistry* debugObjectsPtr_(NULL); +simpleObjectRegistry* infoObjectsPtr_(NULL); +simpleObjectRegistry* optimisationObjectsPtr_(NULL); +simpleObjectRegistry* dimensionSetObjectsPtr_(NULL); +simpleObjectRegistry* dimensionedConstantObjectsPtr_(NULL); + + // to ensure controlDictPtr_ is deleted at the end of the run class deleteControlDictPtr { @@ -56,38 +64,21 @@ public: {} ~deleteControlDictPtr() - { - deleteDemandDrivenData(controlDictPtr_); - } -}; - -deleteControlDictPtr deleteControlDictPtr_; - - -// Debug switch read and write callback tables. -simpleObjectRegistry* debugObjectsPtr_(NULL); -simpleObjectRegistry* infoObjectsPtr_(NULL); -simpleObjectRegistry* optimisationObjectsPtr_(NULL); -simpleObjectRegistry* dimensionSetObjectsPtr_(NULL); -simpleObjectRegistry* dimensionedConstantObjectsPtr_(NULL); -class deleteDebugSwitchPtr -{ -public: - - deleteDebugSwitchPtr() - {} - - ~deleteDebugSwitchPtr() { deleteDemandDrivenData(debugObjectsPtr_); deleteDemandDrivenData(infoObjectsPtr_); deleteDemandDrivenData(optimisationObjectsPtr_); deleteDemandDrivenData(dimensionSetObjectsPtr_); deleteDemandDrivenData(dimensionedConstantObjectsPtr_); + + debugSwitchesPtr_ = NULL; + infoSwitchesPtr_ = NULL; + optimisationSwitchesPtr_ = NULL; + deleteDemandDrivenData(controlDictPtr_); } }; -deleteDebugSwitchPtr deleteDebugSwitchPtr_; +deleteControlDictPtr deleteControlDictPtr_; //! \endcond