calcEntry.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) 2011-2013 OpenFOAM Foundation
9  Copyright (C) 2018-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "calcEntry.H"
31 #include "dictionary.H"
32 #include "dynamicCode.H"
33 #include "codeStream.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace functionEntries
40 {
42  (
44  calcEntry,
45  execute,
46  dictionaryIstream,
47  calc
48  );
49 
51  (
53  calcEntry,
54  execute,
55  primitiveEntryIstream,
56  calc
57  );
58 } // End namespace functionEntries
59 } // End namespace Foam
60 
61 
62 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
63 
64 Foam::string Foam::functionEntries::calcEntry::evaluate
65 (
66  const dictionary& parentDict,
67  Istream& is
68 )
69 {
71  << "Using #calc at line " << is.lineNumber()
72  << " in file " << parentDict.name() << endl;
73 
75  (
76  "functionEntries::calcEntry::evaluate(..)",
77  parentDict
78  );
79 
80  // Read string
81  string s(is);
82 
83  // Construct codeDict for codeStream
84  dictionary codeSubDict;
85  codeSubDict.add("code", "os << (" + s + ");");
86  dictionary codeDict(parentDict, codeSubDict);
87 
88  // Use function to write stream
89  OStringStream os(is.format());
90 
91  streamingFunctionType function = getFunction(parentDict, codeDict);
92  (*function)(os, parentDict);
93 
94  // Return evaluated content as string
95  return os.str();
96 }
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 (
103  const dictionary& parentDict,
105  Istream& is
106 )
107 {
108  IStringStream result(evaluate(parentDict, is));
109  entry.read(parentDict, result);
110 
111  return true;
112 }
113 
114 
116 (
117  dictionary& parentDict,
118  Istream& is
119 )
120 {
121  IStringStream result(evaluate(parentDict, is));
122  parentDict.read(result);
123 
124  return true;
125 }
126 
127 
128 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::primitiveEntry
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
Definition: primitiveEntry.H:63
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
codeStream.H
Foam::functionEntries::calcEntry
Uses dynamic compilation to provide calculating functionality for entering dictionary entries.
Definition: calcEntry.H:69
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
Foam::functionEntries::codeStream::getFunction
static streamingFunctionType getFunction(const dictionary &parentDict, const dictionary &codeDict)
Construct, compile, load and return streaming function.
Definition: codeStream.C:112
Foam::functionEntries::codeStream::streamingFunctionType
void(* streamingFunctionType)(Ostream &, const dictionary &)
Interpreter function type.
Definition: codeStream.H:123
calcEntry.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::dynamicCode::checkSecurity
static void checkSecurity(const char *title, const dictionary &)
Check security for creating dynamic code.
Definition: dynamicCode.C:64
addToMemberFunctionSelectionTable.H
Macros for easy insertion into member function selection tables.
dynamicCode.H
DetailInfo
#define DetailInfo
Definition: evalEntry.C:36
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionEntries::addNamedToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
Foam::IStringStream
Input from string buffer, using a ISstream.
Definition: StringStream.H:111
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::dictionary::read
bool read(Istream &is)
Read dictionary from Istream.
Definition: dictionaryIO.C:141
Foam::functionEntry
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:65
dictionary.H
Foam::stringOps::evaluate
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Definition: stringOpsEvaluate.C:37
Foam::functionEntries::calcEntry::execute
static bool execute(const dictionary &parentDict, primitiveEntry &entry, Istream &is)
Execute in a primitiveEntry context.
Definition: calcEntry.C:102