token.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Note
28  Included by global/globals.C
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "token.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
41 }
42 
44 
45 
46 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
47 
48 void Foam::token::parseError(const char* expected) const
49 {
51  << "Parse error, expected a " << expected
52  << ", found \n " << info() << endl;
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
57 
59 (
60  const word& compoundType,
61  Istream& is
62 )
63 {
64  auto* ctorPtr = IstreamConstructorTable(compoundType);
65 
66  if (!ctorPtr)
67  {
69  (
70  is,
71  "compound",
72  compoundType,
73  *IstreamConstructorTablePtr_
74  ) << abort(FatalIOError);
75  }
76 
77  return autoPtr<Foam::token::compound>(ctorPtr(is));
78 }
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 {
85  return
86  (
87  IstreamConstructorTablePtr_
88  && IstreamConstructorTablePtr_->found(name)
89  );
90 }
91 
92 
94 {
95  if (type_ != tokenType::COMPOUND)
96  {
97  parseError("compound");
98  }
99 
100  if (data_.compoundPtr->moved())
101  {
103  << "compound has already been transferred from token\n "
104  << info() << abort(FatalError);
105  }
106  else
107  {
108  data_.compoundPtr->moved(true);
109  }
110 
111  return *data_.compoundPtr;
112 }
113 
114 
116 {
117  if (type_ != tokenType::COMPOUND)
118  {
119  parseError("compound");
120  }
121 
122  if (data_.compoundPtr->moved())
123  {
125  << "compound has already been transferred from token\n "
126  << info() << abort(FatalIOError);
127  }
128  else
129  {
130  data_.compoundPtr->moved(true);
131  }
132 
133  return *data_.compoundPtr;
134 }
135 
136 
137 // ************************************************************************* //
static const token undefinedToken
An undefined token.
Definition: token.H:343
compound & transferCompoundToken()
Return reference to compound and mark internally as released.
Definition: token.C:86
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:578
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:788
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds an item read from Istream.
Definition: token.H:64
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
token::compound tokenCompound
Definition: token.C:31
Abstract base class for complex tokens.
Definition: token.H:173
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
A class for handling words, derived from Foam::string.
Definition: word.H:63
static autoPtr< compound > New(const word &type, Istream &is)
Construct compound from Istream.
Definition: token.C:52
errorManip< error > abort(error &err)
Definition: errorManip.H:139
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
static bool isCompound(const word &name)
Test if name is a known (registered) compound type.
Definition: token.C:76
defineTypeNameAndDebug(combustionModel, 0)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:607
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:615
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...