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