tokenI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <iostream>
27 #include "token.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 inline void Foam::token::clear()
32 {
33  if (type_ == WORD)
34  {
35  delete wordTokenPtr_;
36  }
37  else if (type_ == FUNCTIONNAME)
38  {
39  delete functionNameTokenPtr_;
40  }
41  else if (type_ == VARIABLE)
42  {
43  delete variableTokenPtr_;
44  }
45  else if (type_ == STRING)
46  {
47  delete stringTokenPtr_;
48  }
49  else if (type_ == VERBATIMSTRING)
50  {
52  }
53  else if (type_ == LONG_DOUBLE_SCALAR)
54  {
56  }
57  else if (type_ == COMPOUND)
58  {
60  {
61  delete compoundTokenPtr_;
62  }
63  else
64  {
65  compoundTokenPtr_->refCount::operator--();
66  }
67  }
68 
69  type_ = UNDEFINED;
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 
76 :
77  type_(UNDEFINED),
78  lineNumber_(0)
79 {}
80 
81 
82 inline Foam::token::token(const token& t)
83 :
84  type_(t.type_),
85  lineNumber_(t.lineNumber_)
86 {
87  switch (type_)
88  {
89  case token::UNDEFINED:
90  break;
91 
92  case PUNCTUATION:
94  break;
95 
96  case WORD:
98  break;
99 
100  case FUNCTIONNAME:
102  break;
103 
104  case VARIABLE:
106  break;
107 
108  case STRING:
110  break;
111 
112  case VERBATIMSTRING:
115  break;
116 
117  case INTEGER_32:
119  break;
120 
121  case INTEGER_64:
123  break;
124 
125  case UNSIGNED_INTEGER_32:
127  break;
128 
129  case UNSIGNED_INTEGER_64:
131  break;
132 
133  case FLOAT_SCALAR:
135  break;
136 
137  case DOUBLE_SCALAR:
139  break;
140 
141  case LONG_DOUBLE_SCALAR:
144  break;
145 
146  case COMPOUND:
148  compoundTokenPtr_->refCount::operator++();
149  break;
150 
151  case token::ERROR:
152  break;
153  }
154 }
155 
156 
158 :
159  type_(PUNCTUATION),
160  punctuationToken_(p),
161  lineNumber_(lineNumber)
162 {}
163 
164 
165 inline Foam::token::token(const word& w, label lineNumber)
166 :
167  type_(WORD),
168  wordTokenPtr_(new word(w)),
169  lineNumber_(lineNumber)
170 {}
171 
172 
173 inline Foam::token::token(const string& s, label lineNumber)
174 :
175  type_(STRING),
176  stringTokenPtr_(new string(s)),
177  lineNumber_(lineNumber)
178 {}
179 
180 
181 inline Foam::token::token(const keyType& kt, label lineNumber)
182 :
183  type_(UNDEFINED),
184  lineNumber_(lineNumber)
185 {
186  switch (kt.Type())
187  {
188  case keyType::UNDEFINED:
189  {
190  type_ = UNDEFINED;
191  break;
192  }
193 
194  case keyType::WORD:
195  {
196  type_ = WORD;
197  wordTokenPtr_ = new word(kt);
198  break;
199  }
200 
202  {
203  type_ = FUNCTIONNAME;
205  break;
206  }
207 
208  case keyType::VARIABLE:
209  {
210  type_ = VARIABLE;
211  variableTokenPtr_ = new variable(kt);
212  break;
213  }
214 
215  case keyType::PATTERN:
216  {
217  type_ = STRING;
218  stringTokenPtr_ = new string(kt);
219  break;
220  }
221  }
222 }
223 
224 
225 inline Foam::token::token(const verbatimString& vs, label lineNumber)
226 :
227  type_(VERBATIMSTRING),
228  verbatimStringTokenPtr_(new verbatimString(vs)),
229  lineNumber_(lineNumber)
230 {}
231 
232 
233 inline Foam::token::token(const int32_t l, label lineNumber)
234 :
235  type_(INTEGER_32),
236  integer32Token_(l),
237  lineNumber_(lineNumber)
238 {}
239 
240 
241 inline Foam::token::token(const int64_t l, label lineNumber)
242 :
243  type_(INTEGER_64),
244  integer64Token_(l),
245  lineNumber_(lineNumber)
246 {}
247 
248 
249 inline Foam::token::token(const uint32_t l, label lineNumber)
250 :
251  type_(UNSIGNED_INTEGER_32),
252  unsignedInteger32Token_(l),
253  lineNumber_(lineNumber)
254 {}
255 
256 
257 inline Foam::token::token(const uint64_t l, label lineNumber)
258 :
259  type_(UNSIGNED_INTEGER_64),
260  unsignedInteger64Token_(l),
261  lineNumber_(lineNumber)
262 {}
263 
264 
265 inline Foam::token::token(const floatScalar s, label lineNumber)
266 :
267  type_(FLOAT_SCALAR),
268  floatScalarToken_(s),
269  lineNumber_(lineNumber)
270 {}
271 
272 
273 inline Foam::token::token(const doubleScalar s, label lineNumber)
274 :
275  type_(DOUBLE_SCALAR),
276  doubleScalarToken_(s),
277  lineNumber_(lineNumber)
278 {}
279 
280 
281 inline Foam::token::token(const longDoubleScalar s, label lineNumber)
282 :
283  type_(LONG_DOUBLE_SCALAR),
284  longDoubleScalarTokenPtr_(new longDoubleScalar(s)),
285  lineNumber_(lineNumber)
286 {}
287 
288 
289 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
290 
292 {
293  clear();
294 }
295 
296 
297 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
298 
300 {
301  return type_;
302 }
303 
305 {
306  return type_;
307 }
308 
309 inline bool Foam::token::good() const
310 {
311  return (type_ != ERROR && type_ != UNDEFINED);
312 }
313 
314 inline bool Foam::token::undefined() const
315 {
316  return (type_ == UNDEFINED);
317 }
318 
319 inline bool Foam::token::error() const
320 {
321  return (type_ == ERROR);
322 }
323 
324 inline bool Foam::token::isPunctuation() const
325 {
326  return (type_ == PUNCTUATION);
327 }
328 
330 {
331  if (type_ == PUNCTUATION)
332  {
333  return punctuationToken_;
334  }
335  else
336  {
337  parseError("punctuation character");
338  return NULL_TOKEN;
339  }
340 }
341 
342 inline bool Foam::token::isWord() const
343 {
344  return (type_ == WORD);
345 }
346 
347 inline const Foam::word& Foam::token::wordToken() const
348 {
349  if (type_ == WORD)
350  {
351  return *wordTokenPtr_;
352  }
353  else
354  {
355  parseError(word::typeName);
356  return word::null;
357  }
358 }
359 
360 inline bool Foam::token::isFunctionName() const
361 {
362  return (type_ == FUNCTIONNAME);
363 }
364 
366 {
367  if (type_ == FUNCTIONNAME)
368  {
369  return *functionNameTokenPtr_;
370  }
371  else
372  {
373  parseError(functionName::typeName);
374  return functionName::null;
375  }
376 }
377 
378 inline bool Foam::token::isVariable() const
379 {
380  return (type_ == VARIABLE);
381 }
382 
384 {
385  if (type_ == VARIABLE)
386  {
387  return *variableTokenPtr_;
388  }
389  else
390  {
391  parseError(variable::typeName);
392  return variable::null;
393  }
394 }
395 
396 inline bool Foam::token::isString() const
397 {
398  return (type_ == STRING);
399 }
400 
402 {
403  if (type_ == STRING)
404  {
405  return *stringTokenPtr_;
406  }
407  else
408  {
409  parseError(string::typeName);
410  return string::null;
411  }
412 }
413 
414 inline bool Foam::token::isVerbatimString() const
415 {
416  return (type_ == VERBATIMSTRING);
417 }
418 
420 {
421  if (type_ == VERBATIMSTRING)
422  {
423  return *verbatimStringTokenPtr_;
424  }
425  else
426  {
427  parseError(verbatimString::typeName);
428  return verbatimString::null;
429  }
430 }
431 
432 inline bool Foam::token::isAnyString() const
433 {
434  return
435  (
436  type_ == WORD
437  || type_ == FUNCTIONNAME
438  || type_ == VARIABLE
439  || type_ == STRING
440  || type_ == VERBATIMSTRING
441  );
442 }
443 
445 {
446  if (type_ == WORD)
447  {
448  return *wordTokenPtr_;
449  }
450  else if (type_ == FUNCTIONNAME)
451  {
452  return *functionNameTokenPtr_;
453  }
454  else if (type_ == VARIABLE)
455  {
456  return *variableTokenPtr_;
457  }
458  else if (type_ == STRING)
459  {
460  return *stringTokenPtr_;
461  }
462  else if (type_ == VERBATIMSTRING)
463  {
464  return *verbatimStringTokenPtr_;
465  }
466  else
467  {
468  parseError(string::typeName);
469  return string::null;
470  }
471 }
472 
473 inline bool Foam::token::isInteger32() const
474 {
475  return
476  type_ == INTEGER_32
477  || (
478  type_ == INTEGER_64
479  && (integer64Token_ >= INT32_MIN) && (integer64Token_ <= INT32_MAX)
480  )
481  || (type_ == UNSIGNED_INTEGER_32 && unsignedInteger32Token_ <= INT32_MAX)
482  || (type_ == UNSIGNED_INTEGER_64 && unsignedInteger64Token_ <= INT32_MAX);
483 }
484 
485 inline int32_t Foam::token::integer32Token() const
486 {
487  if (type_ == INTEGER_32)
488  {
489  return integer32Token_;
490  }
491  else if (type_ == INTEGER_64)
492  {
493  return integer64Token_;
494  }
495  if (type_ == UNSIGNED_INTEGER_32)
496  {
497  return unsignedInteger32Token_;
498  }
499  else if (type_ == UNSIGNED_INTEGER_64)
500  {
501  return unsignedInteger64Token_;
502  }
503  else
504  {
505  parseError(pTraits<int32_t>::typeName);
506  return 0;
507  }
508 }
509 
510 inline bool Foam::token::isInteger64() const
511 {
512  return
513  type_ == INTEGER_32
514  || type_ == INTEGER_64
515  || type_ == UNSIGNED_INTEGER_32
516  || (type_ == UNSIGNED_INTEGER_64 && unsignedInteger64Token_ <= INT64_MAX);
517 }
518 
519 inline int64_t Foam::token::integer64Token() const
520 {
521  if (type_ == INTEGER_32)
522  {
523  return integer32Token_;
524  }
525  else if (type_ == INTEGER_64)
526  {
527  return integer64Token_;
528  }
529  if (type_ == UNSIGNED_INTEGER_32)
530  {
531  return unsignedInteger32Token_;
532  }
533  else if (type_ == UNSIGNED_INTEGER_64)
534  {
535  return unsignedInteger64Token_;
536  }
537  else
538  {
539  parseError(pTraits<int64_t>::typeName);
540  return 0;
541  }
542 }
543 
545 {
546  return
547  (type_ == INTEGER_32 && integer32Token_ >= 0)
548  || (
549  type_ == INTEGER_64
550  && (integer64Token_ >= 0) && (integer64Token_ <= UINT32_MAX)
551  )
552  || type_ == UNSIGNED_INTEGER_32
553  || (type_ == UNSIGNED_INTEGER_64 && unsignedInteger64Token_ <= UINT32_MAX);
554 }
555 
556 inline uint32_t Foam::token::unsignedInteger32Token() const
557 {
558  if (type_ == INTEGER_32)
559  {
560  return integer32Token_;
561  }
562  else if (type_ == INTEGER_64)
563  {
564  return integer64Token_;
565  }
566  if (type_ == UNSIGNED_INTEGER_32)
567  {
568  return unsignedInteger32Token_;
569  }
570  else if (type_ == UNSIGNED_INTEGER_64)
571  {
572  return unsignedInteger64Token_;
573  }
574  else
575  {
576  parseError(pTraits<uint32_t>::typeName);
577  return 0;
578  }
579 }
580 
582 {
583  return
584  (type_ == INTEGER_32 && integer32Token_ >= 0)
585  || (type_ == INTEGER_64 && integer64Token_ >= 0)
586  || type_ == UNSIGNED_INTEGER_32
587  || type_ == UNSIGNED_INTEGER_64;
588 }
589 
590 inline uint64_t Foam::token::unsignedInteger64Token() const
591 {
592  if (type_ == INTEGER_32)
593  {
594  return integer32Token_;
595  }
596  else if (type_ == INTEGER_64)
597  {
598  return integer64Token_;
599  }
600  if (type_ == UNSIGNED_INTEGER_32)
601  {
602  return unsignedInteger32Token_;
603  }
604  else if (type_ == UNSIGNED_INTEGER_64)
605  {
606  return unsignedInteger64Token_;
607  }
608  else
609  {
610  parseError(pTraits<uint64_t>::typeName);
611  return 0;
612  }
613 }
614 
615 inline bool Foam::token::isLabel() const
616 {
617  return
618  type_ == INTEGER_32
619  || (
620  type_ == INTEGER_64
621  && integer64Token_ >= int64_t(labelMin)
622  && integer64Token_ <= int64_t(labelMax)
623  )
624  || (
625  type_ == UNSIGNED_INTEGER_32
626  && uint64_t(unsignedInteger32Token_) <= uint64_t(labelMax)
627  )
628  || (
629  type_ == UNSIGNED_INTEGER_64
630  && unsignedInteger64Token_ <= uint64_t(labelMax)
631  );
632 }
633 
635 {
636  if (type_ == INTEGER_32)
637  {
638  return integer32Token_;
639  }
640  else if (type_ == INTEGER_64)
641  {
642  return integer64Token_;
643  }
644  if (type_ == UNSIGNED_INTEGER_32)
645  {
646  return unsignedInteger32Token_;
647  }
648  else if (type_ == UNSIGNED_INTEGER_64)
649  {
650  return unsignedInteger64Token_;
651  }
652  else
653  {
654  parseError(pTraits<label>::typeName);
655  return 0;
656  }
657 }
658 
659 inline bool Foam::token::isULabel() const
660 {
661  return
662  (
663  type_ == INTEGER_32
664  && integer32Token_ >= 0
665  )
666  || (
667  type_ == INTEGER_64
668  && integer64Token_ >= 0
669  && uint64_t(integer64Token_) <= uint64_t(uLabelMax)
670  )
671  || type_ == UNSIGNED_INTEGER_32
672  || (
673  type_ == UNSIGNED_INTEGER_64
674  && unsignedInteger64Token_ <= uint64_t(uLabelMax)
675  );
676 }
677 
679 {
680  if (type_ == INTEGER_32)
681  {
682  return integer32Token_;
683  }
684  else if (type_ == INTEGER_64)
685  {
686  return integer64Token_;
687  }
688  if (type_ == UNSIGNED_INTEGER_32)
689  {
690  return unsignedInteger32Token_;
691  }
692  else if (type_ == UNSIGNED_INTEGER_64)
693  {
694  return unsignedInteger64Token_;
695  }
696  else
697  {
698  parseError(pTraits<uLabel>::typeName);
699  return 0;
700  }
701 }
702 
703 inline bool Foam::token::isFloatScalar() const
704 {
705  return (type_ == FLOAT_SCALAR);
706 }
707 
709 {
710  if (type_ == FLOAT_SCALAR)
711  {
712  return floatScalarToken_;
713  }
714  else
715  {
716  parseError("floatScalar");
717  return 0.0;
718  }
719 }
720 
721 
722 inline bool Foam::token::isDoubleScalar() const
723 {
724  return (type_ == DOUBLE_SCALAR);
725 }
726 
728 {
729  if (type_ == DOUBLE_SCALAR)
730  {
731  return doubleScalarToken_;
732  }
733  else
734  {
735  parseError("doubleScalar");
736  return 0.0;
737  }
738 }
739 
740 
742 {
743  return (type_ == LONG_DOUBLE_SCALAR);
744 }
745 
747 {
748  if (type_ == LONG_DOUBLE_SCALAR)
749  {
750  return *longDoubleScalarTokenPtr_;
751  }
752  else
753  {
754  parseError("longDoubleScalar");
755  return 0.0;
756  }
757 }
758 
759 
760 inline bool Foam::token::isScalar() const
761 {
762  return
763  type_ == FLOAT_SCALAR
764  || type_ == DOUBLE_SCALAR
765  || type_ == LONG_DOUBLE_SCALAR;
766 }
767 
768 inline Foam::scalar Foam::token::scalarToken() const
769 {
770  if (type_ == FLOAT_SCALAR)
771  {
772  return floatScalarToken_;
773  }
774  else if (type_ == DOUBLE_SCALAR)
775  {
776  return doubleScalarToken_;
777  }
778  else if (type_ == LONG_DOUBLE_SCALAR)
779  {
780  return *longDoubleScalarTokenPtr_;
781  }
782  else
783  {
784  parseError(pTraits<scalar>::typeName);
785  return 0.0;
786  }
787 }
788 
789 inline bool Foam::token::isNumber() const
790 {
791  return
792  type_ == INTEGER_32
793  || type_ == INTEGER_64
794  || type_ == UNSIGNED_INTEGER_32
795  || type_ == UNSIGNED_INTEGER_64
796  || isScalar();
797 }
798 
799 inline Foam::scalar Foam::token::number() const
800 {
801  if (type_ == INTEGER_32)
802  {
803  return integer32Token_;
804  }
805  else if (type_ == INTEGER_64)
806  {
807  return integer64Token_;
808  }
809  if (type_ == UNSIGNED_INTEGER_32)
810  {
811  return unsignedInteger32Token_;
812  }
813  else if (type_ == UNSIGNED_INTEGER_64)
814  {
815  return unsignedInteger64Token_;
816  }
817  else if (isScalar())
818  {
819  return scalarToken();
820  }
821  else
822  {
823  parseError("number (label or scalar)");
824  return 0.0;
825  }
826 }
827 
828 inline bool Foam::token::isCompound() const
829 {
830  return (type_ == COMPOUND);
831 }
832 
834 {
835  if (type_ == COMPOUND)
836  {
837  return *compoundTokenPtr_;
838  }
839  else
840  {
841  parseError("compound");
842  return *compoundTokenPtr_;
843  }
844 }
845 
846 
848 {
849  return lineNumber_;
850 }
851 
853 {
854  return lineNumber_;
855 }
856 
857 
858 inline void Foam::token::setBad()
859 {
860  clear();
861  type_ = ERROR;
862 }
863 
864 
865 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
866 
867 inline void Foam::token::operator=(const token& t)
868 {
869  clear();
870  type_ = t.type_;
871 
872  switch (type_)
873  {
874  case token::UNDEFINED:
875  break;
876 
877  case PUNCTUATION:
878  punctuationToken_ = t.punctuationToken_;
879  break;
880 
881  case WORD:
882  wordTokenPtr_ = new word(*t.wordTokenPtr_);
883  break;
884 
885  case FUNCTIONNAME:
886  functionNameTokenPtr_ = new functionName(*t.functionNameTokenPtr_);
887  break;
888 
889  case VARIABLE:
890  variableTokenPtr_ = new variable(*t.variableTokenPtr_);
891  break;
892 
893  case STRING:
894  stringTokenPtr_ = new string(*t.stringTokenPtr_);
895  break;
896 
897  case VERBATIMSTRING:
898  verbatimStringTokenPtr_ =
900  break;
901 
902  case INTEGER_32:
903  integer32Token_ = t.integer32Token_;
904  break;
905 
906  case INTEGER_64:
907  integer64Token_ = t.integer64Token_;
908  break;
909 
910  case UNSIGNED_INTEGER_32:
911  unsignedInteger32Token_ = t.unsignedInteger32Token_;
912  break;
913 
914  case UNSIGNED_INTEGER_64:
915  unsignedInteger64Token_ = t.unsignedInteger64Token_;
916  break;
917 
918  case FLOAT_SCALAR:
919  floatScalarToken_ = t.floatScalarToken_;
920  break;
921 
922  case DOUBLE_SCALAR:
923  doubleScalarToken_ = t.doubleScalarToken_;
924  break;
925 
926  case LONG_DOUBLE_SCALAR:
927  longDoubleScalarTokenPtr_ =
929  break;
930 
931  case COMPOUND:
932  compoundTokenPtr_ = t.compoundTokenPtr_;
933  compoundTokenPtr_->refCount::operator++();
934  break;
935 
936  case token::ERROR:
937  break;
938  }
939 
940  lineNumber_ = t.lineNumber_;
941 }
942 
944 {
945  clear();
946  type_ = PUNCTUATION;
947  punctuationToken_ = p;
948 }
949 
950 inline void Foam::token::operator=(word* wPtr)
951 {
952  clear();
953  type_ = WORD;
954  wordTokenPtr_ = wPtr;
955 }
956 
957 inline void Foam::token::operator=(const word& w)
958 {
959  operator=(new word(w));
960 }
961 
963 {
964  clear();
965  type_ = FUNCTIONNAME;
966  functionNameTokenPtr_ = fnPtr;
967 }
968 
969 inline void Foam::token::operator=(const functionName& fn)
970 {
971  operator=(new functionName(fn));
972 }
973 
975 {
976  clear();
977  type_ = VARIABLE;
978  variableTokenPtr_ = vPtr;
979 }
980 
981 inline void Foam::token::operator=(const variable& v)
982 {
983  operator=(new variable(v));
984 }
985 
986 inline void Foam::token::operator=(string* sPtr)
987 {
988  clear();
989  type_ = STRING;
990  stringTokenPtr_ = sPtr;
991 }
992 
993 inline void Foam::token::operator=(const string& s)
994 {
995  operator=(new string(s));
996 }
997 
999 {
1000  clear();
1001  type_ = VERBATIMSTRING;
1002  verbatimStringTokenPtr_ = vsPtr;
1003 }
1004 
1006 {
1007  operator=(new verbatimString(vs));
1008 }
1009 
1010 inline void Foam::token::operator=(const int32_t l)
1011 {
1012  clear();
1013  type_ = INTEGER_32;
1014  integer32Token_ = l;
1015 }
1016 
1017 inline void Foam::token::operator=(const int64_t l)
1018 {
1019  clear();
1020  type_ = INTEGER_64;
1021  integer64Token_ = l;
1022 }
1023 
1024 inline void Foam::token::operator=(const uint32_t l)
1025 {
1026  clear();
1027  type_ = UNSIGNED_INTEGER_32;
1028  unsignedInteger32Token_ = l;
1029 }
1030 
1031 inline void Foam::token::operator=(const uint64_t l)
1032 {
1033  clear();
1034  type_ = UNSIGNED_INTEGER_64;
1035  unsignedInteger64Token_ = l;
1036 }
1037 
1039 {
1040  clear();
1041  type_ = FLOAT_SCALAR;
1042  floatScalarToken_ = s;
1043 }
1044 
1046 {
1047  clear();
1048  type_ = DOUBLE_SCALAR;
1049  doubleScalarToken_ = s;
1050 }
1051 
1053 {
1054  clear();
1055  type_ = LONG_DOUBLE_SCALAR;
1056  longDoubleScalarTokenPtr_ = new longDoubleScalar(s);
1057 }
1058 
1060 {
1061  clear();
1062  type_ = COMPOUND;
1063  compoundTokenPtr_ = cPtr;
1064 }
1065 
1066 
1067 inline bool Foam::token::operator==(const token& t) const
1068 {
1069  if (type_ != t.type_)
1070  {
1071  return false;
1072  }
1073 
1074  switch (type_)
1075  {
1076  case token::UNDEFINED:
1077  return true;
1078 
1079  case PUNCTUATION:
1080  return punctuationToken_ == t.punctuationToken_;
1081 
1082  case WORD:
1083  return *wordTokenPtr_ == *t.wordTokenPtr_;
1084 
1085  case FUNCTIONNAME:
1086  return *functionNameTokenPtr_ == *t.functionNameTokenPtr_;
1087 
1088  case VARIABLE:
1089  return *variableTokenPtr_ == *t.variableTokenPtr_;
1090 
1091  case STRING:
1092  return *stringTokenPtr_ == *t.stringTokenPtr_;
1093 
1094  case VERBATIMSTRING:
1095  return *verbatimStringTokenPtr_ == *t.verbatimStringTokenPtr_;
1096 
1097  case INTEGER_32:
1098  return integer32Token_ == t.integer32Token_;
1099 
1100  case INTEGER_64:
1101  return integer64Token_ == t.integer64Token_;
1102 
1103  case UNSIGNED_INTEGER_32:
1104  return unsignedInteger32Token_ == t.unsignedInteger32Token_;
1105 
1106  case UNSIGNED_INTEGER_64:
1107  return unsignedInteger64Token_ == t.unsignedInteger64Token_;
1108 
1109  case FLOAT_SCALAR:
1110  return equal(floatScalarToken_, t.floatScalarToken_);
1111 
1112  case DOUBLE_SCALAR:
1113  return equal(doubleScalarToken_, t.doubleScalarToken_);
1114 
1115  case LONG_DOUBLE_SCALAR:
1116  return equal
1117  (
1118  *longDoubleScalarTokenPtr_,
1120  );
1121 
1122  case COMPOUND:
1123  return compoundTokenPtr_ == t.compoundTokenPtr_;
1124 
1125  case token::ERROR:
1126  return true;
1127  }
1128 
1129  return false;
1130 }
1131 
1133 {
1134  return (type_ == PUNCTUATION && punctuationToken_ == p);
1135 }
1136 
1137 inline bool Foam::token::operator==(const word& w) const
1138 {
1139  return (type_ == WORD && wordToken() == w);
1140 }
1141 
1142 inline bool Foam::token::operator==(const functionName& fn) const
1143 {
1144  return (type_ == FUNCTIONNAME && functionNameToken() == fn);
1145 }
1146 
1147 inline bool Foam::token::operator==(const variable& v) const
1148 {
1149  return (type_ == VARIABLE && variableToken() == v);
1150 }
1151 
1152 inline bool Foam::token::operator==(const string& s) const
1153 {
1154  return (type_ == STRING && stringToken() == s);
1155 }
1156 
1157 inline bool Foam::token::operator==(const verbatimString& vs) const
1158 {
1159  return (type_ == VERBATIMSTRING && verbatimStringToken() == vs);
1160 }
1161 
1162 inline bool Foam::token::operator==(const int32_t l) const
1163 {
1164  return (type_ == INTEGER_32 && integer32Token_ == l);
1165 }
1166 
1167 inline bool Foam::token::operator==(const int64_t l) const
1168 {
1169  return (type_ == INTEGER_64 && integer64Token_ == l);
1170 }
1171 
1172 inline bool Foam::token::operator==(const uint32_t l) const
1173 {
1174  return (type_ == UNSIGNED_INTEGER_32 && unsignedInteger32Token_ == l);
1175 }
1176 
1177 inline bool Foam::token::operator==(const uint64_t l) const
1178 {
1179  return (type_ == UNSIGNED_INTEGER_64 && unsignedInteger64Token_ == l);
1180 }
1181 
1182 inline bool Foam::token::operator==(const floatScalar s) const
1183 {
1184  return (type_ == FLOAT_SCALAR && equal(floatScalarToken_, s));
1185 }
1186 
1187 inline bool Foam::token::operator==(const doubleScalar s) const
1188 {
1189  return (type_ == DOUBLE_SCALAR && equal(doubleScalarToken_, s));
1190 }
1191 
1193 {
1194  return
1195  (
1196  type_ == LONG_DOUBLE_SCALAR && equal(*longDoubleScalarTokenPtr_, s)
1197  );
1198 }
1199 
1200 inline bool Foam::token::operator!=(const token& t) const
1201 {
1202  return !operator==(t);
1203 }
1204 
1206 {
1207  return !operator==(p);
1208 }
1209 
1210 inline bool Foam::token::operator!=(const word& w) const
1211 {
1212  return !operator==(w);
1213 }
1214 
1215 inline bool Foam::token::operator!=(const functionName& fn) const
1216 {
1217  return !operator==(fn);
1218 }
1219 
1220 inline bool Foam::token::operator!=(const variable& v) const
1221 {
1222  return !operator==(v);
1223 }
1224 
1225 inline bool Foam::token::operator!=(const string& s) const
1226 {
1227  return !operator==(s);
1228 }
1229 
1230 inline bool Foam::token::operator!=(const verbatimString& vs) const
1231 {
1232  return !operator==(vs);
1233 }
1234 
1235 inline bool Foam::token::operator!=(const int32_t l) const
1236 {
1237  return !operator==(l);
1238 }
1239 
1240 inline bool Foam::token::operator!=(const int64_t l) const
1241 {
1242  return !operator==(l);
1243 }
1244 
1245 inline bool Foam::token::operator!=(const uint32_t l) const
1246 {
1247  return !operator==(l);
1248 }
1249 
1250 inline bool Foam::token::operator!=(const uint64_t l) const
1251 {
1252  return !operator==(l);
1253 }
1254 
1255 inline bool Foam::token::operator!=(const floatScalar s) const
1256 {
1257  return !operator==(s);
1258 }
1259 
1260 inline bool Foam::token::operator!=(const doubleScalar s) const
1261 {
1262  return !operator==(s);
1263 }
1264 
1266 {
1267  return !operator==(s);
1268 }
1269 
1270 
1271 // ************************************************************************* //
A functionName is a word starting with '#'.
Definition: functionName.H:60
static const functionName null
An empty functionName.
Definition: functionName.H:70
static const char *const typeName
Definition: functionName.H:66
A class for handling keywords in dictionaries.
Definition: keyType.H:69
type Type() const
Definition: keyType.H:131
@ FUNCTIONNAME
Definition: keyType.H:77
Traits class for primitives.
Definition: pTraits.H:53
bool unique() const
Return true if the reference count is zero.
Definition: refCount.H:81
A class for handling character strings derived from std::string.
Definition: string.H:79
static const string null
An empty string.
Definition: string.H:88
static const char *const typeName
Definition: string.H:84
Abstract base class for complex tokens.
Definition: token.H:134
A token holds items read from Istream.
Definition: token.H:74
bool isLabel() const
Definition: tokenI.H:615
longDoubleScalar longDoubleScalarToken() const
Definition: tokenI.H:746
const variable & variableToken() const
Definition: tokenI.H:383
bool isUnsignedInteger32() const
Definition: tokenI.H:544
bool isNumber() const
Definition: tokenI.H:789
bool isPunctuation() const
Definition: tokenI.H:324
punctuationToken punctuationToken_
Definition: token.H:257
bool isDoubleScalar() const
Definition: tokenI.H:722
tokenType
Enumeration defining the types of token.
Definition: token.H:80
@ ERROR
Definition: token.H:98
@ VARIABLE
Definition: token.H:86
@ WORD
Definition: token.H:84
@ UNSIGNED_INTEGER_32
Definition: token.H:91
@ UNDEFINED
Definition: token.H:81
@ COMPOUND
Definition: token.H:96
@ FLOAT_SCALAR
Definition: token.H:93
@ INTEGER_64
Definition: token.H:90
@ DOUBLE_SCALAR
Definition: token.H:94
@ LONG_DOUBLE_SCALAR
Definition: token.H:95
@ VERBATIMSTRING
Definition: token.H:88
@ FUNCTIONNAME
Definition: token.H:85
@ UNSIGNED_INTEGER_64
Definition: token.H:92
@ INTEGER_32
Definition: token.H:89
@ STRING
Definition: token.H:87
@ PUNCTUATION
Definition: token.H:83
bool isLongDoubleScalar() const
Definition: tokenI.H:741
verbatimString * verbatimStringTokenPtr_
Definition: token.H:262
int32_t integer32Token() const
Definition: tokenI.H:485
compound * compoundTokenPtr_
Definition: token.H:270
bool isVerbatimString() const
Definition: tokenI.H:414
functionName * functionNameTokenPtr_
Definition: token.H:259
floatScalar floatScalarToken_
Definition: token.H:267
const functionName & functionNameToken() const
Definition: tokenI.H:365
variable * variableTokenPtr_
Definition: token.H:260
floatScalar floatScalarToken() const
Definition: tokenI.H:708
punctuationToken
Standard punctuation tokens.
Definition: token.H:103
bool isULabel() const
Definition: tokenI.H:659
const string & stringToken() const
Definition: tokenI.H:401
bool isAnyString() const
Definition: tokenI.H:432
punctuationToken pToken() const
Definition: tokenI.H:329
void setBad()
Set bad.
Definition: tokenI.H:858
bool isUnsignedInteger64() const
Definition: tokenI.H:581
label labelToken() const
Definition: tokenI.H:634
uint32_t unsignedInteger32Token() const
Definition: tokenI.H:556
bool isVariable() const
Definition: tokenI.H:378
bool isInteger64() const
Definition: tokenI.H:510
void operator=(const token &)
Definition: tokenI.H:867
int64_t integer64Token() const
Definition: tokenI.H:519
string * stringTokenPtr_
Definition: token.H:261
bool isScalar() const
Definition: tokenI.H:760
tokenType type() const
Definition: tokenI.H:299
const string & anyStringToken() const
Definition: tokenI.H:444
bool isFunctionName() const
Definition: tokenI.H:360
bool isInteger32() const
Definition: tokenI.H:473
int64_t integer64Token_
Definition: token.H:264
bool isCompound() const
Definition: tokenI.H:828
bool error() const
Definition: tokenI.H:319
int32_t integer32Token_
Definition: token.H:263
const compound & compoundToken() const
Definition: tokenI.H:833
bool isFloatScalar() const
Definition: tokenI.H:703
bool undefined() const
Definition: tokenI.H:314
uLabel uLabelToken() const
Definition: tokenI.H:678
bool operator!=(const token &) const
Definition: tokenI.H:1200
uint64_t unsignedInteger64Token() const
Definition: tokenI.H:590
doubleScalar doubleScalarToken() const
Definition: tokenI.H:727
bool isString() const
Definition: tokenI.H:396
bool good() const
Definition: tokenI.H:309
doubleScalar doubleScalarToken_
Definition: token.H:268
bool isWord() const
Definition: tokenI.H:342
word * wordTokenPtr_
Definition: token.H:258
token()
Construct null.
Definition: tokenI.H:75
const word & wordToken() const
Definition: tokenI.H:347
scalar scalarToken() const
Definition: tokenI.H:768
const verbatimString & verbatimStringToken() const
Definition: tokenI.H:419
~token()
Destructor.
Definition: tokenI.H:291
uint32_t unsignedInteger32Token_
Definition: token.H:265
bool operator==(const token &) const
Definition: tokenI.H:1067
uint64_t unsignedInteger64Token_
Definition: token.H:266
label lineNumber() const
Definition: tokenI.H:847
scalar number() const
Definition: tokenI.H:799
longDoubleScalar * longDoubleScalarTokenPtr_
Definition: token.H:269
A variable is a word with support for additional characters, in particular '$' and '/'.
Definition: variable.H:61
static const variable null
An empty variable.
Definition: variable.H:76
static const char *const typeName
Definition: variable.H:72
A class for handling verbatimStrings, derived from string.
static const verbatimString null
An empty verbatimString.
static const char *const typeName
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
static const char *const typeName
Definition: word.H:74
static bool isScalar[maxNames]
Definition: globalFoam.H:27
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
tUEqn clear()
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
static const uLabel uLabelMax
Definition: uLabel.H:61
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
uintWM_LABEL_SIZE_t uLabel
A uLabel is an uint32_t or uint64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: uLabel.H:59
static const label labelMax
Definition: label.H:62
long double longDoubleScalar
Lang double precision floating point scalar type.
static const label labelMin
Definition: label.H:61
volScalarField & p