libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
Logical.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef DEVICEPARAMETERLOGICAL_H_
32 #define DEVICEPARAMETERLOGICAL_H_
33 
34 #include <string>
35 #include <memory>
36 #include <unordered_map>
37 #include <vector>
38 
39 namespace rapidxml
40 {
41 class xml_node;
42 }
43 
44 using namespace rapidxml;
45 
46 namespace BaseLib
47 {
48 
49 class SharedObjects;
50 class Variable;
51 
52 namespace DeviceDescription
53 {
54 
55 class LogicalAction;
56 class LogicalArray;
57 class LogicalBoolean;
58 class LogicalDecimal;
59 class LogicalEnumeration;
60 class LogicalInteger;
61 class LogicalInteger64;
62 class LogicalString;
64 
65 typedef std::shared_ptr<LogicalAction> PLogicalAction;
66 typedef std::shared_ptr<LogicalArray> PLogicalArray;
67 typedef std::shared_ptr<LogicalBoolean> PLogicalBoolean;
68 typedef std::shared_ptr<LogicalDecimal> PLogicalDecimal;
69 typedef std::shared_ptr<LogicalEnumeration> PLogicalEnumeration;
70 typedef std::shared_ptr<LogicalInteger> PLogicalInteger;
71 typedef std::shared_ptr<LogicalInteger64> PLogicalInteger64;
72 typedef std::shared_ptr<LogicalString> PLogicalString;
73 typedef std::shared_ptr<LogicalStruct> PLogicalStruct;
74 
75 
77 {
78 public:
79  std::string id;
80  bool indexDefined = false;
81  int32_t index = -1;
82 
84  EnumerationValue(std::string id, int32_t index) { this->id = id; this->index = index; indexDefined = true; }
86  virtual ~EnumerationValue() {}
87 };
88 
89 class ILogical
90 {
91 public:
92  struct Type
93  {
94  enum Enum { none = 0x00, tInteger = 0x01, tBoolean = 0x02, tString = 0x03, tFloat = 0x04, tEnum = 0x20, tAction = 0x30, tInteger64 = 0xD1, tArray = 0x100, tStruct = 0x101 };
95  };
96 
98  ILogical(BaseLib::SharedObjects* baseLib, xml_node* node);
99  virtual ~ILogical() {}
100  virtual std::shared_ptr<Variable> getSetToValueOnPairing() = 0;
101  virtual std::shared_ptr<Variable> getDefaultValue() = 0;
102 
103  Type::Enum type = Type::none;
104  bool defaultValueExists = false;
105  bool setToValueOnPairingExists = false;
106 protected:
107  BaseLib::SharedObjects* _bl = nullptr;
108 };
109 
110 class LogicalInteger : public ILogical
111 {
112 public:
113  int32_t minimumValue = -2147483648;
114  int32_t maximumValue = 2147483647;
115  int32_t defaultValue = 0;
116  int32_t setToValueOnPairing = 0;
117  std::unordered_map<std::string, int32_t> specialValuesStringMap;
118  std::unordered_map<int32_t, std::string> specialValuesIntegerMap;
119 
122  virtual ~LogicalInteger() {}
123  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
124  virtual std::shared_ptr<Variable> getDefaultValue();
125 };
126 
128 {
129 public:
130  int64_t minimumValue = -9223372036854775807ll - 1;
131  int64_t maximumValue = 9223372036854775807ll;
132  int64_t defaultValue = 0;
133  int64_t setToValueOnPairing = 0;
134  std::unordered_map<std::string, int64_t> specialValuesStringMap;
135  std::unordered_map<int64_t, std::string> specialValuesIntegerMap;
136 
139  virtual ~LogicalInteger64() {}
140  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
141  virtual std::shared_ptr<Variable> getDefaultValue();
142 };
143 
144 class LogicalDecimal : public ILogical
145 {
146 public:
147  double minimumValue = -3.40282347e+38f;
148  double maximumValue = 3.40282347e+38f;
149  double defaultValue = 0;
150  double setToValueOnPairing = 0;
151  std::unordered_map<std::string, double> specialValuesStringMap;
152  std::unordered_map<double, std::string> specialValuesFloatMap;
153 
156  virtual ~LogicalDecimal() {}
157  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
158  virtual std::shared_ptr<Variable> getDefaultValue();
159 };
160 
162 {
163 public:
164  int32_t minimumValue = 0;
165  int32_t maximumValue = 0;
166  int32_t defaultValue = 0;
167  int32_t setToValueOnPairing = 0;
168 
171  virtual ~LogicalEnumeration() {}
172  std::vector<EnumerationValue> values;
173  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
174  virtual std::shared_ptr<Variable> getDefaultValue();
175 };
176 
177 class LogicalBoolean : public ILogical
178 {
179 public:
180  bool defaultValue = false;
181  bool setToValueOnPairing = false;
182 
185  virtual ~LogicalBoolean() {}
186  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
187  virtual std::shared_ptr<Variable> getDefaultValue();
188 };
189 
190 class LogicalString : public ILogical
191 {
192 public:
193  std::string defaultValue;
194  std::string setToValueOnPairing;
195 
198  virtual ~LogicalString() {}
199  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
200  virtual std::shared_ptr<Variable> getDefaultValue();
201 };
202 
203 class LogicalAction : public ILogical
204 {
205 public:
206  bool defaultValue = false;
207  bool setToValueOnPairing = false;
208 
211  virtual ~LogicalAction() {}
212  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
213  virtual std::shared_ptr<Variable> getDefaultValue();
214 };
215 
216 class LogicalArray : public ILogical
217 {
218 public:
221  virtual ~LogicalArray() {}
222  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
223  virtual std::shared_ptr<Variable> getDefaultValue();
224 };
225 
226 class LogicalStruct : public ILogical
227 {
228 public:
231  virtual ~LogicalStruct() {}
232  virtual std::shared_ptr<Variable> getSetToValueOnPairing();
233  virtual std::shared_ptr<Variable> getDefaultValue();
234 };
235 
236 }
237 }
238 
239 #endif
virtual ~LogicalInteger64()
Definition: Logical.h:139
std::shared_ptr< LogicalBoolean > PLogicalBoolean
Definition: Logical.h:67
virtual ~LogicalArray()
Definition: Logical.h:221
virtual ~LogicalAction()
Definition: Logical.h:211
This is the base library main class.
Definition: BaseLib.h:95
std::unordered_map< std::string, double > specialValuesStringMap
Definition: Logical.h:151
virtual ~LogicalDecimal()
Definition: Logical.h:156
int32_t id
Definition: FileDescriptorManager.h:53
std::shared_ptr< LogicalInteger > PLogicalInteger
Definition: Logical.h:70
std::string id
Definition: Logical.h:79
Definition: BaseLib.cpp:34
virtual ~LogicalInteger()
Definition: Logical.h:122
PVariable maximumValue
Definition: UiElements.h:220
std::shared_ptr< LogicalDecimal > PLogicalDecimal
Definition: Logical.h:68
std::shared_ptr< LogicalArray > PLogicalArray
Definition: Logical.h:66
virtual ~LogicalEnumeration()
Definition: Logical.h:171
virtual ~LogicalBoolean()
Definition: Logical.h:185
std::shared_ptr< LogicalInteger64 > PLogicalInteger64
Definition: Logical.h:71
std::string defaultValue
Definition: Logical.h:193
virtual ~EnumerationValue()
Definition: Logical.h:86
virtual ~LogicalString()
Definition: Logical.h:198
std::shared_ptr< LogicalAction > PLogicalAction
Definition: Logical.h:63
std::shared_ptr< LogicalStruct > PLogicalStruct
Definition: Logical.h:73
PVariable minimumValue
Definition: UiElements.h:219
std::unordered_map< int32_t, std::string > specialValuesIntegerMap
Definition: Logical.h:118
virtual ~LogicalStruct()
Definition: Logical.h:231
virtual ~ILogical()
Definition: Logical.h:99
Definition: Logical.h:89
std::shared_ptr< LogicalEnumeration > PLogicalEnumeration
Definition: Logical.h:69
std::string setToValueOnPairing
Definition: Logical.h:194
std::unordered_map< int64_t, std::string > specialValuesIntegerMap
Definition: Logical.h:135
std::unordered_map< double, std::string > specialValuesFloatMap
Definition: Logical.h:152
std::shared_ptr< LogicalString > PLogicalString
Definition: Logical.h:72
std::vector< EnumerationValue > values
Definition: Logical.h:172
std::unordered_map< std::string, int32_t > specialValuesStringMap
Definition: Logical.h:117
Class representing a node of XML document.
Definition: rapidxml.h:539
Definition: BinaryPayload.h:38
EnumerationValue()
Definition: Logical.h:83
EnumerationValue(std::string id, int32_t index)
Definition: Logical.h:84
std::unordered_map< std::string, int64_t > specialValuesStringMap
Definition: Logical.h:134