calcEntry.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) 2011-2020 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 "calcEntry.H"
28 #include "dictionary.H"
29 #include "dynamicCode.H"
30 #include "codeStream.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionEntries
37 {
39 
41  (
43  calcEntry,
44  execute,
45  dictionaryIstream
46  );
47 
49  (
51  calcEntry,
52  execute,
53  primitiveEntryIstream
54  );
55 
56 }
57 }
58 
59 
60 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
61 
62 Foam::string Foam::functionEntries::calcEntry::calc
63 (
64  const dictionary& dict,
65  Istream& is
66 )
67 {
68  Info<< "Using #calcEntry at line " << is.lineNumber()
69  << " in file " << dict.name() << endl;
70 
72  (
73  "functionEntries::calcEntry::execute(..)",
74  dict
75  );
76 
77  // Read string
78  string s(is);
79 
80  // Construct codeDict for codeStream
81  // Must reference parent dictionary for stringOps::expand to work
82  dictionary codeDict(dict.parent(), dict);
83  codeDict.add("code", "os << (" + s + ");");
84 
85  codeStream::streamingFunctionType function = codeStream::getFunction
86  (
87  dict,
88  codeDict
89  );
90 
91  // Use function to write stream
92  OStringStream os(is.format());
93  (*function)(os, dict);
94 
95  // Return the string containing the results of the calculation
96  return os.str();
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 (
104  dictionary& dict,
105  Istream& is
106 )
107 {
108  return insert(dict, calc(dict, is));
109 }
110 
111 
113 (
114  const dictionary& dict,
115  primitiveEntry& thisEntry,
116  Istream& is
117 )
118 {
119  return insert(dict, thisEntry, calc(dict, is));
120 }
121 
122 
123 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Uses dynamic compilation to provide calculating functionality for entering dictionary entries...
Definition: calcEntry.H:69
label lineNumber() const
Return current stream line number.
Definition: IOstream.H:438
addToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream)
void insert(const scalar, DynamicList< floatScalar > &)
Append scalar to given DynamicList.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1056
static bool execute(dictionary &dict, Istream &)
Execute the functionEntry in a sub-dict context.
Definition: calcEntry.C:103
A keyword and a list of tokens is a &#39;primitiveEntry&#39;. An primitiveEntry can be read, written and printed, and the types and values of its tokens analysed.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:296
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:63
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
string str() const
Return the string.
Macros for easy insertion into member function selection tables.
messageStream Info
static void checkSecurity(const char *title, const dictionary &)
Check security for creating dynamic code.
Definition: dynamicCode.C:58
A class for handling character strings derived from std::string.
Definition: string.H:76
Output to memory buffer stream.
Definition: OStringStream.H:49
defineTypeNameAndDebug(calcEntry, 0)
Namespace for OpenFOAM.