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