1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A token holds items read from Istream.
36 \*---------------------------------------------------------------------------*/
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 \*---------------------------------------------------------------------------*/
75 //- Enumeration defining the types of token
92 //- Standard punctuation tokens
120 //- Abstract base class for complex tokens
130 // Private Member Functions
132 //- Disallow default bitwise copy construct
133 compound(const compound&);
135 //- Disallow default bitwise assignment
136 void operator=(const compound&);
141 //- Runtime type information
142 TypeName("compound");
145 //- Declare run-time constructor selection table
146 declareRunTimeSelectionTable
167 //- Select null constructed
168 static autoPtr<compound> New(const word& type, Istream& is);
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
208 friend Ostream& operator<<(Ostream&, const compound&);
213 //- A templated class for holding compound tokens
217 public token::compound,
222 //- Runtime type information
223 TypeName("Compound<T>");
225 Compound(Istream& is)
235 void write(Ostream& os) const
237 operator<<(os, static_cast<const T&>(*this));
242 //- Static undefined token
243 static token undefinedToken;
253 //- Anonymous Union of token types
256 punctuationToken punctuationToken_;
258 string* stringTokenPtr_;
260 floatScalar floatScalarToken_;
261 doubleScalar doubleScalarToken_;
262 mutable compound* compoundTokenPtr_;
265 //- Line number in the file this token was read from
269 // Private member functions
271 //- Clear any allocated storage (word or string)
274 // Parse error, expected 'expected', found ...
275 void parseError(const char* expected) const;
280 // Static data members
282 static const char* const typeName;
290 //- Construct as copy
291 inline token(const token&);
293 //- Construct punctuation character token
294 inline token(punctuationToken p, label lineNumber=0);
296 //- Construct word token
297 inline token(const word& w, label lineNumber=0);
299 //- Construct string token
300 inline token(const string& s, label lineNumber=0);
302 //- Construct label token
303 inline token(const label, label lineNumber=0);
305 //- Construct floatScalar token
306 inline token(const floatScalar s, label lineNumber=0);
308 //- Construct doubleScalar token
309 inline token(const doubleScalar s, label lineNumber=0);
311 //- Construct from Istream
324 inline tokenType type() const;
326 inline bool good() const;
327 inline bool undefined() const;
328 inline bool error() const;
330 inline bool isPunctuation() const;
331 inline punctuationToken pToken() const;
333 inline bool isWord() const;
334 inline const word& wordToken() const;
336 inline bool isString() const;
337 inline const string& stringToken() const;
339 inline bool isLabel() const;
340 inline label labelToken() const;
342 inline bool isFloatScalar() const;
343 inline floatScalar floatScalarToken() const;
345 inline bool isDoubleScalar() const;
346 inline doubleScalar doubleScalarToken() const;
348 inline bool isScalar() const;
349 inline scalar scalarToken() const;
351 inline bool isNumber() const;
352 inline scalar number() const;
354 inline bool isCompound() const;
355 inline const compound& compoundToken() const;
356 compound& transferCompoundToken();
358 inline label lineNumber() const;
359 inline label& lineNumber();
365 inline void setBad();
370 //- Return info proxy.
371 // Used to print token information to a stream
372 InfoProxy<token> info() const
382 inline void operator=(const token&);
384 inline void operator=(const punctuationToken);
386 inline void operator=(word*);
387 inline void operator=(const word&);
389 inline void operator=(string*);
390 inline void operator=(const string&);
392 inline void operator=(const label);
393 inline void operator=(const floatScalar);
394 inline void operator=(const doubleScalar);
396 inline void operator=(compound*);
401 inline bool operator==(const token&) const;
402 inline bool operator==(const punctuationToken) const;
403 inline bool operator==(const word&) const;
404 inline bool operator==(const string&) const;
405 inline bool operator==(const label) const;
406 inline bool operator==(const floatScalar) const;
407 inline bool operator==(const doubleScalar) const;
412 inline bool operator!=(const token&) const;
413 inline bool operator!=(const punctuationToken) const;
414 inline bool operator!=(const word&) const;
415 inline bool operator!=(const string&) const;
416 inline bool operator!=(const label) const;
417 inline bool operator!=(const floatScalar) const;
418 inline bool operator!=(const doubleScalar) const;
421 // IOstream operators
423 friend Istream& operator>>(Istream&, token&);
424 friend Ostream& operator<<(Ostream&, const token&);
426 friend Ostream& operator<<(Ostream&, const punctuationToken&);
427 friend ostream& operator<<(ostream&, const punctuationToken&);
429 friend ostream& operator<<(ostream&, const InfoProxy<token>&);
432 #include "CintUndefs.H"
434 Ostream& operator<<(Ostream&, const token::punctuationToken&);
435 ostream& operator<<(ostream&, const token::punctuationToken&);
436 ostream& operator<<(ostream&, const InfoProxy<token>&);
437 Ostream& operator<<(Ostream&, const token::compound&);
440 #define defineCompoundTypeName(Type, Name) \
441 typedef token::Compound<Type > tokenCompound##Name##_; \
442 defineTemplateTypeNameAndDebugWithName(tokenCompound##Name##_, #Type, 0);
444 #define addCompoundToRunTimeSelectionTable(Type, Name) \
445 token::compound::addIstreamConstructorToTable<token::Compound<Type > > \
446 add##Name##IstreamConstructorToTable_;
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
451 } // End namespace Foam
453 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
458 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
462 // ************************************************************************* //