ensightVarNameI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "error.H"
29 #include <cctype>
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 inline Foam::ensight::VarName::VarName(const char* s)
34 :
35  word(s, false)
36 {
37  stripInvalid();
38 }
39 
40 
41 inline Foam::ensight::VarName::VarName(const std::string& s)
42 :
43  word(s, false)
44 {
45  stripInvalid();
46 }
47 
48 
49 inline Foam::ensight::VarName::VarName(std::string&& s)
50 :
51  word(std::move(s), false)
52 {
53  stripInvalid();
54 }
55 
56 
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 
59 inline bool Foam::ensight::VarName::valid(char c)
60 {
61  return
62  (
63  word::valid(c) // includes space, quotes, /\;{}
64  && c != '!'
65  && c != '#'
66  && c != '%'
67  && c != '('
68  && c != ')'
69  && c != '*'
70  && c != '+'
71  && c != ','
72  && c != '-'
73  && c != '.'
74  && c != '@'
75  && c != '['
76  && c != ']'
77  && c != '^'
78  );
79 }
80 
81 
83 {
84  string::stripInvalid<ensight::VarName>(*this);
85 
86  if (empty())
87  {
89  << "ensight::VarName empty after stripping" << nl
90  << exit(FatalError);
91  }
92 
93  // Prefix with '_' to avoid starting with leading digits
94  if (std::isdigit(front()))
95  {
96  insert(0, 1, '_');
97  }
98 }
99 
100 
101 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
VarName(const VarName &)=default
Copy construct.
A class for handling words, derived from Foam::string.
Definition: word.H:63
static bool valid(char c)
Is this character valid for a word?
Definition: wordI.H:52
void stripInvalid()
Strip invalid characters.
const dimensionedScalar c
Speed of light in a vacuum.
static bool valid(char c)
Is this character valid for an ensight var-name.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))