00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef token_H
00038 #define token_H
00039
00040 #include <OpenFOAM/label.H>
00041 #include <OpenFOAM/uLabel.H>
00042 #include <OpenFOAM/scalar.H>
00043 #include <OpenFOAM/word.H>
00044 #include <OpenFOAM/InfoProxy.H>
00045 #include <OpenFOAM/refCount.H>
00046 #include <OpenFOAM/typeInfo.H>
00047
00048 #define NoHashTableC
00049 #include <OpenFOAM/runTimeSelectionTables.H>
00050
00051 #include <iostream>
00052
00053
00054
00055 namespace Foam
00056 {
00057
00058
00059
00060 class token;
00061 Istream& operator>>(Istream&, token&);
00062 Ostream& operator<<(Ostream&, const token&);
00063
00064
00065
00066
00067
00068 class token
00069 {
00070
00071 public:
00072
00073
00074 enum tokenType
00075 {
00076 UNDEFINED,
00077
00078 PUNCTUATION,
00079 WORD,
00080 STRING,
00081 LABEL,
00082 FLOAT_SCALAR,
00083 DOUBLE_SCALAR,
00084 COMPOUND,
00085
00086 ERROR
00087 };
00088
00089
00090
00091 enum punctuationToken
00092 {
00093 NULL_TOKEN = '\0',
00094 SPACE = ' ',
00095 TAB = '\t',
00096 NL = '\n',
00097
00098 END_STATEMENT = ';',
00099 BEGIN_LIST = '(',
00100 END_LIST = ')',
00101 BEGIN_SQR = '[',
00102 END_SQR = ']',
00103 BEGIN_BLOCK = '{',
00104 END_BLOCK = '}',
00105 COLON = ':',
00106 COMMA = ',',
00107
00108 BEGIN_STRING = '"',
00109 END_STRING = BEGIN_STRING,
00110
00111 ASSIGN = '=',
00112 ADD = '+',
00113 SUBTRACT = '-',
00114 MULTIPLY = '*',
00115 DIVIDE = '/'
00116 };
00117
00118
00119
00120 class compound
00121 :
00122 public refCount
00123 {
00124
00125
00126 bool empty_;
00127
00128
00129
00130
00131
00132 compound(const compound&);
00133
00134
00135 void operator=(const compound&);
00136
00137
00138 public:
00139
00140
00141 TypeName("compound");
00142
00143
00144
00145 declareRunTimeSelectionTable
00146 (
00147 autoPtr,
00148 compound,
00149 Istream,
00150 (Istream& is),
00151 (is)
00152 );
00153
00154
00155
00156
00157
00158 compound()
00159 :
00160 empty_(false)
00161 {}
00162
00163
00164
00165
00166
00167 static autoPtr<compound> New(const word& type, Istream&);
00168
00169
00170
00171
00172 virtual ~compound();
00173
00174
00175
00176
00177
00178
00179
00180 static bool isCompound(const word& name);
00181
00182 bool empty() const
00183 {
00184 return empty_;
00185 }
00186
00187 bool& empty()
00188 {
00189 return empty_;
00190 }
00191
00192 virtual label size() const = 0;
00193
00194
00195
00196
00197
00198
00199
00200
00201 virtual void write(Ostream&) const = 0;
00202
00203
00204
00205
00206 friend Ostream& operator<<(Ostream&, const compound&);
00207 };
00208
00209
00210
00211 template<class T>
00212 class Compound
00213 :
00214 public token::compound,
00215 public T
00216 {
00217 public:
00218
00219
00220 TypeName("Compound<T>");
00221
00222 Compound(Istream& is)
00223 :
00224 T(is)
00225 {}
00226
00227 label size() const
00228 {
00229 return T::size();
00230 }
00231
00232 void write(Ostream& os) const
00233 {
00234 operator<<(os, static_cast<const T&>(*this));
00235 }
00236 };
00237
00238
00239
00240 static token undefinedToken;
00241
00242
00243 private:
00244
00245
00246
00247
00248 tokenType type_;
00249
00250
00251 union
00252 {
00253 punctuationToken punctuationToken_;
00254 word* wordTokenPtr_;
00255 string* stringTokenPtr_;
00256 label labelToken_;
00257 floatScalar floatScalarToken_;
00258 doubleScalar doubleScalarToken_;
00259 mutable compound* compoundTokenPtr_;
00260 };
00261
00262
00263 label lineNumber_;
00264
00265
00266
00267
00268
00269 inline void clear();
00270
00271
00272 void parseError(const char* expected) const;
00273
00274
00275 public:
00276
00277
00278
00279 static const char* const typeName;
00280
00281
00282
00283
00284
00285 inline token();
00286
00287
00288 inline token(const token&);
00289
00290
00291 inline token(punctuationToken, label lineNumber=0);
00292
00293
00294 inline token(const word&, label lineNumber=0);
00295
00296
00297 inline token(const string&, label lineNumber=0);
00298
00299
00300 inline token(const label, label lineNumber=0);
00301
00302
00303 inline token(const floatScalar, label lineNumber=0);
00304
00305
00306 inline token(const doubleScalar, label lineNumber=0);
00307
00308
00309 token(Istream&);
00310
00311
00312
00313
00314 inline ~token();
00315
00316
00317
00318
00319
00320
00321 inline tokenType type() const;
00322
00323 inline bool good() const;
00324 inline bool undefined() const;
00325 inline bool error() const;
00326
00327 inline bool isPunctuation() const;
00328 inline punctuationToken pToken() const;
00329
00330 inline bool isWord() const;
00331 inline const word& wordToken() const;
00332
00333 inline bool isString() const;
00334 inline const string& stringToken() const;
00335
00336 inline bool isLabel() const;
00337 inline label labelToken() const;
00338
00339 inline bool isFloatScalar() const;
00340 inline floatScalar floatScalarToken() const;
00341
00342 inline bool isDoubleScalar() const;
00343 inline doubleScalar doubleScalarToken() const;
00344
00345 inline bool isScalar() const;
00346 inline scalar scalarToken() const;
00347
00348 inline bool isNumber() const;
00349 inline scalar number() const;
00350
00351 inline bool isCompound() const;
00352 inline const compound& compoundToken() const;
00353 compound& transferCompoundToken();
00354
00355 inline label lineNumber() const;
00356 inline label& lineNumber();
00357
00358
00359
00360
00361
00362 inline void setBad();
00363
00364
00365
00366
00367
00368
00369 InfoProxy<token> info() const
00370 {
00371 return *this;
00372 }
00373
00374
00375
00376
00377
00378
00379 inline void operator=(const token&);
00380
00381 inline void operator=(const punctuationToken);
00382
00383 inline void operator=(word*);
00384 inline void operator=(const word&);
00385
00386 inline void operator=(string*);
00387 inline void operator=(const string&);
00388
00389 inline void operator=(const label);
00390 inline void operator=(const floatScalar);
00391 inline void operator=(const doubleScalar);
00392
00393 inline void operator=(compound*);
00394
00395
00396
00397
00398 inline bool operator==(const token&) const;
00399 inline bool operator==(const punctuationToken) const;
00400 inline bool operator==(const word&) const;
00401 inline bool operator==(const string&) const;
00402 inline bool operator==(const label) const;
00403 inline bool operator==(const floatScalar) const;
00404 inline bool operator==(const doubleScalar) const;
00405
00406
00407
00408
00409 inline bool operator!=(const token&) const;
00410 inline bool operator!=(const punctuationToken) const;
00411 inline bool operator!=(const word&) const;
00412 inline bool operator!=(const string&) const;
00413 inline bool operator!=(const label) const;
00414 inline bool operator!=(const floatScalar) const;
00415 inline bool operator!=(const doubleScalar) const;
00416
00417
00418
00419
00420 friend Istream& operator>>(Istream&, token&);
00421 friend Ostream& operator<<(Ostream&, const token&);
00422
00423 friend Ostream& operator<<(Ostream&, const punctuationToken&);
00424 friend ostream& operator<<(ostream&, const punctuationToken&);
00425
00426 friend ostream& operator<<(ostream&, const InfoProxy<token>&);
00427 };
00428
00429
00430 Ostream& operator<<(Ostream&, const token::punctuationToken&);
00431 ostream& operator<<(ostream&, const token::punctuationToken&);
00432 ostream& operator<<(ostream&, const InfoProxy<token>&);
00433 Ostream& operator<<(Ostream&, const token::compound&);
00434
00435
00436 #define defineCompoundTypeName(Type, Name) \
00437 typedef token::Compound<Type > tokenCompound##Name##_; \
00438 defineTemplateTypeNameAndDebugWithName(tokenCompound##Name##_, #Type, 0);
00439
00440 #define addCompoundToRunTimeSelectionTable(Type, Name) \
00441 token::compound::addIstreamConstructorToTable<token::Compound<Type > > \
00442 add##Name##IstreamConstructorToTable_;
00443
00444
00445
00446
00447 }
00448
00449
00450
00451 #include "tokenI.H"
00452 #include <OpenFOAM/Istream.H>
00453
00454
00455
00456 #endif
00457
00458