CodedSourceIO.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 | Copyright (C) 2012-2016 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 "CodedSource.H"
27 #include "stringOps.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
33 {
34  if (cellSetOption::read(dict))
35  {
36  coeffs_.lookup("fields") >> fieldNames_;
37  applied_.setSize(fieldNames_.size(), false);
38 
39  // Backward compatibility
40  if (dict.found("redirectType"))
41  {
42  dict.lookup("redirectType") >> name_;
43  }
44  else
45  {
46  dict.lookup("name") >> name_;
47  }
48 
49  // Code snippets
50  {
51  const entry& e = coeffs_.lookupEntry
52  (
53  "codeCorrect",
54  false,
55  false
56  );
57  codeCorrect_ = stringOps::trim(e.stream());
58  stringOps::inplaceExpand(codeCorrect_, coeffs_);
59  dynamicCodeContext::addLineDirective
60  (
61  codeCorrect_,
62  e.startLineNumber(),
63  coeffs_.name()
64  );
65  }
66 
67  {
68  const entry& e = coeffs_.lookupEntry
69  (
70  "codeAddSup",
71  false,
72  false
73  );
74  codeAddSup_ = stringOps::trim(e.stream());
75  stringOps::inplaceExpand(codeAddSup_, coeffs_);
76  dynamicCodeContext::addLineDirective
77  (
78  codeAddSup_,
79  e.startLineNumber(),
80  coeffs_.name()
81  );
82  }
83 
84  {
85  const entry& e = coeffs_.lookupEntry
86  (
87  "codeSetValue",
88  false,
89  false
90  );
91  codeSetValue_ = stringOps::trim(e.stream());
92  stringOps::inplaceExpand(codeSetValue_, coeffs_);
93  dynamicCodeContext::addLineDirective
94  (
95  codeSetValue_,
96  e.startLineNumber(),
97  coeffs_.name()
98  );
99  }
100 
101  return true;
102  }
103  else
104  {
105  return false;
106  }
107 }
108 
109 
110 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual label startLineNumber() const =0
Return line number of first token in dictionary.
string trim(const string &)
Return string trimmed of leading and trailing whitespace.
Definition: stringOps.C:923
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: CodedSourceIO.C:32
bool read(const char *, int32_t &)
Definition: int32IO.C:85
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:78
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
string & inplaceExpand(string &, const HashTable< string, word, string::hash > &mapping, const char sigil= '$')
Inplace expand occurences of variables according to the mapping.
Definition: stringOps.C:87
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451