BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
Incomplete.h
1 #pragma once
2 
3 namespace BeeeOn {
4 
10 template <typename T, typename CompleteTest, typename Complete>
11 class Incomplete {
12 public:
18  {
19  }
20 
21  Incomplete(const T &value):
22  m_value(value)
23  {
24  }
25 
26  virtual ~Incomplete()
27  {
28  }
29 
35  bool isComplete() const
36  {
37  CompleteTest test;
38  return test(m_value);
39  }
40 
41  T deriveComplete(const Complete &complete) const
42  {
43  if (isComplete())
44  return value();
45 
46  return complete(value());
47  }
48 
49  Incomplete &completeSelf(const Complete &complete)
50  {
51  return assign(deriveComplete(complete));
52  }
53 
54  T &value()
55  {
56  return m_value;
57  }
58 
59  const T &value() const
60  {
61  return m_value;
62  }
63 
64  operator T &()
65  {
66  return value();
67  }
68 
69  operator const T &() const
70  {
71  return value();
72  }
73 
74  Incomplete &assign(const T &value)
75  {
76  m_value = value;
77  return *this;
78  }
79 
80  Incomplete &assign(const Incomplete &other)
81  {
82  return assign(other.value());
83  }
84 
85  Incomplete &operator =(const Incomplete &other)
86  {
87  return assign(other);
88  }
89 
90  Incomplete &operator =(const T &other)
91  {
92  return assign(other);
93  }
94 
95  bool operator ==(const Incomplete &other) const
96  {
97  if (isComplete() != other.isComplete())
98  return false;
99 
100  return other.value() == value();
101  }
102 
103  bool operator ==(const T &other) const
104  {
105  if (!isComplete())
106  return false;
107 
108  return value() == other;
109  }
110 
111  bool operator !=(const Incomplete &other) const
112  {
113  if (isComplete() != other.isComplete())
114  return true;
115 
116  return other.value() != value();
117  }
118 
119  bool operator !=(const T &other) const
120  {
121  if (!isComplete())
122  return true;
123 
124  return value() != other;
125  }
126 
127  bool operator <(const Incomplete &other) const
128  {
129  if (isComplete() == other.isComplete())
130  return value() < other.value();
131 
132  if (!isComplete() && other.isComplete())
133  return true;
134 
135  return false;
136  }
137 
138  bool operator <(const T &other) const
139  {
140  if (isComplete())
141  return value() < other;
142 
143  return true;
144  }
145 
146  bool operator >(const Incomplete &other) const
147  {
148  return !(*this == other) && !(*this < other);
149  }
150 
151 private:
152  T m_value;
153 };
154 
155 }
bool isComplete() const
Definition: Incomplete.h:35
Definition: Incomplete.h:11
Incomplete()
Definition: Incomplete.h:17