1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 \*---------------------------------------------------------------------------*/
41 #include <OpenFOAM/label.H>
42 #include <OpenFOAM/uLabel.H>
43 #include <OpenFOAM/scalar.H>
44 #include <OpenFOAM/word.H>
45 #include <OpenFOAM/InfoProxy.H>
46 #include <OpenFOAM/refCount.H>
47 #include <OpenFOAM/typeInfo.H>
50 #include <OpenFOAM/runTimeSelectionTables.H>
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 // Forward declaration of friend functions and operators
62 Istream& operator>>(Istream&, token&);
63 Ostream& operator<<(Ostream&, const token&);
65 /*---------------------------------------------------------------------------*\
66 Class token Declaration
67 \*---------------------------------------------------------------------------*/
74 //- Enumeration defining the types of token
91 //- Standard punctuation tokens
110 END_STRING = BEGIN_STRING,
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&);
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
322 inline tokenType type() const;
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 typedef token::Compound<Type > tokenCompound##Name##_; \
439 defineTemplateTypeNameAndDebugWithName(tokenCompound##Name##_, #Type, 0);
441 #define addCompoundToRunTimeSelectionTable(Type, Name) \
442 token::compound::addIstreamConstructorToTable<token::Compound<Type > > \
443 add##Name##IstreamConstructorToTable_;
446 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
448 } // End namespace Foam
450 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
453 #include <OpenFOAM/Istream.H>
455 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
459 // ************************ vim: set sw=4 sts=4 et: ************************ //