BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
ModuleType.h
1 #pragma once
2 
3 #include <set>
4 
5 #include "model/CustomTypeID.h"
6 #include "util/Enum.h"
7 
8 namespace BeeeOn {
9 
18 class ModuleType {
19 public:
20  struct AttributeEnum {
21  enum Raw {
41  };
42 
43  static EnumHelper<Raw>::ValueMap &valueMap();
44  };
45 
46  struct TypeEnum {
47  enum Raw {
76  TYPE_CO2 = 5,
81  TYPE_ENUM = 6,
86  TYPE_FIRE = 7,
125  TYPE_RSSI = 16,
182  TYPE_HEAT = 28,
186  TYPE_PM25 = 29,
191  };
192 
193  static EnumHelper<Raw>::ValueMap &valueMap();
194  };
195 
196  struct UnitEnum {
197  enum Raw {
266  };
267 
268  static EnumHelper<Raw>::ValueMap &valueMap();
269  };
270 
271  typedef Enum<TypeEnum> Type;
272  typedef Enum<AttributeEnum> Attribute;
273 
277  class Unit : public Enum<UnitEnum> {
278  public:
279  Unit(const UnitEnum::Raw &raw);
280 
284  bool isValid(double value) const;
285 
292  std::string symbol(bool plain = false) const;
293 
303  std::string format(double value, bool plain = false) const;
304  };
305 
306  ModuleType();
307  ModuleType(const Type &type);
308  ModuleType(const Type &type, const std::set<Attribute> &attributes);
309  ModuleType(const Type &type, const CustomTypeID &customID);
310  ModuleType(const Type &type, const CustomTypeID &customID, const std::set<Attribute> &attributes);
311 
316  Unit baseUnit() const;
317 
318  void setType(const Type &type);
319  Type type() const;
320 
321  void setAttributes(const std::set<Attribute> &attributes);
322  std::set<Attribute> attributes() const;
323 
324  bool isControllable() const;
325 
326  void setCustomTypeID(CustomTypeID id);
327  CustomTypeID customTypeID() const;
328 
329  static ModuleType parse(std::string input);
330 
331 protected:
332  static bool hasCombination(
333  const std::set<Attribute> &attributes,
334  const std::set<Attribute> &check);
335  static void assureValidAttributes(
336  const std::set<Attribute> &attributes);
337 
338 private:
339  Type m_type;
340  std::set<Attribute> m_attributes;
341  CustomTypeID m_customID;
342 };
343 
344 }
Definition: ModuleType.h:261
Definition: ModuleType.h:230
Raw
Definition: ModuleType.h:21
Definition: ModuleType.h:76
bool isValid(double value) const
Definition: ModuleType.cpp:92
Definition: ModuleType.h:252
Definition: ModuleType.h:172
std::string format(double value, bool plain=false) const
Definition: ModuleType.cpp:169
Definition: ModuleType.h:222
Definition: ModuleType.h:244
Definition: ModuleType.h:20
Raw
Definition: ModuleType.h:47
Definition: ModuleType.h:182
Definition: ModuleType.h:46
Definition: ModuleType.h:207
Unit baseUnit() const
Definition: ModuleType.cpp:233
Representation of physical units.
Definition: ModuleType.h:277
Definition: ModuleType.h:217
Definition: ModuleType.h:256
Definition: ModuleType.h:248
Definition: ModuleType.h:186
Definition: ModuleType.h:177
std::string symbol(bool plain=false) const
Definition: ModuleType.cpp:131
Raw
Definition: ModuleType.h:197
Definition: ModuleType.h:235
Definition: ModuleType.h:149
Definition: ModuleType.h:18
Definition: ModuleType.h:81
Definition: ModuleType.h:153
Definition: CustomTypeID.h:11
Definition: ModuleType.h:226
Definition: ModuleType.h:103
Definition: ModuleType.h:136
Definition: ModuleType.h:157
Definition: ModuleType.h:265
Definition: ModuleType.h:196
Definition: ModuleType.h:113
Definition: ModuleType.h:125
Definition: ModuleType.h:212
std::map< Raw, std::string > ValueMap
Definition: Enum.h:20
Definition: ModuleType.h:86
Definition: ModuleType.h:202
Definition: ModuleType.h:240