CodedBase.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) 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 "CodedBase.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 template<class CodedType>
31 const Foam::word Foam::CodedBase<CodedType>::codeTemplateC =
32  Foam::word(CodedType::typeName_()) + "Template.C";
33 
34 template<class CodedType>
35 const Foam::word Foam::CodedBase<CodedType>::codeTemplateH =
36  Foam::word(CodedType::typeName_()) + "Template.H";
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 template<class CodedType>
42 const Foam::wordList&
44 {
45  return codeKeys_;
46 }
47 
48 
49 template<class CodedType>
51 {
52  return CodedType::typeName + " " + codeName();
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
58 template<class CodedType>
60 :
61  codeName_(dict.lookup("name")),
62  dict_(dict)
63 {}
64 
65 
66 template<class CodedType>
68 :
69  codeName_(cb.codeName_),
70  dict_(cb.dict_)
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
75 
76 
77 template<class CodedType>
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
84 template<class CodedType>
86 {
87  return codeName_;
88 }
89 
90 
91 template<class CodedType>
92 const Foam::dictionary&
94 {
95  return dict_;
96 }
97 
98 
99 template<class CodedType>
101 {
102  writeEntry(os, "name", codeName_);
103 
104  forAll(codeKeys_, i)
105  {
106  if (dict_.found(codeKeys_[i]))
107  {
108  writeKeyword(os, codeKeys_[i]);
109  os.write(verbatimString(dict_[codeKeys_[i]]))
110  << token::END_STATEMENT << nl;
111  }
112  }
113 }
114 
115 
116 // ************************************************************************* //
A class for handling verbatimStrings, derived from string.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual Ostream & write(const char)=0
Write character.
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
Definition: keyType.C:155
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
virtual const dictionary & codeDict() const
Get the dictionary to initialize the codeContext.
Definition: CodedBase.C:93
virtual const word & codeName() const
Name of the dynamically generated CodedType.
Definition: CodedBase.C:85
stressControl lookup("compactNormalStress") >> compactNormalStress
A class for handling words, derived from string.
Definition: word.H:59
Templated wrapper class to reduce code duplication and simplify maintenance of coded classes...
Definition: CodedBase.H:49
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
CodedBase()
Construct null.
Definition: CodedBase.H:88
virtual ~CodedBase()
Destructor.
Definition: CodedBase.C:78
void writeCode(Ostream &os) const
Definition: CodedBase.C:100
A class for handling character strings derived from std::string.
Definition: string.H:76