Kaynağa Gözat

isSet, const for getters

Chris Mullins 8 yıl önce
ebeveyn
işleme
0c8cd7b79b
2 değiştirilmiş dosya ile 51 ekleme ve 23 silme
  1. 27 13
      lib/MiLightState/GroupState.cpp
  2. 24 10
      lib/MiLightState/GroupState.h

+ 27 - 13
lib/MiLightState/GroupState.cpp

@@ -33,32 +33,46 @@ bool GroupId::operator==(const GroupId &other) {
 }
 
 GroupState::GroupState() {
-  _on         = 0;
-  _brightness = 0;
-  _hue        = 0;
-  _saturation = 0;
-  _mode       = 0;
-  _bulbMode   = 0;
-  _kelvin     = 0;
+  _on              = 0;
+  _brightness      = 0;
+  _hue             = 0;
+  _saturation      = 0;
+  _mode            = 0;
+  _bulbMode        = 0;
+  _kelvin          = 0;
+  _isSetOn         = 0;
+  _isSetHue        = 0;
+  _isSetBrightness = 0;
+  _isSetSaturation = 0;
+  _isSetMode       = 0;
+  _isSetKelvin     = 0;
+  _isSetBulbMode   = 0;
 }
 
-bool GroupState::isOn() { return _on; }
+bool GroupState::isSetOn() const { return _isSetOn; }
+bool GroupState::isOn() const { return _on; }
 void GroupState::setOn(bool on) { _on = on; }
 
+bool GroupState::isSetBrightness() const { return _isSetBrightness; }
 uint8_t GroupState::getBrightness() const { return _brightness; }
 void GroupState::setBrightness(uint8_t brightness) { _brightness = brightness; }
 
-uint8_t GroupState::getHue() { return _hue; }
+bool GroupState::isSetHue() const { return _isSetHue; }
+uint8_t GroupState::getHue() const { return _hue; }
 void GroupState::setHue(uint8_t hue) { _hue = hue; }
 
-uint8_t GroupState::getSaturation() { return _saturation; }
+bool GroupState::isSetSaturation() const { return _isSetSaturation; }
+uint8_t GroupState::getSaturation() const { return _saturation; }
 void GroupState::setSaturation(uint8_t saturation) { _saturation = saturation; }
 
-uint8_t GroupState::getMode() { return _mode; }
+bool GroupState::isSetMode() const { return _isSetMode; }
+uint8_t GroupState::getMode() const { return _mode; }
 void GroupState::setMode(uint8_t mode) { _mode = mode; }
 
-uint8_t GroupState::getKelvin() { return _kelvin; }
+bool GroupState::isSetKelvin() const { return _isSetKelvin; }
+uint8_t GroupState::getKelvin() const { return _kelvin; }
 void GroupState::setKelvin(uint8_t kelvin) { _kelvin = kelvin; }
 
-BulbMode GroupState::getBulbMode() { return static_cast<BulbMode>(_bulbMode); }
+bool GroupState::isSetBulbMode() const { return _isSetBulbMode; }
+BulbMode GroupState::getBulbMode() const { return static_cast<BulbMode>(_bulbMode); }
 void GroupState::setBulbMode(BulbMode bulbMode) { _bulbMode = bulbMode; }

+ 24 - 10
lib/MiLightState/GroupState.h

@@ -28,31 +28,38 @@ public:
   GroupState();
 
   // 1 bit
-  bool isOn();
+  bool isSetOn() const;
+  bool isOn() const;
   void setOn(bool on);
 
   // 7 bits
+  bool isSetBrightness() const;
   uint8_t getBrightness() const;
   void setBrightness(uint8_t brightness);
 
   // 8 bits
-  uint8_t getHue();
+  bool isSetHue() const;
+  uint8_t getHue() const;
   void setHue(uint8_t hue);
 
   // 7 bits
-  uint8_t getSaturation();
+  bool isSetSaturation() const;
+  uint8_t getSaturation() const;
   void setSaturation(uint8_t saturation);
 
   // 5 bits
-  uint8_t getMode();
+  bool isSetMode() const;
+  uint8_t getMode() const;
   void setMode(uint8_t mode);
 
   // 7 bits
-  uint8_t getKelvin();
+  bool isSetKelvin() const;
+  uint8_t getKelvin() const;
   void setKelvin(uint8_t kelvin);
 
   // 3 bits
-  BulbMode getBulbMode();
+  bool isSetBulbMode() const;
+  BulbMode getBulbMode() const;
   void setBulbMode(BulbMode mode);
 
   static const GroupState DEFAULT_STATE;
@@ -65,10 +72,17 @@ private:
     _saturation : 7,
     _mode       : 4,
     _bulbMode   : 3,
-                : 2;
-  uint8_t
-    _kelvin     : 7,
-                : 1;
+    _isSetOn    : 1,
+    _isSetHue   : 1;
+
+  uint16_t
+    _kelvin          : 7,
+    _isSetBrightness : 1,
+    _isSetSaturation : 1,
+    _isSetMode       : 1,
+    _isSetKelvin     : 1,
+    _isSetBulbMode   : 1,
+                     : 4;
 };
 
 struct GroupStateNode {