dynamicCodeContext.H
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-2024 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 Class
25  Foam::dynamicCodeContext
26 
27 Description
28  Encapsulation of dynamic code dictionaries
29 
30 SourceFiles
31  dynamicCodeContext.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef dynamicCodeContext_H
36 #define dynamicCodeContext_H
37 
38 #include "dictionary.H"
39 #include "HashTable.H"
40 #include "SHA1Digest.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class dynamicCodeContext Declaration
49 \*---------------------------------------------------------------------------*/
50 
52 {
53  // Private Data
54 
55  //- Keywords associated with source code
56  const wordList& codeKeys_;
57 
58  //- Name of the dictionary variables in the source code
59  const wordList& codeDictVars_;
60 
61  //- Code strings
62  // Stored to write for restart
63  List<verbatimString> codeStrings_;
64 
65  //- Code entries
66  HashTable<string> code_;
67 
68  //- Optional "codeOptions" string
69  // Stored to write for restart
70  verbatimString optionsString_;
71 
72  //- Optional "codeOptions" entry
73  string options_;
74 
75  //- Optional "codeLibs" string
76  // Stored to write for restart
77  verbatimString libsString_;
78 
79  //- Optional "codeLibs" entry
80  string libs_;
81 
82  //- Calculated SHA1Digest
83  SHA1Digest sha1_;
84 
85 
86  // Private Member Functions
87 
88  //- Add a \#line directive to the start of the given source string that
89  // compilation messages are meaningful
90  static void addLineDirective
91  (
92  string&,
93  const label lineNum,
94  const fileName& name
95  );
96 
97 
98 public:
99 
100  // Constructors
101 
102  //- Construct from the context and code dictionaries
103  // and lists of which entries correspond to code
105  (
106  const dictionary& contextDict,
107  const dictionary& codeDict,
108  const wordList& codeKeys,
109  const wordList& codeDictVars
110  );
111 
112  //- Construct from the context dictionary also containing the code
113  // and lists of which entries correspond
115  (
116  const dictionary& contextDict,
117  const wordList& codeKeys,
118  const wordList& codeDictVars
119  );
120 
121 
122  // Member Functions
123 
124  //- Return the code table
125  const HashTable<string>& code() const
126  {
127  return code_;
128  }
129 
130  //- Return the code-options
131  const string& options() const
132  {
133  return options_;
134  }
135 
136  //- Return the code-libs
137  const string& libs() const
138  {
139  return libs_;
140  }
141 
142  //- Return SHA1 digest calculated from include, options, code
143  const SHA1Digest& sha1() const
144  {
145  return sha1_;
146  }
147 
148  void read
149  (
150  const dictionary& contextDict,
151  const dictionary& codeDict
152  );
153 
154  void read(const dictionary& contextDict);
155 
156  //- Write the code for restart
157  void write(Ostream& os) const;
158 };
159 
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 } // End namespace Foam
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 #endif
168 
169 // ************************************************************************* //
An STL-conforming hash table.
Definition: HashTable.H:127
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
The SHA1 message digest.
Definition: SHA1Digest.H:63
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Encapsulation of dynamic code dictionaries.
const HashTable< string > & code() const
Return the code table.
dynamicCodeContext(const dictionary &contextDict, const dictionary &codeDict, const wordList &codeKeys, const wordList &codeDictVars)
Construct from the context and code dictionaries.
const string & options() const
Return the code-options.
const string & libs() const
Return the code-libs.
void write(Ostream &os) const
Write the code for restart.
const SHA1Digest & sha1() const
Return SHA1 digest calculated from include, options, code.
void read(const dictionary &contextDict, const dictionary &codeDict)
A class for handling file names.
Definition: fileName.H:82
A class for handling verbatimStrings, derived from string.
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.