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