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 \*---------------------------------------------------------------------------*/
28 
29 #include "token.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
38 }
39 
41 
42 
43 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
44 
45 void Foam::token::parseError(const char* expected) const
46 {
48  << "Parse error, expected a " << expected
49  << ", found \n " << info() << endl;
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
54 
56 (
57  const word& compoundType,
58  Istream& is
59 )
60 {
61  auto* ctorPtr = IstreamConstructorTable(compoundType);
62 
63  if (!ctorPtr)
64  {
66  (
67  is,
68  "compound",
69  compoundType,
70  *IstreamConstructorTablePtr_
71  ) << abort(FatalIOError);
72  }
73 
74  return autoPtr<Foam::token::compound>(ctorPtr(is));
75 }
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
81 {
82  return
83  (
84  IstreamConstructorTablePtr_
85  && IstreamConstructorTablePtr_->found(name)
86  );
87 }
88 
89 
91 {
92  if (type_ != tokenType::COMPOUND)
93  {
94  parseError("compound");
95  }
96 
97  if (data_.compoundPtr->moved())
98  {
100  << "compound has already been transferred from token\n "
101  << info() << abort(FatalError);
102  }
103  else
104  {
105  data_.compoundPtr->moved(true);
106  }
107 
108  return *data_.compoundPtr;
109 }
110 
111 
113 {
114  if (type_ != tokenType::COMPOUND)
115  {
116  parseError("compound");
117  }
118 
119  if (data_.compoundPtr->moved())
120  {
122  << "compound has already been transferred from token\n "
123  << info() << abort(FatalIOError);
124  }
125  else
126  {
127  data_.compoundPtr->moved(true);
128  }
129 
130  return *data_.compoundPtr;
131 }
132 
133 
134 // ************************************************************************* //
token.H
Foam::tokenCompound
token::compound tokenCompound
Definition: token.C:35
Foam::token::compound
Abstract base class for complex tokens.
Definition: token.H:168
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
Foam::token::info
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::token::compound::isCompound
static bool isCompound(const word &name)
Test if name is a known (registered) compound type.
Definition: token.C:80
Foam::token::undefinedToken
static const token undefinedToken
An undefined token.
Definition: token.H:294
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::token::transferCompoundToken
compound & transferCompoundToken()
Return reference to compound and mark internally as released.
Definition: token.C:90
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::token::compound::New
static autoPtr< compound > New(const word &type, Istream &is)
Construct compound from Istream.
Definition: token.C:56
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)