-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty_value.py
More file actions
60 lines (45 loc) · 1.59 KB
/
property_value.py
File metadata and controls
60 lines (45 loc) · 1.59 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
PV_TYPE_INT = "int"
PV_TYPE_BOOL = "bool"
PV_TYPE_STRING = "str"
class PropertyValue(object):
def __init__(self, data_type: str):
self.data_type = data_type
self.int_value = 0
self.bool_value = False
self.string_value = ""
def get_int_value(self) -> int:
if self.is_int():
return self.int_value
else:
print("warning: calling get_int_value, but data type is '%s'" % self.data_type)
return 0
def get_bool_value(self) -> bool:
if self.is_bool():
return self.bool_value
else:
print("warning: calling get_bool_value, but data type is '%s'" % self.data_type)
return False
def get_string_value(self) -> str:
if self.is_string():
return self.string_value
else:
print("warning: calling get_string_value, but data type is '%s'" % self.data_type)
return ""
def is_int(self) -> bool:
return self.data_type == PV_TYPE_INT
def is_bool(self) -> bool:
return self.data_type == PV_TYPE_BOOL
def is_string(self) -> bool:
return self.data_type == PV_TYPE_STRING
def new_int_property_value(int_value: int) -> PropertyValue:
pv = PropertyValue(PV_TYPE_INT)
pv.int_value = int_value
return pv
def new_bool_property_value(bool_value: bool) -> PropertyValue:
pv = PropertyValue(PV_TYPE_BOOL)
pv.bool_value = bool_value
return pv
def new_string_property_value(str_value: str) -> PropertyValue:
pv = PropertyValue(PV_TYPE_STRING)
pv.string_value = str_value
return pv