Completed
Push — master ( 57e7bf...8a74a7 )
by P.R.
01:36
created

DataType   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %
Metric Value
wmc 8
dl 0
loc 91
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A is_defined() 0 8 1
A is_constant() 0 8 1
A dereference() 0 8 1
A get_value() 0 8 1
A get_type_id() 0 8 1
A is_true() 0 8 1
A is_scalar() 0 8 1
A debug() 0 10 1
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9
import abc
10
11
12
class DataType:
13
    """
14
    Abstract parent class for all data types.
15
    """
16
17
    # Constants for all data types.
18
    INT = 1
19
    STRING = 2
20
    ARRAY = 3
21
22
    # ------------------------------------------------------------------------------------------------------------------
23
    @abc.abstractmethod
24
    def debug(self, indent=0):
25
        """
26
        Returns a string for debugging.
27
28
        :param int indent: The indentation level.
29
30
        :rtype: str
31
        """
32
        raise NotImplementedError
33
34
    # ------------------------------------------------------------------------------------------------------------------
35
    @abc.abstractmethod
36
    def dereference(self):
37
        """
38
        Returns a clone of this data type.
39
40
        :rtype: DataType
41
        """
42
        raise NotImplementedError
43
44
    # ------------------------------------------------------------------------------------------------------------------
45
    @abc.abstractmethod
46
    def get_value(self):
47
        """
48
        Returns the underling value of this data type.
49
50
        :rtype: str|int
51
        """
52
        raise NotImplementedError
53
54
    # ------------------------------------------------------------------------------------------------------------------
55
    @abc.abstractmethod
56
    def get_type_id(self):
57
        """
58
        Returns the ID of this data type.
59
60
        :rtype: int
61
        """
62
        raise NotImplementedError
63
64
    # ------------------------------------------------------------------------------------------------------------------
65
    @abc.abstractmethod
66
    def is_constant(self):
67
        """
68
        Returns True if this data type is a constant. Returns False otherwise.
69
70
        :rtype: bool
71
        """
72
        raise NotImplementedError
73
74
    # ------------------------------------------------------------------------------------------------------------------
75
    @abc.abstractmethod
76
    def is_defined(self):
77
        """
78
        Returns True if this data type is defined, i.e. has a value. Returns False otherwise.
79
80
        :rtype: bool
81
        """
82
        raise NotImplementedError
83
84
    # ------------------------------------------------------------------------------------------------------------------
85
    @abc.abstractmethod
86
    def is_scalar(self):
87
        """
88
        Returns True if this data type is a scalar. Returns False otherwise.
89
90
        :rtype: bool
91
        """
92
        raise NotImplementedError
93
94
    # ------------------------------------------------------------------------------------------------------------------
95
    @abc.abstractmethod
96
    def is_true(self):
97
        """
98
        Returns True if this data type evaluates to True. Returns False otherwise.
99
100
        :rtype: bool
101
        """
102
        raise NotImplementedError
103
104
# ----------------------------------------------------------------------------------------------------------------------
105