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 #include "arts.h" 00019 #include "messages.h" 00020 #include "token.h" 00021 00026 String TokValTypeName[7] = {"String", "Index", "Numeric", 00027 "ArrayOfString", "ArrayOfIndex", "Vector", 00028 "undefined"}; 00029 00030 00031 // Conversion functions to read TokVal for the 6 different types: 00032 00033 TokVal::operator String() const { 00034 assert (mtype == String_t); 00035 return ms; 00036 } 00037 00038 TokVal::operator Index() const { 00039 assert (mtype == Index_t); 00040 return mn; 00041 } 00042 00043 TokVal::operator Numeric() const { 00044 assert (mtype == Numeric_t); 00045 return mx; 00046 } 00047 00048 00049 TokVal::operator ArrayOfString() const { 00050 assert (mtype == Array_String_t); 00051 return msv; 00052 } 00053 00054 TokVal::operator ArrayOfIndex() const { 00055 assert (mtype == Array_Index_t); 00056 return mnv; 00057 } 00058 00059 TokVal::operator Vector() const { 00060 assert (mtype == Vector_t); 00061 return mxv; 00062 } 00063 00064 00065 ostream& operator<<(ostream& os, const TokVal& a) 00066 { 00067 switch (a.mtype) 00068 { 00069 case String_t: 00070 os << a.ms; 00071 break; 00072 case Index_t: 00073 os << a.mn; 00074 break; 00075 case Numeric_t: 00076 os << a.mx; 00077 break; 00078 case Array_String_t: 00079 os << a.msv; 00080 break; 00081 case Array_Index_t: 00082 os << a.mnv; 00083 break; 00084 case Vector_t: 00085 os << a.mxv; 00086 break; 00087 default: 00088 out0 << "Undefined token type.\n"; 00089 exit(1); 00090 } 00091 return os; 00092 } 00093 00094 00095 // main() 00096 // { 00097 // String a("Test"); 00098 // TokVal tv(a); 00099 00100 // String b=tv; 00101 // cout << b << '\n'; 00102 // Numeric c = 3.8; 00103 // TokVal tvtv(c); 00104 // tv = tvtv; 00105 // Numeric d = tv; 00106 // cout << d << '\n'; 00107 // b = tv; // should cause an error because of wrong type 00108 // }