-
Notifications
You must be signed in to change notification settings - Fork 0
/
ircstackentry.cpp
88 lines (82 loc) · 1.35 KB
/
ircstackentry.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "ircstack.h"
stackentry::stackentry(std::string st)
{
size_t found_int0;
size_t found_double0;
found_int0 = st.find_first_not_of("0");
found_double0 = st.find_first_not_of("0.");
if(found_int0 == std::string::npos)
{
mytype=S_INT;
i=0;
}
else if(found_double0 == std::string::npos)
{
mytype=S_FLOAT;
f=0.0;
}
else if((i=atoi(st.c_str())) != 0)
{
mytype=S_INT;
}
else if(f=atof(st.c_str()))
{
mytype=S_FLOAT;
}
else
{
mytype=S_STRING;
s=std::string(st);
}
}
stackentry::stackentry(stackentry* old) //copy constructor
{
mytype = old->mytype;
f = old->f;
i = old->i;
s = old->s;
o = old->o;
}
stackentry::stackentry(int x)
{
mytype=S_INT;
i=x;
}
stackentry::stackentry(float y)
{
mytype=S_FLOAT;
f=y;
}
std::string stackentry::print()
{
std::stringstream ss;
std::cout << mytype << std::endl;
switch(mytype)
{
case S_STRING:
ss << s;
return ss.str();
break;
case S_INT:
ss << i;
return ss.str();
break;
case S_FLOAT:
ss << f;
return ss.str();
break;
}
}
bool stackentry::isNumber()
{
return (mytype==S_INT || mytype==S_FLOAT);
}
float stackentry::floatVal()
{
if(mytype == S_FLOAT)
return f;
if(mytype == S_INT)
return (float)i;
else
return 0.0f;
}