ARTS  1.0.222
token.cc
Go to the documentation of this file.
1 /* Copyright (C) 2000, 2001 Stefan Buehler <sbuehler@uni-bremen.de>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
18 #include "arts.h"
19 #include "messages.h"
20 #include "token.h"
21 
26 String TokValTypeName[7] = {"String", "Index", "Numeric",
27  "ArrayOfString", "ArrayOfIndex", "Vector",
28  "undefined"};
29 
30 
31 // Conversion functions to read TokVal for the 6 different types:
32 
33 TokVal::operator String() const {
34  assert (mtype == String_t);
35  return ms;
36 }
37 
38 TokVal::operator Index() const {
39  assert (mtype == Index_t);
40  return mn;
41 }
42 
43 TokVal::operator Numeric() const {
44  assert (mtype == Numeric_t);
45  return mx;
46 }
47 
48 
49 TokVal::operator ArrayOfString() const {
50  assert (mtype == Array_String_t);
51  return msv;
52 }
53 
54 TokVal::operator ArrayOfIndex() const {
55  assert (mtype == Array_Index_t);
56  return mnv;
57 }
58 
59 TokVal::operator Vector() const {
60  assert (mtype == Vector_t);
61  return mxv;
62 }
63 
64 
65 ostream& operator<<(ostream& os, const TokVal& a)
66 {
67  switch (a.mtype)
68  {
69  case String_t:
70  os << a.ms;
71  break;
72  case Index_t:
73  os << a.mn;
74  break;
75  case Numeric_t:
76  os << a.mx;
77  break;
78  case Array_String_t:
79  os << a.msv;
80  break;
81  case Array_Index_t:
82  os << a.mnv;
83  break;
84  case Vector_t:
85  os << a.mxv;
86  break;
87  default:
88  out0 << "Undefined token type.\n";
89  exit(1);
90  }
91  return os;
92 }
93 
94 
95 // main()
96 // {
97 // String a("Test");
98 // TokVal tv(a);
99 
100 // String b=tv;
101 // cout << b << '\n';
102 // Numeric c = 3.8;
103 // TokVal tvtv(c);
104 // tv = tvtv;
105 // Numeric d = tv;
106 // cout << d << '\n';
107 // b = tv; // should cause an error because of wrong type
108 // }
TokVal
This stores arbitrary token values and remembers the type.
Definition: token.h:33
operator<<
ostream & operator<<(ostream &os, const TokVal &a)
Definition: token.cc:65
Array_Index_t
@ Array_Index_t
Definition: token.h:28
out0
Out0 out0
Level 0 output stream.
Definition: messages.cc:50
Vector_t
@ Vector_t
Definition: token.h:28
ArrayOfIndex
Array< Index > ArrayOfIndex
An array of Index.
Definition: arts.h:162
Index_t
@ Index_t
Definition: token.h:27
String_t
@ String_t
Definition: token.h:27
TokVal::mnv
ArrayOfIndex mnv
Definition: token.h:108
messages.h
Declarations having to do with the four output streams.
my_basic_string< char >
ArrayOfString
Array< String > ArrayOfString
An array of Strings.
Definition: mystring.h:285
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: arts.h:147
Numeric_t
@ Numeric_t
Definition: token.h:27
TokVal::ms
String ms
Definition: token.h:104
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: arts.h:153
TokVal::msv
ArrayOfString msv
Definition: token.h:107
String
my_basic_string< char > String
The String type for ARTS.
Definition: mystring.h:281
TokVal::mxv
Vector mxv
Definition: token.h:109
TokValTypeName
String TokValTypeName[7]
The name of the type associated with the different tokens.
Definition: token.cc:26
Array_String_t
@ Array_String_t
Definition: token.h:28
TokVal::mx
Numeric mx
Definition: token.h:106
TokVal::mtype
TokValType mtype
Definition: token.h:103
Vector
The Vector class.
Definition: matpackI.h:389
token.h
arts.h
The global header file for ARTS.
TokVal::mn
Index mn
Definition: token.h:105