-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue.cpp
More file actions
63 lines (59 loc) · 1.18 KB
/
Copy pathvalue.cpp
File metadata and controls
63 lines (59 loc) · 1.18 KB
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
#include "value.h"
namespace louis {
namespace value {
// 基本数据类型转Value
Value::Value(int value) {
*this = value;
}
Value::Value(double value) {
*this = value;
}
Value::Value(const char* value) {
*this = value;
}
Value::Value(const string& value) {
*this = value;
}
Value::Value(bool value) {
*this = value;
}
// 重载赋值运算符
Value& Value::operator=(int value) {
stringstream ss;
ss << value;
value_ = ss.str();
return *this;
}
Value& Value::operator=(double value) {
stringstream ss;
ss << value;
value_ = ss.str();
return *this;
}
Value& Value::operator=(const char* value) {
value_ = value;
return *this;
}
Value& Value::operator=(const string& value) {
value_ = value;
return *this;
}
Value& Value::operator=(bool value) {
value_ = value ? "true" : "false";
return *this;
}
// Value转基本数据类型
Value::operator int() const {
return std::atoi(value_.c_str());
}
Value::operator double() const {
return std::atof(value_.c_str());
}
Value::operator string() const {
return value_;
}
Value::operator bool() const{
return value_ == "true";
}
} // namespace value
} // namespace louis