All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
variableI.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) 2019 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 <cctype>
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 inline void Foam::variable::stripInvalid()
31 {
32  // skip stripping unless debug is active to avoid
33  // costly operations
34  if (debug && string::stripInvalid<variable>(*this))
35  {
36  std::cerr
37  << "variable::stripInvalid() called for variable "
38  << this->c_str() << std::endl;
39 
40  if (debug > 1)
41  {
42  std::cerr
43  << " For debug level (= " << debug
44  << ") > 1 this is considered fatal" << std::endl;
45  std::abort();
46  }
47  }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 :
55  word()
56 {}
57 
58 
60 :
61  word(v)
62 {}
63 
64 
66 :
67  word(w)
68 {}
69 
70 
71 inline Foam::variable::variable(const string& s, const bool doStripInvalid)
72 :
73  word(s)
74 {
75  if (doStripInvalid)
76  {
77  stripInvalid();
78  }
79 }
80 
81 
82 inline Foam::variable::variable(const std::string& s, const bool doStripInvalid)
83 :
84  word(s)
85 {
86  if (doStripInvalid)
87  {
88  stripInvalid();
89  }
90 }
91 
92 
93 inline Foam::variable::variable(const char* s, const bool doStripInvalid)
94 :
95  word(s)
96 {
97  if (doStripInvalid)
98  {
99  stripInvalid();
100  }
101 }
102 
103 
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105 
106 inline bool Foam::variable::valid(char c)
107 {
108  return
109  (
110  !isspace(c)
111  && c != '"' // string quote
112  && c != '\'' // string quote
113  && c != ';' // end statement
114  && c != '{' // beg subdict
115  && c != '}' // end subdict
116  );
117 }
118 
119 
120 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
121 
123 {
125 }
126 
127 
128 inline void Foam::variable::operator=(const word& s)
129 {
131 }
132 
133 
134 inline void Foam::variable::operator=(const string& s)
135 {
137  stripInvalid();
138 }
139 
140 
141 inline void Foam::variable::operator=(const std::string& s)
142 {
144  stripInvalid();
145 }
146 
147 
148 inline void Foam::variable::operator=(const char* s)
149 {
151  stripInvalid();
152 }
153 
154 
155 // ************************************************************************* //
static bool valid(char)
Is this character valid for a variable.
Definition: variableI.H:106
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static int debug
Definition: variable.H:73
const dimensionedScalar & c
Speed of light in a vacuum.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().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))
variable()
Construct null.
Definition: variableI.H:53
A class for handling words, derived from string.
Definition: word.H:59
void operator=(const variable &)
Definition: variableI.H:122
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool isspace(char c)
Definition: char.H:53
void operator=(const string &)
Definition: stringI.H:229
A variable is a word with support for additional characters, in particular &#39;$&#39; and &#39;/&#39;...
Definition: variable.H:58