From 3c9e050d6e4b3ee06d429614e6ebc32db5e2c7cf Mon Sep 17 00:00:00 2001 From: Andrew Heather <andy@shelob.opencfd.co.uk> Date: Fri, 21 Oct 2016 17:01:35 +0100 Subject: [PATCH] ENH: stateFunctionObject - separated dictionary access and updated api to return result status for retrieving properties --- .../stateFunctionObject/stateFunctionObject.C | 33 +++++++++++++++++++ .../stateFunctionObject/stateFunctionObject.H | 27 +++++++++++---- .../stateFunctionObjectTemplates.C | 28 +++++++--------- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C index 2a24995c343..43627cd4f2d 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C @@ -95,6 +95,39 @@ bool Foam::functionObjects::stateFunctionObject::foundProperty } +bool Foam::functionObjects::stateFunctionObject::getDict +( + const word& entryName, + dictionary& dict +) const +{ + return getObjectDict(name(), entryName, dict); +} + + +bool Foam::functionObjects::stateFunctionObject::getObjectDict +( + const word& objectName, + const word& entryName, + dictionary& dict +) const +{ + const IOdictionary& stateDict = this->stateDict(); + + if (stateDict.found(objectName)) + { + const dictionary& baseDict = stateDict.subDict(objectName); + if (baseDict.found(entryName) && baseDict.isDict(entryName)) + { + dict = baseDict.subDict(entryName); + return true; + } + } + + return false; +} + + Foam::word Foam::functionObjects::stateFunctionObject::resultType ( const word& entryName diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H index 20a5c669194..09cd289b9e0 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H @@ -125,6 +125,21 @@ public: //- Return true if the property exists bool foundProperty(const word& entryName) const; + //- Set dictionary, return true if set + bool getDict + ( + const word& entryName, + dictionary& dict + ) const; + + //- Set dictionary from named object, return true if set + bool getObjectDict + ( + const word& objectName, + const word& entryName, + dictionary& dict + ) const; + //- Retrieve generic property template<class Type> Type getProperty @@ -133,9 +148,9 @@ public: const Type& defaultValue = Type(Zero) ) const; - //- Retrieve generic property + //- Set generic property, return true if set template<class Type> - void getProperty(const word& entryName, Type& value) const; + bool getProperty(const word& entryName, Type& value) const; //- Add generic property template<class Type> @@ -150,9 +165,9 @@ public: const Type& defaultValue = Type(Zero) ) const; - //- Retrieve generic property from named object + //- Set generic property from named object, return true if set template<class Type> - void getObjectProperty + bool getObjectProperty ( const word& objectName, const word& entryName, @@ -205,9 +220,9 @@ public: const Type& defaultValue = Type(Zero) ) const; - //- Retrieve result from named object + //- Set result from named object, return true if set template<class Type> - void getObjectResult + bool getObjectResult ( const word& objectName, const word& entryName, diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObjectTemplates.C b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObjectTemplates.C index 35184d3ecab..cf8efceac8d 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObjectTemplates.C +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObjectTemplates.C @@ -41,13 +41,13 @@ Type Foam::functionObjects::stateFunctionObject::getProperty template<class Type> -void Foam::functionObjects::stateFunctionObject::getProperty +bool Foam::functionObjects::stateFunctionObject::getProperty ( const word& entryName, Type& value ) const { - getObjectProperty(name(), entryName, value); + return getObjectProperty(name(), entryName, value); } @@ -77,7 +77,7 @@ Type Foam::functionObjects::stateFunctionObject::getObjectProperty template<class Type> -void Foam::functionObjects::stateFunctionObject::getObjectProperty +bool Foam::functionObjects::stateFunctionObject::getObjectProperty ( const word& objectName, const word& entryName, @@ -89,18 +89,10 @@ void Foam::functionObjects::stateFunctionObject::getObjectProperty if (stateDict.found(objectName)) { const dictionary& baseDict = stateDict.subDict(objectName); - if (baseDict.found(entryName)) - { - if (baseDict.isDict(entryName)) - { - value = baseDict.subDict(entryName); - } - else - { - baseDict.lookup(entryName) >> value; - } - } + return baseDict.readIfPresent(entryName, value); } + + return false; } @@ -192,13 +184,13 @@ Type Foam::functionObjects::stateFunctionObject::getObjectResult ) const { Type result = defaultValue; - getObjectResult(objectName, entryName, result); + (void)getObjectResult(objectName, entryName, result); return result; } template<class Type> -void Foam::functionObjects::stateFunctionObject::getObjectResult +bool Foam::functionObjects::stateFunctionObject::getObjectResult ( const word& objectName, const word& entryName, @@ -222,10 +214,12 @@ void Foam::functionObjects::stateFunctionObject::getObjectResult const dictionary& resultTypeDict = objectDict.subDict(dictTypeName); - resultTypeDict.readIfPresent<Type>(entryName, value); + return resultTypeDict.readIfPresent<Type>(entryName, value); } } } + + return false; } -- GitLab