token.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::token
29 
30 Description
31  A token holds an item read from Istream.
32 
33 SourceFiles
34  tokenI.H
35  token.C
36  tokenIO.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Foam_token_H
41 #define Foam_token_H
42 
43 #include "label.H"
44 #include "uLabel.H"
45 #include "scalar.H"
46 #include "word.H"
47 #include "contiguous.H"
48 #include "refCount.H"
49 #include "InfoProxy.H"
50 #include "typeInfo.H"
51 
52 #define NoHashTableC
53 #include "runTimeSelectionTables.H"
54 
55 #include <iostream>
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward Declarations
63 class token;
64 Ostream& operator<<(Ostream& os, const token& tok);
65 
66 /*---------------------------------------------------------------------------*\
67  Class token Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class token
71 {
72 public:
73 
74  //- Enumeration defining the types of token.
75  // Since the enumeration is used to tag content in Pstream, it is of
76  // type \c char and shall have values that do not overlap with regular
77  // punctuation characters.
78  enum tokenType : char
79  {
80  UNDEFINED = '\0',
81  ERROR = '\x80',
82 
83  // Fundamental types
84  FLAG,
86  BOOL,
88  FLOAT,
89  DOUBLE,
90 
91  // Pointer types
92  WORD,
93  STRING,
95 
96  DIRECTIVE,
97 
100  VARIABLE,
102  VERBATIM,
104  CHAR_DATA,
107  // Aliases
111  };
112 
113 
114  //- Stream or output control flags (1-byte width)
115  enum flagType
116  {
117  NO_FLAG = 0,
118  ASCII = 1,
119  BINARY = 2
120  };
121 
122 
123  //- Standard punctuation tokens (a character)
124  enum punctuationToken : char
125  {
126  NULL_TOKEN = '\0',
127  TAB = '\t',
128  NL = '\n',
129  SPACE = ' ',
131  COLON = ':',
132  SEMICOLON = ';',
133  COMMA = ',',
134  HASH = '#',
135  DOLLAR = '$',
136  QUESTION = '?',
137  ATSYM = '@',
138  SQUOTE = '\'',
139  DQUOTE = '"',
141  ASSIGN = '=',
142  PLUS = '+',
143  MINUS = '-',
144  MULTIPLY = '*',
145  DIVIDE = '/',
147  LPAREN = '(',
148  RPAREN = ')',
149  LSQUARE = '[',
150  RSQUARE = ']',
151  LBRACE = '{',
152  RBRACE = '}',
154  // With semantically meaning
155 
156  ADD = PLUS,
157  SUBTRACT = MINUS,
167  END_STRING = DQUOTE
168  };
170 
171  //- Abstract base class for complex tokens
172  class compound
173  :
174  public refCount
175  {
176  protected:
177 
178  //- The compound token state, internally used values only
179  // (0: initial, 1: moved, 2: pending read...)
180  unsigned char state_;
181 
182  public:
183 
184  //- Declare type-name, virtual type (without debug switch)
185  TypeNameNoDebug("compound");
186 
187  //- Declare run-time constructor selection table
189  (
190  autoPtr,
191  compound,
192  empty,
193  (),
194  ()
195  );
196 
197 
198  // Constructors
199 
200  //- Default construct
201  constexpr compound() noexcept
202  :
203  state_(0)
204  {}
205 
206 
207  //- Destructor
208  virtual ~compound() noexcept = default;
209 
210 
211  // Selectors
212 
213  //- Default construct specified compound type
214  static autoPtr<compound> New(const word& compoundType);
215 
216  //- Default construct specified compound type
217  //- and read from stream
218  static autoPtr<compound> New
219  (
220  const word& compoundType,
221  Istream& is,
222  const bool readContent = true
223  );
224 
225  //- Attempt dynamic_cast to \c Type
226  //- returns nullptr if cast is not possible
227  template<class Type>
228  const Type* isA() const
229  {
230  return dynamic_cast<const Type*>(this);
231  }
232 
233 
234  // Member Functions
235 
236  //- True if a known (registered) compound type
237  static bool isCompound(const word& compoundType);
238 
239  //- Get compound transferred status
240  bool moved() const noexcept { return (state_ & 1); }
241 
242  //- Set compound transferred status
243  void moved(bool b) noexcept
244  {
245  if (b) { state_ |= 1; } else { state_ &= ~1; }
246  }
247 
248  //- Get compound pending-read status
249  bool pending() const noexcept { return (state_ & 2); }
250 
251  //- Set compound pending-read status
252  void pending(bool b) noexcept
253  {
254  if (b) { state_ |= 2; } else { state_ &= ~2; }
255  }
256 
257  //- The size of the underlying content
258  virtual label size() const = 0;
259 
260  //- Change the size of the underlying container content
261  virtual void resize(const label n) = 0;
262 
263  //- Fill with zero values, or with default constructed
264  virtual void fill_zero() = 0;
266  //- Read from stream into the underlying content
267  virtual void read(Istream& is) = 0;
268 
269  //- Write the underlying content
270  virtual void write(Ostream& os) const = 0;
271 
272 
273  // Attributes and access methods
274 
275  //- The token type (if any) corresponding to the contained
276  //- component type (LABEL, FLOAT, DOUBLE, etc).
277  virtual tokenType typeCode() const = 0;
279  //- The number of vector-space or other components
280  //- of the underlying data content
281  virtual direction nComponents() const = 0;
282 
283  //- The vector-space rank associated with the data content
284  virtual direction rank() const = 0;
285 
286  //- Pointer to the underlying data as byte data
287  virtual const char* cdata_bytes() const = 0;
288 
289  //- Pointer to the underlying data as byte data
290  virtual char* data_bytes() = 0;
291 
292  //- Size of the (contiguous) byte data
293  virtual std::streamsize size_bytes() const = 0;
294 
295 
296  // Operators
297 
298  //- Output operator
299  friend Ostream& operator<<(Ostream& os, const compound& ct);
300  };
301 
302 
303  //- A templated class for holding compound tokens.
304  //- The underlying container is normally a List of values,
305  //- it must have a \c value_type typedef as well as
306  //- size(), resize(), cdata_bytes(), data_bytes(), size_bytes() methods
307  template<class T>
308  class Compound
309  :
310  public token::compound,
311  public T
312  {
313  // Private Member Functions
314 
315  //- Fill with zero (contiguous types)
316  template<class ValT = typename T::value_type>
317  typename std::enable_if<pTraits_has_zero<ValT>::value, void>::type
318  _m_fill_zero()
319  {
320  T::operator=(pTraits<ValT>::zero);
321  }
322 
323  //- Fill with default value initialized (non-contiguous types)
324  template<class ValT = typename T::value_type>
325  typename std::enable_if<!pTraits_has_zero<ValT>::value, void>::type
326  _m_fill_zero()
327  {
328  T::operator=(ValT());
329  }
330 
331  public:
332 
333  //- The type of values held by the compound
334  typedef typename T::value_type value_type;
335 
336  //- Declare type-name, virtual type (without debug switch)
337  TypeNameNoDebug("Compound<T>");
338 
339  //- No copy construct
340  Compound(const Compound<T>&) = delete;
341 
342  //- No copy assignment
343  void operator=(const Compound<T>&) = delete;
344 
345  // Constructors
346 
347  //- Default construct
348  Compound() = default;
349 
350  //- Copy construct from base content
351  explicit Compound(const T& content)
352  :
353  T(content)
354  {}
355 
356  //- Move construct from base content
357  explicit Compound(T&& content)
358  :
359  T(std::move(content))
360  {}
361 
362  //- Read construct from Istream
363  explicit Compound(Istream& is)
364  :
365  T(is)
366  {}
367 
368 
369  // Selectors
370 
371  //- Construct autoPtr compound with forwarding arguments.
372  // The return type is compound, not Compound since that
373  // is what the token interface requires.
374  template<class... Args>
375  static autoPtr<compound> New(Args&&... args)
376  {
377  return autoPtr<compound>
378  (
379  new Compound<T>(T(std::forward<Args>(args)...))
380  );
381  }
382 
383 
384  // Member Functions
385 
386  //- The size of the underlying content
387  virtual label size() const
388  {
389  return T::size();
390  }
391 
392  //- Change the size of the underlying content
393  virtual void resize(const label n)
394  {
395  T::resize(n);
396  }
398  //- Fill with zero value or with default value initialized
399  virtual void fill_zero() { _m_fill_zero(); }
400 
401  //- Redirect read to underlying content
402  virtual void read(Istream& is)
403  {
404  token::compound::state_ = 0; // Clean state
405  operator>>(is, static_cast<T&>(*this));
406  }
407 
408  //- Redirect write to underlying content
409  virtual void write(Ostream& os) const
410  {
411  operator<<(os, static_cast<const T&>(*this));
412  }
413 
414 
415  // Attributes and access methods
416 
417  //- The token type (if any) corresponding to the contained
418  //- component type (LABEL, FLOAT, DOUBLE, etc).
419  virtual tokenType typeCode() const;
420 
421  //- The number of vector-space or other components
422  //- of the underlying data content
423  virtual direction nComponents() const
424  {
426  }
427 
428  //- The vector-space rank associated with the data content
429  virtual direction rank() const
430  {
431  return pTraits_rank<value_type>();
432  }
433 
434  //- Pointer to the underlying data as byte data
435  virtual const char* cdata_bytes() const
436  {
437  return T::cdata_bytes();
438  }
439 
440  //- Pointer to the underlying data as byte data
441  virtual char* data_bytes()
442  {
443  return T::data_bytes();
444  }
445 
446  //- Size of the (contiguous) byte data
447  virtual std::streamsize size_bytes() const
448  {
449  return T::size_bytes();
450  }
451  };
452 
453 
454  //- An undefined token
455  static const token undefinedToken;
456 
457 
458 private:
459 
460  //- A %union of token types
461  union content
462  {
463  // Fundamental values. Largest first for any {} initialization.
464  int64_t int64Val;
465  int32_t int32Val;
466 
467  int flagVal; // bitmask - stored as int, not enum
468  punctuationToken punctuationVal;
469  label labelVal;
470  float floatVal;
471  double doubleVal;
472 
473  // Pointers
474  word* wordPtr;
475  string* stringPtr;
476  mutable compound* compoundPtr;
477  };
478 
479 
480  // Private Data
481 
482  //- The data content (as a union).
483  // For memory alignment this should appear as the first member.
484  content data_;
486  //- The token type
487  tokenType type_;
488 
489  //- The file line number where the token was read from
490  label line_;
491 
492 
493  // Private Member Functions
494 
495  //- Set as UNDEFINED and zero the union content without any checking
496  inline void setUndefined() noexcept;
497 
498  //- True if token type corresponds to WORD or WORD-variant.
499  inline static bool is_wordToken(tokenType tokType) noexcept;
500 
501  //- True if token type corresponds to STRING or STRING-variant
502  inline static bool is_stringToken(tokenType tokType) noexcept;
503 
504  // Parse error, expected 'expected', found ...
505  void parseError(const char* expected) const;
506 
507 
508 public:
509 
510  // Static Data Members
511 
512  //- The type name is "token"
513  static constexpr const char* const typeName = "token";
514 
515 
516  // Constructors
518  //- Default construct, initialized to an UNDEFINED token.
519  inline constexpr token() noexcept;
520 
521  //- Copy construct
522  inline token(const token& t);
523 
524  //- Move construct. The original token is left as UNDEFINED.
525  inline token(token&& t) noexcept;
526 
527  //- Construct punctuation character token
528  inline explicit token(punctuationToken p, label lineNum=0) noexcept;
529 
530  //- Construct label token
531  //- \note Use boolean() static method for creating a \b bool token
532  //- since \c bool and \c int are otherwise indistinguishable
533  inline explicit token(const label val, label lineNum=0) noexcept;
534 
535  //- Construct float token
536  inline explicit token(const float val, label lineNum=0) noexcept;
537 
538  //- Construct double token
539  inline explicit token(const double val, label lineNum=0) noexcept;
540 
541  //- Copy construct word token
542  inline explicit token(const word& w, label lineNum=0);
543 
544  //- Copy construct string token
545  inline explicit token(const string& str, label lineNum=0);
546 
547  //- Move construct word token
548  inline explicit token(word&& w, label lineNum=0);
550  //- Move construct string token
551  inline explicit token(string&& str, label lineNum=0);
552 
553  //- Copy construct word/string token with the specified variant.
554  // A invalid word/string variant type is silently treated as STRING.
555  // No character stripping
556  inline explicit token(tokenType typ, const std::string&, label line=0);
557 
558  //- Move construct word/string token with the specified variant.
559  // A invalid word/string variant type is silently treated as STRING.
560  // No character stripping
561  inline explicit token(tokenType typ, std::string&&, label line=0);
562 
563  //- Construct from a compound pointer, taking ownership
564  inline explicit token(token::compound* ptr, label lineNum=0);
565 
566  //- Move construct from a compound pointer, taking ownership
567  inline explicit token(autoPtr<token::compound>&& ptr, label lineNum=0);
568 
569  //- Construct from Istream
570  explicit token(Istream& is);
571 
572 
573  //- Destructor
574  inline ~token();
575 
576 
577  // Static Functions
578 
579  //- Create a bool token.
580  inline static token boolean(bool on) noexcept;
581 
582  //- Create a token with stream flags, no sanity check
583  //
584  // \param bitmask the flags to set
585  inline static token flag(int bitmask) noexcept;
586 
587  //- True if the character is a punctuation separator (eg, in ISstream).
588  // Since it could also start a number, SUBTRACT is not included as
589  // a separator.
590  //
591  // \param c the character to test, passed as int for consistency with
592  // isdigit, isspace etc.
593  inline static bool isseparator(int c) noexcept;
594 
595 
596  // Member Functions
597 
598  // Status
599 
600  //- Return the name for the token type
601  static word name(const token::tokenType tokType);
602 
603  //- Return the name of the current token type
604  inline word name() const;
605 
606  //- Return the token type
607  inline tokenType type() const noexcept;
608 
609  //- Change the token type, for similar types.
610  // This can be used to change between string-like variants
611  // (eg, STRING, VARIABLE, etc)
612  // To change types entirely (eg, STRING to DOUBLE),
613  // use the corresponding assignment operator.
614  //
615  // \return true if the change was successful or no change was required
616  inline bool setType(const tokenType tokType) noexcept;
617 
618  //- The line number for the token
619  inline label lineNumber() const noexcept;
620 
621  //- Change token line number, return old value
622  inline label lineNumber(const label lineNum) noexcept;
623 
624  //- True if token is not UNDEFINED or ERROR
625  inline bool good() const noexcept;
626 
627  //- Token is UNDEFINED
628  inline bool undefined() const noexcept;
629 
630  //- Token is ERROR
631  inline bool error() const noexcept;
632 
633  //- Token is BOOL
634  inline bool isBool() const noexcept;
635 
636  //- Token is FLAG
637  inline bool isFlag() const noexcept;
638 
639  //- Token is PUNCTUATION
640  inline bool isPunctuation() const noexcept;
641 
642  //- True if token is PUNCTUATION and equal to parameter
643  inline bool isPunctuation(const punctuationToken p) const noexcept;
644 
645  //- Token is PUNCTUATION and isseparator
646  inline bool isSeparator() const noexcept;
647 
648  //- Token is LABEL
649  inline bool isLabel() const noexcept;
650 
651  //- True if token is LABEL and equal to parameter
652  inline bool isLabel(const label value) const noexcept;
653 
654  //- Token is FLOAT
655  inline bool isFloat() const noexcept;
656 
657  //- Token is DOUBLE
658  inline bool isDouble() const noexcept;
659 
660  //- Token is FLOAT or DOUBLE
661  inline bool isScalar() const noexcept;
662 
663  //- Token is LABEL, FLOAT or DOUBLE
664  inline bool isNumber() const noexcept;
665 
666  //- Token is word-variant (WORD, DIRECTIVE)
667  inline bool isWord() const noexcept;
668 
669  //- Token is word-variant and equal to parameter
670  inline bool isWord(const std::string& s) const;
671 
672  //- Token is DIRECTIVE (word variant)
673  inline bool isDirective() const noexcept;
674 
675  //- Token is (quoted) STRING (string variant)
676  inline bool isQuotedString() const noexcept;
677 
678  //- Token is string-variant
679  //- (STRING, EXPRESSION, VARIABLE, VERBATIM, CHAR_DATA)
680  inline bool isString() const noexcept;
681 
682  //- Token is EXPRESSION (string variant)
683  inline bool isExpression() const noexcept;
684 
685  //- Token is VARIABLE (string variant)
686  inline bool isVariable() const noexcept;
687 
688  //- Token is VERBATIM string (string variant)
689  inline bool isVerbatim() const noexcept;
690 
691  //- Token is CHAR_DATA (string variant)
692  inline bool isCharData() const noexcept;
693 
694  //- Token is word-variant or string-variant
695  //- (WORD, DIRECTIVE, STRING, EXPRESSION, VARIABLE, VERBATIM, CHAR_DATA)
696  inline bool isStringType() const noexcept;
697 
698  //- Token is COMPOUND
699  inline bool isCompound() const noexcept;
700 
701  //- True if token is COMPOUND and its type() is equal to parameter
702  inline bool isCompound(const word& compoundType) const;
703 
704  //- If token is COMPOUND and can be dynamic_cast to the \c Type
705  //- return a const pointer to the content.
706  // Return nullptr on any failure.
707  template<class Type>
708  inline const Type* isCompound() const;
709 
710  //- True if token is not UNDEFINED or ERROR. Same as good().
711  explicit operator bool() const noexcept { return good(); }
712 
713 
714  // Access
715 
716  //- Return boolean token value.
717  // Report FatalIOError and return false if token is not BOOL or LABEL
718  inline bool boolToken() const;
719 
720  //- Return flag bitmask value.
721  // Report FatalIOError and return NO_FLAG if token is not FLAG
722  inline int flagToken() const;
723 
724  //- Return punctuation character.
725  // Report FatalIOError and return \b \\0 if token is not PUNCTUATION
726  inline punctuationToken pToken() const;
727 
728  //- Return label value.
729  // Report FatalIOError and return \b 0 if token is not LABEL
730  inline label labelToken() const;
731 
732  //- Return float value.
733  // Report FatalIOError and return \b 0 if token is not FLOAT
734  inline float floatToken() const;
735 
736  //- Return double value.
737  // Report FatalIOError and return \b 0 if token is not DOUBLE
738  inline double doubleToken() const;
739 
740  //- Return float or double value.
741  // Report FatalIOError and return \b 0 if token is not a
742  // FLOAT or DOUBLE
743  inline scalar scalarToken() const;
744 
745  //- Return label, float or double value.
746  // Report FatalIOError and return \b 0 if token is not a
747  // LABEL, FLOAT or DOUBLE
748  inline scalar number() const;
749 
750  //- Return const reference to the word contents.
751  // Report FatalIOError and return \b "" if token is not a
752  // WORD or DIRECTIVE
753  inline const word& wordToken() const;
754 
755  //- Return const reference to the string contents.
756  // Report FatalIOError and return \b "" if token is not a
757  // STRING, EXPRESSION, VARIABLE, VERBATIM, CHAR_DATA
758  // or an upcast WORD or DIRECTIVE
759  inline const string& stringToken() const;
760 
761  //- Const reference to compound token. Fatal if the wrong type.
762  inline const compound& compoundToken() const;
763 
764  //- Return reference to compound token. Fatal if the wrong type.
765  //- No checks for \em released or \em pending states
766  inline compound& refCompoundToken();
767 
768  //- Return reference to the underlying encapsulated container
769  //- (eg, \c List<label> etc) of a compound token.
770  //- No checks for \em released or \em pending states
771  template<class Type>
772  inline Type& refCompoundToken();
773 
774  //- Default construct the specified compound type and read from stream.
775  // A no-op and returns false if compound type is unknown.
776  // Modify the token and return true on success.
777  bool readCompoundToken
778  (
779  const word& compoundType,
780  Istream& is,
781  const bool readContent = true
782  );
783 
784  //- Return reference to compound and mark internally as \em released.
785  // Optional Istream parameter only as reference for errors messages.
786  compound& transferCompoundToken(const Istream* is = nullptr);
787 
788  //- Return reference to compound and mark internally as \em released.
789  // The Istream is used for reference error messages only.
790  inline compound& transferCompoundToken(const Istream& is);
791 
792  //- Mark the compound as \em released and return a reference
793  //- to the underlying encapsulated container - eg, \c List<label>
794  // The Istream is used for reference error messages only.
795  template<class Type>
796  inline Type& transferCompoundToken(const Istream& is);
797 
798 
799  // Edit
800 
801  //- Reset token to UNDEFINED and clear any allocated storage
802  inline void reset();
803 
804  //- Clear token and set to be ERROR.
805  inline void setBad();
806 
807  //- Swap token contents: type, data, line-number
808  inline void swap(token& tok) noexcept;
809 
810 
811  // Info
812 
813  //- Return info proxy,
814  //- for printing token information to a stream
815  InfoProxy<token> info() const noexcept { return *this; }
816 
817 
818  // Member Operators
819 
820  // Assignment
821 
822  //- Copy assign
823  inline void operator=(const token& tok);
824 
825  //- Move assign
826  inline void operator=(token&& tok);
827 
828  //- Copy assign from punctuation
829  inline void operator=(const punctuationToken p);
830 
831  //- Copy assign from label
832  inline void operator=(const label val);
833 
834  //- Copy assign from float
835  inline void operator=(const float val);
836 
837  //- Copy assign from double
838  inline void operator=(const double val);
839 
840  //- Copy assign from word content
841  inline void operator=(const word& w);
842 
843  //- Copy assign from string content
844  inline void operator=(const string& str);
845 
846  //- Move assign from word content
847  inline void operator=(word&& w);
848 
849  //- Move assign from string content
850  inline void operator=(string&& str);
851 
852  //- Assign compound with reference counting to token
853  inline void operator=(token::compound* ptr);
854 
855  //- Move assign from compound pointer
856  inline void operator=(autoPtr<token::compound>&& ptr);
857 
858 
859  // Equality
860 
861  inline bool operator==(const token& tok) const;
862  inline bool operator==(const punctuationToken p) const noexcept;
863  inline bool operator==(const label val) const noexcept;
864  inline bool operator==(const float val) const noexcept;
865  inline bool operator==(const double val) const noexcept;
866  inline bool operator==(const std::string& s) const;
867 
868 
869  // Inequality
870 
871  inline bool operator!=(const token& tok) const;
872  inline bool operator!=(const punctuationToken p) const noexcept;
873  inline bool operator!=(const label val) const noexcept;
874  inline bool operator!=(const float val) const noexcept;
875  inline bool operator!=(const double val) const noexcept;
876  inline bool operator!=(const std::string& s) const;
877 
878 
879  // IOstream Operators
880 
881  friend Ostream& operator<<(Ostream& os, const token& tok);
882 
883  friend Ostream& operator<<(Ostream& os, const punctuationToken& pt);
884  friend ostream& operator<<(ostream& os, const punctuationToken& pt);
885 
886  friend ostream& operator<<(ostream& os, const InfoProxy<token>& ip);
887 
888 
889  // Housekeeping
890 
891  //- Write access for the token line number
892  // \deprecated(2021-03) - use lineNumber(label)
893  label& lineNumber() noexcept { return line_; }
894 
895  //- Token is FLOAT
896  // \deprecated(2020-01) - isFloat()
897  bool isFloatScalar() const { return isFloat(); };
898 
899  //- Token is DOUBLE
900  // \deprecated(2020-01) - isDouble()
901  bool isDoubleScalar() const { return isDouble(); }
902 
903  //- Return float value.
904  // \deprecated(2020-01) - floatToken()
905  float floatScalarToken() const { return floatToken(); }
906 
907  //- Return double value.
908  // \deprecated(2020-01) - doubleToken()
909  double doubleScalarToken() const { return doubleToken(); }
910 
911  //- Deprecated(2017-11) transfer word pointer to the token
912  // \deprecated(2017-11) - use move assign from word
913  void operator=(word*) = delete;
914 
915  //- Deprecated(2017-11) transfer string pointer to the token
916  // \deprecated(2017-11) - use move assign from string
917  void operator=(string*) = delete;
918 };
919 
920 
921 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
922 
923 // IOstream Operators
924 
925 Istream& operator>>(Istream& is, token& tok);
926 Ostream& operator<<(Ostream& os, const token::punctuationToken& pt);
927 ostream& operator<<(ostream& os, const token::punctuationToken& pt);
928 Ostream& operator<<(Ostream& os, const token::compound& ct);
929 
930 ostream& operator<<(ostream& os, const InfoProxy<token>& ip);
931 
932 template<>
933 Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip);
934 
935 
936 // Handling of compound types
937 
938 //- Define compound using \a Type for its name
939 #define defineCompoundTypeName(Type, UnusedTag) \
940  defineTemplateTypeNameWithName(token::Compound<Type>, #Type);
941 
942 //- Define compound using \a Name for its name
943 #define defineNamedCompoundTypeName(Type, Name) \
944  defineTemplateTypeNameWithName(token::Compound<Type>, #Name);
945 
946 //- Add compound to selection tables, lookup using typeName
947 #define addCompoundToRunTimeSelectionTable(Type, Tag) \
948  token::compound::addemptyConstructorToTable<token::Compound<Type>> \
949  add##Tag##emptyConstructorToTable_;
950 
951 //- Add compound to selection tables, lookup as \a Name
952 #define addNamedCompoundToRunTimeSelectionTable(Type, Tag, Name) \
953  token::compound::addemptyConstructorToTable<token::Compound<Type>> \
954  add##Tag##emptyConstructorToTable_(#Name);
955 
956 
957 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
958 
959 } // End namespace Foam
960 
961 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
962 
963 #include "tokenI.H"
964 #include "Istream.H"
965 
966 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
967 
968 #endif
969 
970 // ************************************************************************* //
Subtract or start of negative number.
Definition: token.H:145
static bool isCompound(const word &compoundType)
True if a known (registered) compound type.
Definition: token.C:104
virtual void read(Istream &is)=0
Read from stream into the underlying content.
Begin block [isseparator].
Definition: token.H:165
static const token undefinedToken
An undefined token.
Definition: token.H:559
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
Definition: tokenI.H:507
double doubleScalarToken() const
Return double value.
Definition: token.H:1239
static autoPtr< compound > New(const word &compoundType)
Default construct specified compound type.
Definition: token.C:52
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:561
bool operator!=(const token &tok) const
Definition: tokenI.H:1202
bool isDouble() const noexcept
Token is DOUBLE.
Definition: tokenI.H:663
boolean type
Definition: token.H:84
Left parenthesis [isseparator].
Definition: token.H:149
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
Definition: tokenI.H:729
BINARY-mode stream.
Definition: token.H:119
punctuationToken pToken() const
Return punctuation character.
Definition: tokenI.H:587
uint8_t direction
Definition: direction.H:46
A line primitive.
Definition: line.H:52
constexpr token() noexcept
Default construct, initialized to an UNDEFINED token.
Definition: tokenI.H:113
virtual tokenType typeCode() const
The token type (if any) corresponding to the contained component type (LABEL, FLOAT, DOUBLE, etc).
Definition: tokenI.H:907
single character punctuation
Definition: token.H:83
No flags.
Definition: token.H:117
patchWriters resize(patchIds.size())
Reference counter for various OpenFOAM components.
Definition: refCount.H:44
stream flag (1-byte bitmask)
Definition: token.H:82
Double quote.
Definition: token.H:141
bool isCompound() const noexcept
Token is COMPOUND.
Definition: tokenI.H:821
scalar number() const
Return label, float or double value.
Definition: tokenI.H:713
Begin dimensions [isseparator].
Definition: token.H:163
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.H:747
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds an item read from Istream.
Definition: token.H:65
TypeNameNoDebug("Compound<T>")
Declare type-name, virtual type (without debug switch)
tokenType
Enumeration defining the types of token.
Definition: token.H:76
Newline [isspace].
Definition: token.H:130
bool moved() const noexcept
Get compound transferred status.
Definition: token.H:265
The vector-space number of components: default is 1.
Definition: pTraits.H:168
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
tokenType type() const noexcept
Return the token type.
Definition: tokenI.H:405
bool isFlag() const noexcept
Token is FLAG.
Definition: tokenI.H:543
Begin string with double quote.
Definition: token.H:168
friend Ostream & operator<<(Ostream &os, const token &tok)
Begin list [isseparator].
Definition: token.H:161
Subtract or start of negative number.
Definition: token.H:159
Addition [isseparator].
Definition: token.H:158
Assignment/equals [isseparator].
Definition: token.H:143
float floatToken() const
Return float value.
Definition: tokenI.H:651
bool isExpression() const noexcept
Token is EXPRESSION (string variant)
Definition: tokenI.H:771
bool isSeparator() const noexcept
Token is PUNCTUATION and isseparator.
Definition: tokenI.H:577
virtual ~compound() noexcept=default
Destructor.
The vector-space rank: default is 0.
Definition: pTraits.H:127
End entry [isseparator].
Definition: token.H:160
bool undefined() const noexcept
Token is UNDEFINED.
Definition: tokenI.H:513
virtual void resize(const label n)
Change the size of the underlying content.
Definition: token.H:477
scalar scalarToken() const
Return float or double value.
Definition: tokenI.H:691
bool boolToken() const
Return boolean token value.
Definition: tokenI.H:531
Dollar - start variable or expression.
Definition: token.H:137
bool readCompoundToken(const word &compoundType, Istream &is, const bool readContent=true)
Default construct the specified compound type and read from stream.
Definition: token.C:126
word name() const
Return the name of the current token type.
Definition: tokenI.H:399
Foam::word.
Definition: token.H:90
declareRunTimeSelectionTable(autoPtr, compound, empty,(),())
Declare run-time constructor selection table.
static constexpr const char *const typeName
The type name is "token".
Definition: token.H:634
virtual void fill_zero()=0
Fill with zero values, or with default constructed.
virtual direction nComponents() const
The number of vector-space or other components of the underlying data content.
Definition: token.H:517
virtual std::streamsize size_bytes() const
Size of the (contiguous) byte data.
Definition: token.H:549
End dimensions [isseparator].
Definition: token.H:164
bool isScalar() const noexcept
Token is FLOAT or DOUBLE.
Definition: tokenI.H:681
bool isString() const noexcept
Token is string-variant (STRING, EXPRESSION, VARIABLE, VERBATIM, CHAR_DATA)
Definition: tokenI.H:765
virtual void fill_zero()
Fill with zero value or with default value initialized.
Definition: token.H:485
int flagToken() const
Return flag bitmask value.
Definition: tokenI.H:549
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:70
Right square bracket [isseparator].
Definition: token.H:152
Abstract base class for complex tokens.
Definition: token.H:176
Compound()=default
Default construct.
A templated class for holding compound tokens. The underlying container is normally a List of values...
Definition: token.H:365
label (integer) type
Definition: token.H:85
Addition [isseparator].
Definition: token.H:144
Right parenthesis [isseparator].
Definition: token.H:150
Comma [isseparator].
Definition: token.H:135
Compound type such as List<label> etc.
Definition: token.H:92
label lineNumber() const noexcept
The line number for the token.
Definition: tokenI.H:493
double doubleToken() const
Return double value.
Definition: tokenI.H:669
compatibility name for FLOAT
Definition: token.H:106
compound & transferCompoundToken(const Istream *is=nullptr)
Return reference to compound and mark internally as released.
Definition: token.C:157
Left square bracket [isseparator].
Definition: token.H:151
Single quote.
Definition: token.H:140
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
bool isStringType() const noexcept
Token is word-variant or string-variant (WORD, DIRECTIVE, STRING, EXPRESSION, VARIABLE, VERBATIM, CHAR_DATA)
Definition: tokenI.H:795
virtual std::streamsize size_bytes() const =0
Size of the (contiguous) byte data.
virtual const char * cdata_bytes() const =0
Pointer to the underlying data as byte data.
A class for handling words, derived from Foam::string.
Definition: word.H:63
static bool isseparator(int c) noexcept
True if the character is a punctuation separator (eg, in ISstream).
Definition: tokenI.H:69
virtual void resize(const label n)=0
Change the size of the underlying container content.
Istream & operator>>(Istream &, directionInfo &)
End string with double quote.
Definition: token.H:169
flagType
Stream or output control flags (1-byte width)
Definition: token.H:115
Space [isspace].
Definition: token.H:131
void swap(token &tok) noexcept
Swap token contents: type, data, line-number.
Definition: tokenI.H:386
void setBad()
Clear token and set to be ERROR.
Definition: tokenI.H:379
punctuationToken
Standard punctuation tokens (a character)
Definition: token.H:126
virtual void read(Istream &is)
Redirect read to underlying content.
Definition: token.H:490
compatibility name for VERBATIM
Definition: token.H:108
void operator=(const Compound< T > &)=delete
No copy assignment.
const compound & compoundToken() const
Const reference to compound token. Fatal if the wrong type.
Definition: tokenI.H:849
End list [isseparator].
Definition: token.H:162
float (single-precision) type
Definition: token.H:86
virtual direction nComponents() const =0
The number of vector-space or other components of the underlying data content.
float floatScalarToken() const
Return float value.
Definition: token.H:1232
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
Divide [isseparator].
Definition: token.H:147
bool isBool() const noexcept
Token is BOOL.
Definition: tokenI.H:525
constexpr compound() noexcept
Default construct.
Definition: token.H:214
Token error encountered.
Definition: token.H:79
bool setType(const tokenType tokType) noexcept
Change the token type, for similar types.
Definition: tokenI.H:411
The TAB Method for Numerical Calculation of Spray Droplet Breakup.
Definition: TAB.H:60
OBJstream os(runTime.globalPath()/outputName)
bool isFloatScalar() const
Token is FLOAT.
Definition: token.H:1218
bool isDoubleScalar() const
Token is DOUBLE.
Definition: token.H:1225
const string & stringToken() const
Return const reference to the string contents.
Definition: tokenI.H:801
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Left brace [isseparator].
Definition: token.H:153
unsigned char state_
The compound token state, internally used values only.
Definition: token.H:187
static token flag(int bitmask) noexcept
Create a token with stream flags, no sanity check.
Definition: tokenI.H:36
bool operator==(const token &tok) const
Definition: tokenI.H:1105
Foam::string (usually double-quoted)
Definition: token.H:91
virtual tokenType typeCode() const =0
The token type (if any) corresponding to the contained component type (LABEL, FLOAT, DOUBLE, etc).
void operator=(const token &tok)
Copy assign.
Definition: tokenI.H:961
TypeNameNoDebug("compound")
Declare type-name, virtual type (without debug switch)
virtual const char * cdata_bytes() const
Pointer to the underlying data as byte data.
Definition: token.H:533
bool isCharData() const noexcept
Token is CHAR_DATA (string variant)
Definition: tokenI.H:789
Basic run-time type information using word as the type&#39;s name. Used to enhance the standard RTTI to c...
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
bool isFloat() const noexcept
Token is FLOAT.
Definition: tokenI.H:645
void reset()
Reset token to UNDEFINED and clear any allocated storage.
Definition: tokenI.H:335
virtual label size() const =0
The size of the underlying content.
A helper class for outputting values to Ostream.
Definition: ensightCells.H:44
ASCII-mode stream.
Definition: token.H:118
const dimensionedScalar c
Speed of light in a vacuum.
virtual char * data_bytes()=0
Pointer to the underlying data as byte data.
label labelToken() const
Return label value.
Definition: tokenI.H:633
Semicolon [isseparator].
Definition: token.H:134
double (double-precision) type
Definition: token.H:87
Right brace [isseparator].
Definition: token.H:154
T::value_type value_type
The type of values held by the compound.
Definition: token.H:397
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:599
The &#39;at&#39; symbol.
Definition: token.H:139
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition: token.H:1106
virtual direction rank() const =0
The vector-space rank associated with the data content.
virtual direction rank() const
The vector-space rank associated with the data content.
Definition: token.H:525
compound & refCompoundToken()
Return reference to compound token. Fatal if the wrong type. No checks for released or pending states...
Definition: tokenI.H:859
label n
String-variant: plain character content.
Definition: token.H:103
virtual char * data_bytes()
Pointer to the underlying data as byte data.
Definition: token.H:541
virtual void write(Ostream &os) const
Redirect write to underlying content.
Definition: token.H:499
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
const Type * isA() const
Attempt dynamic_cast to Type returns nullptr if cast is not possible.
Definition: token.H:249
Macros to ease declaration of run-time selection tables.
Question mark (eg, ternary)
Definition: token.H:138
volScalarField & p
bool isVariable() const noexcept
Token is VARIABLE (string variant)
Definition: tokenI.H:777
bool isDirective() const noexcept
Token is DIRECTIVE (word variant)
Definition: tokenI.H:741
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
End block [isseparator].
Definition: token.H:166
Foam::argList args(argc, argv)
Nul character.
Definition: token.H:128
static autoPtr< compound > New(Args &&... args)
Construct autoPtr compound with forwarding arguments.
Definition: token.H:455
bool isNumber() const noexcept
Token is LABEL, FLOAT or DOUBLE.
Definition: tokenI.H:707
compatibility name for DOUBLE
Definition: token.H:107
An undefined token-type.
Definition: token.H:78
virtual void write(Ostream &os) const =0
Write the underlying content.
friend Ostream & operator<<(Ostream &os, const compound &ct)
Output operator.
bool isVerbatim() const noexcept
Token is VERBATIM string (string variant)
Definition: tokenI.H:783
Multiply [isseparator].
Definition: token.H:146
bool pending() const noexcept
Get compound pending-read status.
Definition: token.H:278
Namespace for OpenFOAM.
Hash - directive or start verbatim string.
Definition: token.H:136
virtual label size() const
The size of the underlying content.
Definition: token.H:469
bool isQuotedString() const noexcept
Token is (quoted) STRING (string variant)
Definition: tokenI.H:759
Colon [isseparator].
Definition: token.H:133