negEntry.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "negEntry.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace functionEntries
34 {
36 
38  (
40  negEntry,
41  execute,
42  primitiveEntryIstream
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 Foam::string Foam::functionEntries::negEntry::negateVariable
51 (
52  const dictionary& parentDict,
53  Istream& is
54 )
55 {
56  // Read variable name as a word including the '$'
57  const variable var(is);
58 
59  // Strip the leading '$' from the variable name
60  const string varName = var(1, var.size() - 1);
61 
62  // Lookup the variable name in the parent dictionary....
63  const entry* ePtr = parentDict.lookupScopedEntryPtr(varName, true, false);
64 
65  if (ePtr && ePtr->isStream())
66  {
67  const token variable(ePtr->stream());
68 
69  // Convert to a string
70  OStringStream os(is.format());
71  os << variable;
72  const string str(os.str());
73 
74  // Negate
75  if (str[0] == '-')
76  {
77  return str(1, str.size() - 1);
78  }
79  else
80  {
81  return '-' + str;
82  }
83  }
84  else
85  {
87  (
88  parentDict
89  ) << "Unknown dictionary variable name " << varName << endl
90  << "Valid dictionary entries are " << parentDict.toc()
91  << exit(FatalIOError);
92 
93  return string::null;
94  }
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 (
102  const dictionary& contextDict,
103  primitiveEntry& contextEntry,
104  Istream& is
105 )
106 {
107  return insert(contextDict, contextEntry, negateVariable(contextDict, is));
108 }
109 
110 
111 // ************************************************************************* //
Macros for easy insertion into member function selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
entry(const keyType &key, const label keywordLineNumber)
Construct from keyword and corresponding line number.
Definition: entry.C:40
Negate a variable by prefixing with neg.
Definition: negEntry.H:67
virtual bool execute(dictionary &contextDict, Istream &is)
Expand the functionEntry into the contextDict.
Definition: negEntry.H:93
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
A class for handling character strings derived from std::string.
Definition: string.H:79
static const string null
An empty string.
Definition: string.H:88
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
defineFunctionTypeNameAndDebug(includeFvConstraintEntry, 0)
addToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, primitiveEntryIstream)
void insert(const scalar, DynamicList< floatScalar > &)
Append scalar to given DynamicList.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
IOerror FatalIOError