1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 // Clear any allocated storage (word or string)
36 inline void token::clear()
42 else if (type_ == STRING)
44 delete stringTokenPtr_;
46 else if (type_ == COMPOUND)
48 if (compoundTokenPtr_->okToDelete())
50 delete compoundTokenPtr_;
54 compoundTokenPtr_->refCount::operator--();
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 inline token::token(const token& t)
75 lineNumber_(t.lineNumber_)
79 case token::UNDEFINED:
83 punctuationToken_ = t.punctuationToken_;
87 wordTokenPtr_ = new word(*t.wordTokenPtr_);
91 stringTokenPtr_ = new string(*t.stringTokenPtr_);
95 labelToken_ = t.labelToken_;
99 floatScalarToken_ = t.floatScalarToken_;
103 doubleScalarToken_ = t.doubleScalarToken_;
106 case LONG_DOUBLE_SCALAR:
107 longDoubleScalarToken_ = t.longDoubleScalarToken_;
111 compoundTokenPtr_ = t.compoundTokenPtr_;
112 compoundTokenPtr_->refCount::operator++();
115 case token::FATALERROR:
120 // Construct punctuation character token
121 inline token::token(punctuationToken p, label lineNumber)
124 punctuationToken_(p),
125 lineNumber_(lineNumber)
128 // Construct word token
129 inline token::token(const word& w, label lineNumber)
132 wordTokenPtr_(new word(w)),
133 lineNumber_(lineNumber)
136 // Construct string token
137 inline token::token(const string& s, label lineNumber)
140 stringTokenPtr_(new string(s)),
141 lineNumber_(lineNumber)
144 // Construct label token
145 inline token::token(const label l, label lineNumber)
149 lineNumber_(lineNumber)
152 // Construct floatScalar token
153 inline token::token(const floatScalar s, label lineNumber)
156 floatScalarToken_(s),
157 lineNumber_(lineNumber)
160 // Construct doubleScalar token
161 inline token::token(const doubleScalar s, label lineNumber)
163 type_(DOUBLE_SCALAR),
164 doubleScalarToken_(s),
165 lineNumber_(lineNumber)
169 // Construct longDoubleScalar token
170 inline token::token(const longDoubleScalar s, label lineNumber)
172 type_(LONG_DOUBLE_SCALAR),
173 longDoubleScalarToken_(s),
174 lineNumber_(lineNumber)
178 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
180 // Delete token clearing the storage used by word or string
181 inline token::~token()
187 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
189 inline token::tokenType token::type() const
194 inline bool token::good() const
196 return (type_ != FATALERROR && type_ != UNDEFINED);
199 inline bool token::undefined() const
201 return (type_ == UNDEFINED);
204 inline bool token::error() const
206 return (type_ == FATALERROR);
209 inline bool token::isPunctuation() const
211 return (type_ == PUNCTUATION);
214 inline token::punctuationToken token::pToken() const
216 if (type_ == PUNCTUATION)
218 return punctuationToken_;
222 parseError("punctuation character");
227 inline bool token::isWord() const
229 return (type_ == WORD);
232 inline const word& token::wordToken() const
236 return *wordTokenPtr_;
245 inline bool token::isString() const
247 return (type_ == STRING);
250 inline const string& token::stringToken() const
254 return *stringTokenPtr_;
258 parseError("string");
263 inline bool token::isLabel() const
265 return (type_ == LABEL);
268 inline label token::labelToken() const
281 inline bool token::isFloatScalar() const
283 return (type_ == FLOAT_SCALAR);
286 inline floatScalar token::floatScalarToken() const
288 if (type_ == FLOAT_SCALAR)
290 return floatScalarToken_;
294 parseError("floatScalar");
300 inline bool token::isDoubleScalar() const
302 return (type_ == DOUBLE_SCALAR);
306 inline doubleScalar token::doubleScalarToken() const
308 if (type_ == DOUBLE_SCALAR)
310 return doubleScalarToken_;
314 parseError("doubleScalar");
320 inline bool token::isLongDoubleScalar() const
322 return (type_ == LONG_DOUBLE_SCALAR);
326 inline longDoubleScalar token::longDoubleScalarToken() const
328 if (type_ == LONG_DOUBLE_SCALAR)
330 return longDoubleScalarToken_;
334 parseError("longDoubleScalar");
340 inline bool token::isScalar() const
344 type_ == FLOAT_SCALAR
345 || type_ == DOUBLE_SCALAR
346 || type_ == LONG_DOUBLE_SCALAR
350 inline scalar token::scalarToken() const
352 if (type_ == FLOAT_SCALAR)
354 return floatScalarToken_;
356 else if (type_ == DOUBLE_SCALAR)
358 return doubleScalarToken_;
360 else if (type_ == LONG_DOUBLE_SCALAR)
362 return longDoubleScalarToken_;
366 parseError("scalar");
371 inline bool token::isNumber() const
373 return (type_ == LABEL || isScalar());
376 inline scalar token::number() const
384 return scalarToken();
388 parseError("number (label or scalar)");
393 inline bool token::isCompound() const
395 return (type_ == COMPOUND);
398 inline const token::compound& token::compoundToken() const
400 if (type_ == COMPOUND)
402 return *compoundTokenPtr_;
406 parseError("compound");
407 return *compoundTokenPtr_;
412 inline label token::lineNumber() const
417 inline label& token::lineNumber()
423 inline void token::setBad()
430 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
432 inline void token::operator=(const token& t)
439 case token::UNDEFINED:
443 punctuationToken_ = t.punctuationToken_;
447 wordTokenPtr_ = new word(*t.wordTokenPtr_);
451 stringTokenPtr_ = new string(*t.stringTokenPtr_);
455 labelToken_ = t.labelToken_;
459 floatScalarToken_ = t.floatScalarToken_;
463 doubleScalarToken_ = t.doubleScalarToken_;
466 case LONG_DOUBLE_SCALAR:
467 longDoubleScalarToken_ = t.longDoubleScalarToken_;
471 compoundTokenPtr_ = t.compoundTokenPtr_;
472 compoundTokenPtr_->refCount::operator++();
475 case token::FATALERROR:
479 lineNumber_ = t.lineNumber_;
483 inline void token::operator=(const punctuationToken p)
487 punctuationToken_ = p;
490 inline void token::operator=(word* wPtr)
494 wordTokenPtr_ = wPtr;
497 inline void token::operator=(const word& w)
499 operator=(new word(w));
502 inline void token::operator=(string* sPtr)
506 stringTokenPtr_ = sPtr;
509 inline void token::operator=(const string& s)
511 operator=(new string(s));
514 inline void token::operator=(const label l)
521 inline void token::operator=(const floatScalar s)
524 type_ = FLOAT_SCALAR;
525 floatScalarToken_ = s;
528 inline void token::operator=(const doubleScalar s)
531 type_ = DOUBLE_SCALAR;
532 doubleScalarToken_ = s;
535 inline void token::operator=(const longDoubleScalar s)
538 type_ = LONG_DOUBLE_SCALAR;
539 longDoubleScalarToken_ = s;
542 inline void token::operator=(token::compound* cPtr)
546 compoundTokenPtr_ = cPtr;
550 inline bool token::operator==(const token& t) const
552 if (type_ != t.type_)
559 case token::UNDEFINED:
563 return punctuationToken_ == t.punctuationToken_;
566 return *wordTokenPtr_ == *t.wordTokenPtr_;
569 return *stringTokenPtr_ == *t.stringTokenPtr_;
572 return labelToken_ == t.labelToken_;
575 return equal(floatScalarToken_, t.floatScalarToken_);
578 return equal(doubleScalarToken_, t.doubleScalarToken_);
580 case LONG_DOUBLE_SCALAR:
581 return equal(longDoubleScalarToken_, t.longDoubleScalarToken_);
584 return compoundTokenPtr_ == t.compoundTokenPtr_;
586 case token::FATALERROR:
593 inline bool token::operator==(const punctuationToken p) const
595 return (type_ == PUNCTUATION && punctuationToken_ == p);
598 inline bool token::operator==(const word& w) const
600 return (type_ == WORD && wordToken() == w);
603 inline bool token::operator==(const string& s) const
605 return (type_ == STRING && stringToken() == s);
608 inline bool token::operator==(const label l) const
610 return (type_ == LABEL && labelToken_ == l);
613 inline bool token::operator==(const floatScalar s) const
615 return (type_ == FLOAT_SCALAR && equal(floatScalarToken_, s));
618 inline bool token::operator==(const doubleScalar s) const
620 return (type_ == DOUBLE_SCALAR && equal(doubleScalarToken_, s));
623 inline bool token::operator==(const longDoubleScalar s) const
625 return (type_ == LONG_DOUBLE_SCALAR && equal(longDoubleScalarToken_, s));
628 inline bool token::operator!=(const token& t) const
630 return !operator==(t);
633 inline bool token::operator!=(const punctuationToken p) const
635 return !operator==(p);
638 inline bool token::operator!=(const word& w) const
640 return !operator==(w);
643 inline bool token::operator!=(const string& s) const
645 return !operator==(s);
648 inline bool token::operator!=(const floatScalar s) const
650 return !operator==(s);
653 inline bool token::operator!=(const doubleScalar s) const
655 return !operator==(s);
658 inline bool token::operator!=(const longDoubleScalar s) const
660 return !operator==(s);
663 inline bool token::operator!=(const label l) const
665 return !operator==(l);
669 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
671 } // End namespace Foam
673 // ************************************************************************* //