-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValue.h
More file actions
63 lines (54 loc) · 1.13 KB
/
Value.h
File metadata and controls
63 lines (54 loc) · 1.13 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
#pragma once
#include<string>
using namespace std;
class Value{
public:
string type; // int, float, strinf, bool sau error
int i;
float f;
bool b;
string s;
Value(){
type = "error";
i=0; f=0.0; b=false; s="";
}
//constructori
static Value makeInt(int x){
Value v;
v.type= "int";
v.i=x;
return v;
}
static Value makeFloat(float x){
Value v;
v.type="float";
v.f=x;
return v;
}
static Value makeBool(bool x){
Value v;
v.type="bool";
v.b=x;
return v;
}
static Value makeString(const string& x){
Value v;
v.type="string";
v.s=x;
return v;
}
static Value def( const string &a){
if( a == "int") return makeInt(0);
if ( a== "float") return makeFloat(0);
if( a == "bool") return makeBool(false);
if(a == "string") return makeString("");
return Value(); //err
}
string to_str() const{
if( type== "int") return to_string(i);
if ( type == "float") return to_string(f);
if( type== "bool") return b ? "true":"false";
if( type == "string") return s;
return "error";
}
};