Browse Source

default instance as singleton method

Chris Mullins 8 years ago
parent
commit
2543f0f11d

+ 5 - 0
lib/MiLightState/GroupState.cpp

@@ -1,5 +1,10 @@
 #include <GroupState.h>
 
+const GroupState& GroupState::defaultState() {
+  static GroupState instance;
+  return instance;
+}
+
 GroupId::GroupId()
   : deviceId(0),
     groupId(0),

+ 1 - 1
lib/MiLightState/GroupState.h

@@ -62,7 +62,7 @@ public:
   BulbMode getBulbMode() const;
   void setBulbMode(BulbMode mode);
 
-  static const GroupState DEFAULT_STATE;
+  static const GroupState& defaultState();
 
 private:
   uint32_t

+ 1 - 1
lib/MiLightState/GroupStateCache.cpp

@@ -8,7 +8,7 @@ const GroupState* GroupStateCache::get(const GroupId& id) {
   GroupState* state = getInternal(id);
 
   if (state == NULL) {
-    return &GroupState::DEFAULT_STATE;
+    return &GroupState::defaultState();
   } else {
     return state;
   }