/
codeStream.H
190 lines (137 loc) · 5.45 KB
/
codeStream.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionEntries::codeStream
Description
Dictionary entry that contains C++ OpenFOAM code that is compiled to
generate the entry itself. So
- codeStream reads three entries: 'code', 'codeInclude' (optional),
'codeOptions' (optional)
and uses those to generate library sources inside \c codeStream/
- these get compiled using 'wmake libso'
- the resulting library is loaded in executed with as arguments
\code
(const dictionary& dict, Ostream& os)
\endcode
where the dictionary is the current dictionary.
- the code has to write into Ostream which is then used to construct
the actual dictionary entry.
E.g. to set the internal field of a field:
\verbatim
internalField #codeStream
{
code
#{
const IOdictionary& d = static_cast<const IOdictionary&>(dict);
const fvMesh& mesh = refCast<const fvMesh>(d.db());
scalarField fld(mesh.nCells(), 12.34);
fld.writeEntry("", os);
#};
//- Optional:
codeInclude
#{
#include "fvCFD.H"
#};
//- Optional:
codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude
#};
};
\endverbatim
Note the \c \#{ ... \c \#} syntax is a 'verbatim' input mode that allows
inputting strings with embedded newlines.
Limitations:
- '~' symbol not allowed inside the code sections.
- probably some other limitations (uses string::expand which expands
\c \$ and \c ~ sequences)
Note
The code to be compiled is stored under the local \c codeStream directory
with a subdirectory name corresponding to the SHA1 of the contents.
The corresponding library code is located under the local
\c codeStream/platforms/$WM_OPTIONS/lib directory in a library
\c libcodeStream_SHA1.so
SourceFiles
codeStream.C
\*---------------------------------------------------------------------------*/
#ifndef codeStream_H
#define codeStream_H
#include "functionEntry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class dlLibraryTable;
namespace functionEntries
{
// Forward declaration of friend classes
class calcEntry;
/*---------------------------------------------------------------------------*\
Class codeStream Declaration
\*---------------------------------------------------------------------------*/
class codeStream
:
public functionEntry
{
//- Interpreter function type
typedef void (*streamingFunctionType)(Ostream&, const dictionary&);
// Private Member Functions
//- Helper function: parent (of parent etc.) of dictionary up to the top
static const dictionary& topDict(const dictionary&);
//- Helper function: access IOobject for master-only-reading
// functionality
static bool doingMasterOnlyReading(const dictionary& dict);
//- Helper function: access to dlLibraryTable of Time
static dlLibraryTable& libs(const dictionary& dict);
//- Construct, compile, load and return streaming function
static streamingFunctionType getFunction
(
const dictionary& parentDict,
const dictionary& codeDict
);
//- Disallow default bitwise copy construct
codeStream(const codeStream&);
//- Disallow default bitwise assignment
void operator=(const codeStream&);
public:
// Static data members
//- Name of the C code template to be used
static const word codeTemplateC;
// Related types
//- Declare friendship with the calcEntry class
friend class calcEntry;
//- Runtime type information
ClassName("codeStream");
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
//- Execute the functionEntry in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry&,
Istream&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionEntries
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //