functionObjectPropertiesTemplates.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "IOdictionary.H"
29
30// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31
32template<class Type>
34(
35 const word& objectName,
36 const word& entryName,
37 const Type& defaultValue
38) const
39{
40 Type result = defaultValue;
41 getObjectProperty(objectName, entryName, result);
42 return result;
43}
44
45
46template<class Type>
48(
49 const word& objectName,
50 const word& entryName,
51 Type& value
52) const
53{
54 if (this->found(objectName))
55 {
56 const dictionary& baseDict = this->subDict(objectName);
57 return baseDict.readIfPresent(entryName, value);
58 }
59
60 return false;
61}
62
63
64template<class Type>
66(
67 const word& objectName,
68 const word& entryName,
69 const Type& value
70)
71{
72 if (!this->found(objectName))
73 {
74 this->add(objectName, dictionary());
75 }
76
77 dictionary& baseDict = this->subDict(objectName);
78 baseDict.add(entryName, value, true);
79}
80
81
82template<class Type>
84(
85 const word& objectName,
86 const word& entryName,
87 const Type& value
88)
89{
90 if (!this->found(resultsName_))
91 {
92 this->add(resultsName_, dictionary());
93 }
94
95 dictionary& resultsDict = this->subDict(resultsName_);
96
97 if (!resultsDict.found(objectName))
98 {
99 resultsDict.add(objectName, dictionary());
100 }
101
102 dictionary& objectDict = resultsDict.subDict(objectName);
103
104 const word& dictTypeName = pTraits<Type>::typeName;
105
106 if (!objectDict.found(dictTypeName))
107 {
108 objectDict.add(dictTypeName, dictionary());
109 }
110
111 dictionary& resultTypeDict = objectDict.subDict(dictTypeName);
112
113 resultTypeDict.add(entryName, value, true);
114}
115
116
117template<class Type>
119(
120 const word& objectName,
121 const word& entryName,
122 const Type& defaultValue
123) const
124{
125 Type result = defaultValue;
126 (void)getObjectResult(objectName, entryName, result);
127 return result;
128}
129
130
131template<class Type>
133(
134 const word& objectName,
135 const word& entryName,
136 Type& value
137) const
138{
139 if (this->found(resultsName_))
140 {
141 const dictionary& resultsDict = this->subDict(resultsName_);
142
143 if (resultsDict.found(objectName))
144 {
145 const dictionary& objectDict = resultsDict.subDict(objectName);
146
147 const word& dictTypeName = pTraits<Type>::typeName;
148
149 if (objectDict.found(dictTypeName))
150 {
151 const dictionary& resultTypeDict =
152 objectDict.subDict(dictTypeName);
153
154 return resultTypeDict.readIfPresent<Type>(entryName, value);
155 }
156 }
157 }
158
159 return false;
160}
161
162
163// ************************************************************************* //
bool found
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
Definition: add.H:161
void setObjectResult(const word &objectName, const word &entryName, const Type &value)
Add result from named object.
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from named object.
void setObjectProperty(const word &objectName, const word &entryName, const Type &value)
Add generic property from named object.
Type getObjectResult(const word &objectName, const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve result from named object.
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:68