00001 /* Copyright (C) 2000, 2001 Stefan Buehler <sbuehler@uni-bremen.de> 00002 00003 This program is free software; you can redistribute it and/or modify it 00004 under the terms of the GNU General Public License as published by the 00005 Free Software Foundation; either version 2, or (at your option) any 00006 later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00016 USA. */ 00017 00018 #ifndef token_h 00019 #define token_h 00020 00021 #include "matpackI.h" 00022 #include "array.h" 00023 #include "mystring.h" 00024 00027 enum TokValType { String_t, Index_t, Numeric_t, 00028 Array_String_t, Array_Index_t, Vector_t, 00029 undefined_t }; 00030 00033 class TokVal { 00034 public: 00035 00037 TokVal() { 00038 mtype = undefined_t; 00039 } 00040 00042 TokVal(const char s[]) { 00043 mtype = String_t; 00044 ms = s; 00045 } 00046 00048 TokVal(const String& s) { 00049 mtype = String_t; 00050 ms = s; 00051 } 00052 00054 TokVal(Index n) { 00055 mtype = Index_t; 00056 mn = n; 00057 } 00058 00060 TokVal(Numeric x) { 00061 mtype = Numeric_t; 00062 mx = x; 00063 } 00064 00066 TokVal(ArrayOfString sv) : msv(sv) 00067 { 00068 mtype = Array_String_t; 00069 } 00070 00072 TokVal(ArrayOfIndex nv) : mnv(nv) 00073 { 00074 mtype = Array_Index_t; 00075 } 00076 00078 TokVal(Vector xv) : mxv(xv) 00079 { 00080 mtype = Vector_t; 00081 } 00082 00083 // Conversion functions to return TokVal for the 6 different types: 00084 00086 operator String() const; 00088 operator Index() const; 00090 operator Numeric() const; 00091 00093 operator ArrayOfString() const; 00095 operator ArrayOfIndex() const; 00097 operator Vector() const; 00098 00100 friend ostream& operator<<(ostream& os, const TokVal& a); 00101 00102 private: 00103 TokValType mtype; 00104 String ms; 00105 Index mn; 00106 Numeric mx; 00107 ArrayOfString msv; 00108 ArrayOfIndex mnv; 00109 Vector mxv; 00110 }; 00111 00112 00113 // typedef Array<TokValType> TokValTypeVector; 00114 // typedef Array<TokVal> TokValVector; 00115 00116 00117 00118 #endif // token_h