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-------------------------------------------------------------------------------
11License
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
33namespace Foam
34{
38}
39
41
42
43// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
44
45void 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// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Abstract base class for complex tokens.
Definition: token.H:171
A token holds an item read from Istream.
Definition: token.H:69
compound & transferCompoundToken()
Return reference to compound and mark internally as released.
Definition: token.C:90
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
bool isCompound() const noexcept
Token is COMPOUND.
Definition: tokenI.H:716
static const token undefinedToken
An undefined token.
Definition: token.H:294
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
token::compound tokenCompound
Definition: token.C:35
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
IOerror FatalIOError
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.