1
|
1 |
|
from sdoc.sdoc1.data_type.DataType import DataType |
2
|
|
|
|
3
|
|
|
|
4
|
1 |
View Code Duplication |
class StringDataType(DataType): |
5
|
|
|
""" |
6
|
|
|
Class for string data types. |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
10
|
1 |
|
def __init__(self, value: str): |
11
|
|
|
""" |
12
|
|
|
Object constructor. |
13
|
|
|
|
14
|
|
|
:param str value: The value of this string constant. |
15
|
|
|
""" |
16
|
1 |
|
self._value: str = value |
17
|
1 |
|
""" |
18
|
|
|
The value of this constant integer. |
19
|
|
|
""" |
20
|
|
|
|
21
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
22
|
1 |
|
def debug(self, indent: int = 0) -> str: |
23
|
|
|
""" |
24
|
|
|
Returns a string for debugging. |
25
|
|
|
|
26
|
|
|
:param int indent: Unused. |
27
|
|
|
""" |
28
|
1 |
|
return "'" + self._value + "'" |
29
|
|
|
|
30
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
31
|
1 |
|
def dereference(self): |
32
|
|
|
""" |
33
|
|
|
Returns a clone of this string. |
34
|
|
|
|
35
|
|
|
:rtype: sdoc.sdoc1.data_type.StringDataType.StringDataType |
36
|
|
|
""" |
37
|
1 |
|
return StringDataType(self._value) |
38
|
|
|
|
39
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
40
|
1 |
|
def get_value(self) -> str: |
41
|
|
|
""" |
42
|
|
|
Returns the underling value of this data type. |
43
|
|
|
""" |
44
|
1 |
|
return self._value |
45
|
|
|
|
46
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
47
|
1 |
|
def get_type_id(self) -> int: |
48
|
|
|
""" |
49
|
|
|
Returns the ID of this data type. |
50
|
|
|
""" |
51
|
|
|
return DataType.STRING |
52
|
|
|
|
53
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
54
|
1 |
|
def is_constant(self) -> bool: |
55
|
|
|
""" |
56
|
|
|
Returns False always. |
57
|
|
|
""" |
58
|
|
|
return False |
59
|
|
|
|
60
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
61
|
1 |
|
def is_defined(self) -> bool: |
62
|
|
|
""" |
63
|
|
|
Returns True always. |
64
|
|
|
""" |
65
|
1 |
|
return True |
66
|
|
|
|
67
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
68
|
1 |
|
def is_scalar(self) -> bool: |
69
|
|
|
""" |
70
|
|
|
Returns True always. |
71
|
|
|
""" |
72
|
1 |
|
return True |
73
|
|
|
|
74
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
75
|
1 |
|
def is_true(self) -> bool: |
76
|
|
|
""" |
77
|
|
|
Returns True if this string is not empty. Returns False otherwise. |
78
|
|
|
""" |
79
|
|
|
return self._value != '' |
80
|
|
|
|
81
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
82
|
1 |
|
def __str__(self) -> str: |
83
|
|
|
""" |
84
|
|
|
Returns the string representation of the string constant. |
85
|
|
|
""" |
86
|
|
|
return self._value |
87
|
|
|
|
88
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
89
|
|
|
|