1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 A token holds items read from Istream.
35 \*---------------------------------------------------------------------------*/
44 #include "InfoProxy.H"
49 #include "runTimeSelectionTables.H"
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 // Forward declaration of friend functions and operators
61 Istream& operator>>(Istream&, token&);
62 Ostream& operator<<(Ostream&, const token&);
64 /*---------------------------------------------------------------------------*\
65 Class token Declaration
66 \*---------------------------------------------------------------------------*/
73 //- Enumeration defining the types of token
91 //- Standard punctuation tokens
111 END_STRING = BEGIN_STRING,
121 //- Abstract base class for complex tokens
131 // Private Member Functions
133 //- Disallow default bitwise copy construct
134 compound(const compound&);
136 //- Disallow default bitwise assignment
137 void operator=(const compound&);
142 //- Runtime type information
143 TypeName("compound");
146 //- Declare run-time constructor selection table
147 declareRunTimeSelectionTable
168 //- Select null constructed
169 static autoPtr<compound> New(const word& type, Istream&);
180 //- Return true if name is a compound type
181 static bool isCompound(const word& name);
193 virtual label size() const = 0;
202 virtual void write(Ostream&) const = 0;
205 // IOstream Operators
207 friend Ostream& operator<<(Ostream&, const compound&);
211 //- A templated class for holding compound tokens
215 public token::compound,
220 //- Runtime type information
221 TypeName("Compound<T>");
223 Compound(Istream& is)
233 void write(Ostream& os) const
235 operator<<(os, static_cast<const T&>(*this));
240 //- Static undefined token
241 static token undefinedToken;
251 //- Anonymous Union of token types
254 punctuationToken punctuationToken_;
256 string* stringTokenPtr_;
258 floatScalar floatScalarToken_;
259 doubleScalar doubleScalarToken_;
260 mutable compound* compoundTokenPtr_;
263 //- Line number in the file this token was read from
267 // Private Member Functions
269 //- Clear any allocated storage (word or string)
272 // Parse error, expected 'expected', found ...
273 void parseError(const char* expected) const;
278 // Static data members
280 static const char* const typeName;
288 //- Construct as copy
289 inline token(const token&);
291 //- Construct punctuation character token
292 inline token(punctuationToken, label lineNumber=0);
294 //- Construct word token
295 inline token(const word&, label lineNumber=0);
297 //- Construct string token
298 inline token(const string&, label lineNumber=0);
300 //- Construct label token
301 inline token(const label, label lineNumber=0);
303 //- Construct floatScalar token
304 inline token(const floatScalar, label lineNumber=0);
306 //- Construct doubleScalar token
307 inline token(const doubleScalar, label lineNumber=0);
309 //- Construct from Istream
321 inline tokenType type() const;
322 inline tokenType& type();
324 inline bool good() const;
325 inline bool undefined() const;
326 inline bool error() const;
328 inline bool isPunctuation() const;
329 inline punctuationToken pToken() const;
331 inline bool isWord() const;
332 inline const word& wordToken() const;
334 inline bool isString() const;
335 inline const string& stringToken() const;
337 inline bool isLabel() const;
338 inline label labelToken() const;
340 inline bool isFloatScalar() const;
341 inline floatScalar floatScalarToken() const;
343 inline bool isDoubleScalar() const;
344 inline doubleScalar doubleScalarToken() const;
346 inline bool isScalar() const;
347 inline scalar scalarToken() const;
349 inline bool isNumber() const;
350 inline scalar number() const;
352 inline bool isCompound() const;
353 inline const compound& compoundToken() const;
354 compound& transferCompoundToken();
356 inline label lineNumber() const;
357 inline label& lineNumber();
363 inline void setBad();
368 //- Return info proxy.
369 // Used to print token information to a stream
370 InfoProxy<token> info() const
380 inline void operator=(const token&);
382 inline void operator=(const punctuationToken);
384 inline void operator=(word*);
385 inline void operator=(const word&);
387 inline void operator=(string*);
388 inline void operator=(const string&);
390 inline void operator=(const label);
391 inline void operator=(const floatScalar);
392 inline void operator=(const doubleScalar);
394 inline void operator=(compound*);
399 inline bool operator==(const token&) const;
400 inline bool operator==(const punctuationToken) const;
401 inline bool operator==(const word&) const;
402 inline bool operator==(const string&) const;
403 inline bool operator==(const label) const;
404 inline bool operator==(const floatScalar) const;
405 inline bool operator==(const doubleScalar) const;
410 inline bool operator!=(const token&) const;
411 inline bool operator!=(const punctuationToken) const;
412 inline bool operator!=(const word&) const;
413 inline bool operator!=(const string&) const;
414 inline bool operator!=(const label) const;
415 inline bool operator!=(const floatScalar) const;
416 inline bool operator!=(const doubleScalar) const;
419 // IOstream operators
421 friend Istream& operator>>(Istream&, token&);
422 friend Ostream& operator<<(Ostream&, const token&);
424 friend Ostream& operator<<(Ostream&, const punctuationToken&);
425 friend ostream& operator<<(ostream&, const punctuationToken&);
427 friend ostream& operator<<(ostream&, const InfoProxy<token>&);
431 Ostream& operator<<(Ostream&, const token::punctuationToken&);
432 ostream& operator<<(ostream&, const token::punctuationToken&);
433 ostream& operator<<(ostream&, const InfoProxy<token>&);
434 Ostream& operator<<(Ostream&, const token::compound&);
437 #define defineCompoundTypeName(Type, Name) \
438 defineTemplateTypeNameAndDebugWithName(token::Compound<Type>, #Type, 0);
440 #define addCompoundToRunTimeSelectionTable(Type, Name) \
441 token::compound::addIstreamConstructorToTable<token::Compound<Type> > \
442 add##Name##IstreamConstructorToTable_;
445 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
447 } // End namespace Foam
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
454 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
458 // ************************************************************************* //