-
Notifications
You must be signed in to change notification settings - Fork 1
/
winxedxx_scalar.cxx
147 lines (113 loc) · 2.39 KB
/
winxedxx_scalar.cxx
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// winxedxx_scalar.cxx
// (C) 2011-2012 Julián Albo
// Scalar types: Integer, Float, String.
#include "winxedxx_types.h"
#include "winxedxx_object.h"
#include "winxedxx_default.h"
#include "winxedxx_integer.h"
#include <iostream>
#include <sstream>
namespace WinxedXX
{
//*************************************************************
WxxInteger::WxxInteger(int value) : WxxDefault("Integer")
{
i = value;
}
void WxxInteger::init_pmc(const WxxObjectPtr &arg)
{
i = arg.get_integer();
}
std::string WxxInteger::class_name() const
{
return "Integer";
}
int WxxInteger::get_integer() { return i; };
double WxxInteger::get_number() { return i; }
std::string WxxInteger::get_string()
{
std::ostringstream oss;
oss << i;
return oss.str();
}
int WxxInteger::is_equal(const WxxObject &to)
{
if (const WxxInteger *fromint = dynamic_cast<const WxxInteger *>(& to))
return i == fromint->i;
else
return false;
}
WxxObject & WxxInteger::set(int value)
{
i = value;
return *this;
}
WxxObject & WxxInteger::set(double value)
{
i = value;
return *this;
}
void WxxInteger::increment()
{
++i;
}
void WxxInteger::decrement()
{
--i;
}
WxxObjectPtr WxxInteger::add(const WxxObjectPtr &value)
{
return new WxxInteger(i + int(value));
}
WxxObjectPtr WxxInteger::sub(const WxxObjectPtr &value)
{
return new WxxInteger(i - int(value));
}
//*************************************************************
WxxFloat::WxxFloat(double value) : WxxDefault("Float")
{
n = value;
}
std::string WxxFloat::class_name() const
{
return "Float";
}
int WxxFloat::get_integer() { return n; };
double WxxFloat::get_number() { return n; }
std::string WxxFloat::get_string()
{
std::ostringstream oss;
oss << n;
return oss.str();
}
WxxObject & WxxFloat::set(int value)
{
n = value;
return *this;
}
WxxObject & WxxFloat::set(double value)
{
n = value;
return *this;
}
//*************************************************************
WxxString::WxxString(std::string value) : WxxDefault("String")
{
str = value;
}
std::string WxxString::class_name() const
{
return "String";
}
std::string WxxString::get_string() { return str; }
WxxObject & WxxString::set(const std::string &s)
{
str = s;
return *this;
}
WxxObjectPtr WxxString::get_iter()
{
return WxxObjectPtr(new WxxStringIterator(str));
}
} // namespace WinxedXX
// End