-
Notifications
You must be signed in to change notification settings - Fork 1
/
generic.cpp
83 lines (64 loc) · 1.12 KB
/
generic.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
#include <cstdlib>
#include <cassert>
#include <string>
#include <sstream>
#include <iostream>
#include "generic.hpp"
generic::generic(std::string const& value) {
value_=value;
}
generic::generic(const char* c) {
value_=c;
}
generic::generic(double d) {
std::stringstream s;
s<<d;
value_=s.str();
}
generic::generic(unsigned long d) {
std::stringstream s;
s<<d;
value_=s.str();
}
generic::generic(long d) {
std::stringstream s;
s<<d;
value_=s.str();
}
generic::generic(generic const& other) {
value_=other.value_;
}
generic& generic::operator=(generic const& other) {
value_=other.value_;
return *this;
}
generic& generic::operator=(double i) {
std::stringstream s;
s << i;
value_ = s.str();
return *this;
}
generic& generic::operator=(std::string const& s)
{
value_=s;
return *this;
}
generic::operator std::string() const
{
return value_;
}
generic::operator double() const
{
return atof(value_.c_str());
}
generic::operator long() const
{
return atol(value_.c_str());
}
generic::operator unsigned long() const
{
std::stringstream s(value_);
unsigned long v;
s>>v;
return v;
}