-
Notifications
You must be signed in to change notification settings - Fork 2
/
dator.h
101 lines (87 loc) · 2.36 KB
/
dator.h
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
#ifndef DATOR_H_INCLUDED
#define DATOR_H_INCLUDED
#include "mmanager.h"
class BaseDator : public IMMObject
{
protected:
BaseDator(){}
BaseDator(BaseDator &b){(*this)=b;}
public:
virtual BaseDator &operator =(std::string &s)=0;
virtual BaseDator &operator +=(std::string &s)=0;
virtual BaseDator &operator -=(std::string &s)=0;
virtual bool operator ==(std::string &s)=0;
virtual bool operator !=(std::string &s)=0;
virtual bool hasMultipleValues()=0;
virtual operator std::string()=0;
};
template<class T>
class Dator : public BaseDator
{
protected:
T& target;
T toVal(std::string &s)
{
std::stringstream str;
str.unsetf(std::ios::skipws);
str<<s;
T res;
str>>res;
return res;
}
std::string toString(T &val)
{
std::stringstream str;
str.unsetf(std::ios::skipws);
str<<val;
std::string res;
str>>res;
return res;
}
public:
Dator(T& t) : target(t) {}
BaseDator &operator =(std::string &s) { target=toVal(s); return *this; }
BaseDator &operator +=(std::string &s) { target+=toVal(s); return *this; }
BaseDator &operator -=(std::string &s) { target-=toVal(s); return *this; }
bool operator ==(std::string &s) { return (s==(std::string)(*this)); }
bool operator !=(std::string &s) { return (s!=(std::string)(*this)); }
operator std::string() { return toString(target); }
bool hasMultipleValues() { return false; }
AUTO_SIZE;
};
template<class T>
class ListDator : public BaseDator
{
protected:
std::list<T> &values;
T toVal(std::string &s)
{
std::stringstream str;
str.unsetf(std::ios::skipws);
str<<s;
T res;
str>>res;
return res;
}
std::string toString(T &val)
{
std::stringstream str;
str.unsetf(std::ios::skipws);
str<<val;
std::string res;
str>>res;
return res;
}
public:
ListDator(std::list<T> &v) : values(v) { }
BaseDator &operator =(std::string &s) { values.clear(); values.push_back(toVal(s)); return *this; }
BaseDator &operator +=(std::string &s) { values.push_back(toVal(s)); return *this; }
BaseDator &operator -=(std::string &s) { values.remove(toVal(s)); return *this; }
bool operator ==(std::string &s) { return (std::find(values.begin(),values.end(),toVal(s))!=values.end()); }
bool operator !=(std::string &s) { return !((*this)==s); }
operator std::string() { return toString(values.back()); }
operator std::list<T>&() { return values; }
bool hasMultipleValues(){return true;}
AUTO_SIZE;
};
#endif