token.C
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) 2011-2022 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 "token.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  const char* const token::typeName = "token";
34 
38 }
39 
40 
41 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
42 
43 void Foam::token::parseError(const char* expected) const
44 {
45  cerr<< "Parse error, expected a " << expected
46  << ", found \n " << info() << std::endl;
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
51 
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
57 
59 (
60  const word& compoundType,
61  Istream& is
62 )
63 {
64  IstreamConstructorTable::iterator cstrIter =
65  IstreamConstructorTablePtr_->find(compoundType);
66 
67  if (cstrIter == IstreamConstructorTablePtr_->end())
68  {
70  << "Unknown compound type " << compoundType << nl << nl
71  << "Valid compound types:" << endl
72  << IstreamConstructorTablePtr_->sortedToc()
73  << abort(FatalIOError);
74  }
75 
76  return autoPtr<Foam::token::compound>(cstrIter()(is));
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
83 {
84  return
85  (
86  IstreamConstructorTablePtr_
87  && IstreamConstructorTablePtr_->found(name)
88  );
89 }
90 
91 
93 {
94  if (type_ == COMPOUND)
95  {
96  if (compoundTokenPtr_->empty())
97  {
99  << "compound has already been transferred from token\n "
100  << info() << abort(FatalIOError);
101  }
102  else
103  {
104  compoundTokenPtr_->empty() = true;
105  }
106 
107  return *compoundTokenPtr_;
108  }
109  else
110  {
111  parseError("compound");
112  return *compoundTokenPtr_;
113  }
114 }
115 
116 
117 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Abstract base class for complex tokens.
Definition: token.H:130
static autoPtr< compound > New(const word &type, Istream &)
Select null constructed.
Definition: token.C:59
static bool isCompound(const word &name)
Return true if name is a compound type.
Definition: token.C:82
virtual ~compound()
Destructor.
Definition: token.C:52
compound & transferCompoundToken(const Istream &is)
Definition: token.C:92
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
static token undefinedToken
Static undefined token.
Definition: token.H:237
static const char *const typeName
Definition: token.H:280
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
Namespace for OpenFOAM.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
errorManip< error > abort(error &err)
Definition: errorManip.H:131
token::compound tokenCompound
Definition: token.C:35
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static const char nl
Definition: Ostream.H:260