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 | Copyright (C) 2011-2012 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  {
70  FatalIOErrorIn("token::compound::New(const word&, Istream&)", is)
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  (
101  "token::transferCompoundToken(const Istream& is)",
102  is
103  ) << "compound has already been transfered from token\n "
104  << info() << abort(FatalIOError);
105  }
106  else
107  {
108  compoundTokenPtr_->empty() = true;
109  }
110 
111  return *compoundTokenPtr_;
112  }
113  else
114  {
115  parseError("compound");
116  return *compoundTokenPtr_;
117  }
118 }
119 
120 
121 // ************************************************************************* //
static token undefinedToken
Static undefined token.
Definition: token.H:241
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual ~compound()
Destructor.
Definition: token.C:53
A class for handling words, derived from string.
Definition: word.H:59
Namespace for OpenFOAM.
static const char *const typeName
Definition: token.H:280
static bool isCompound(const word &name)
Return true if name is a compound type.
Definition: token.C:83
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOerror FatalIOError
errorManip< error > abort(error &err)
Definition: errorManip.H:131
compound & transferCompoundToken(const Istream &is)
Definition: token.C:93
Abstract base class for complex tokens.
Definition: token.H:122
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
static autoPtr< compound > New(const word &type, Istream &)
Select null constructed.
Definition: token.C:60
token::compound tokenCompound
Definition: token.C:35
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
defineTypeNameAndDebug(combustionModel, 0)