Commit 967b7515987cfacac60964f20d676619a2f6608e
Committed by
Moritz Wirger
1 parent
bc52722a
Move MakeCopyable helper class into detail namespace.
Showing
5 changed files
with
36 additions
and
18 deletions
include/hueplusplus/BridgeConfig.h
| @@ -19,6 +19,9 @@ | @@ -19,6 +19,9 @@ | ||
| 19 | along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | 19 | along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. |
| 20 | **/ | 20 | **/ |
| 21 | 21 | ||
| 22 | +#ifndef INCLUDE_HUEPLUSPLUS_BRIDGE_CONFIG_H | ||
| 23 | +#define INCLUDE_HUEPLUSPLUS_BRIDGE_CONFIG_H | ||
| 24 | + | ||
| 22 | #include <string> | 25 | #include <string> |
| 23 | #include <vector> | 26 | #include <vector> |
| 24 | 27 | ||
| @@ -55,7 +58,6 @@ public: | @@ -55,7 +58,6 @@ public: | ||
| 55 | //! \brief Construct BridgeConfig | 58 | //! \brief Construct BridgeConfig |
| 56 | BridgeConfig(std::shared_ptr<APICache> baseCache, std::chrono::steady_clock::duration refreshDuration); | 59 | BridgeConfig(std::shared_ptr<APICache> baseCache, std::chrono::steady_clock::duration refreshDuration); |
| 57 | 60 | ||
| 58 | - | ||
| 59 | //! \brief Refreshes internal cached state. | 61 | //! \brief Refreshes internal cached state. |
| 60 | //! \throws std::system_error when system or socket operations fail | 62 | //! \throws std::system_error when system or socket operations fail |
| 61 | //! \throws HueException when response contained no body | 63 | //! \throws HueException when response contained no body |
| @@ -102,4 +104,6 @@ protected: | @@ -102,4 +104,6 @@ protected: | ||
| 102 | private: | 104 | private: |
| 103 | APICache cache; | 105 | APICache cache; |
| 104 | }; | 106 | }; |
| 105 | -} // namespace hueplusplus | ||
| 106 | \ No newline at end of file | 107 | \ No newline at end of file |
| 108 | +} // namespace hueplusplus | ||
| 109 | + | ||
| 110 | +#endif |
include/hueplusplus/Hue.h
| @@ -42,6 +42,7 @@ | @@ -42,6 +42,7 @@ | ||
| 42 | #include "ResourceList.h" | 42 | #include "ResourceList.h" |
| 43 | #include "Scene.h" | 43 | #include "Scene.h" |
| 44 | #include "Schedule.h" | 44 | #include "Schedule.h" |
| 45 | +#include "Utils.h" | ||
| 45 | 46 | ||
| 46 | #include "json/json.hpp" | 47 | #include "json/json.hpp" |
| 47 | 48 | ||
| @@ -118,14 +119,6 @@ private: | @@ -118,14 +119,6 @@ private: | ||
| 118 | std::shared_ptr<const IHttpHandler> http_handler; | 119 | std::shared_ptr<const IHttpHandler> http_handler; |
| 119 | }; | 120 | }; |
| 120 | 121 | ||
| 121 | -template <typename T> | ||
| 122 | -class MakeCopyable : public T | ||
| 123 | -{ | ||
| 124 | -public: | ||
| 125 | - using T::T; | ||
| 126 | - using T::operator=; | ||
| 127 | -}; | ||
| 128 | - | ||
| 129 | //! \brief Hue class for a bridge. | 122 | //! \brief Hue class for a bridge. |
| 130 | //! | 123 | //! |
| 131 | //! This is the main class used to interact with the Hue bridge. | 124 | //! This is the main class used to interact with the Hue bridge. |
| @@ -204,7 +197,7 @@ public: | @@ -204,7 +197,7 @@ public: | ||
| 204 | //! \brief Provides access to the configuration of the bridge. | 197 | //! \brief Provides access to the configuration of the bridge. |
| 205 | //! \note Does not refresh state. | 198 | //! \note Does not refresh state. |
| 206 | const BridgeConfig& config() const; | 199 | const BridgeConfig& config() const; |
| 207 | - | 200 | + |
| 208 | //! \brief Provides access to the HueLight%s on the bridge. | 201 | //! \brief Provides access to the HueLight%s on the bridge. |
| 209 | LightList& lights(); | 202 | LightList& lights(); |
| 210 | //! \brief Provides access to the HueLight%s on the bridge. | 203 | //! \brief Provides access to the HueLight%s on the bridge. |
| @@ -238,6 +231,7 @@ private: | @@ -238,6 +231,7 @@ private: | ||
| 238 | //! before Hue is used. | 231 | //! before Hue is used. |
| 239 | //! Resets all caches and resource lists. | 232 | //! Resets all caches and resource lists. |
| 240 | void setHttpHandler(std::shared_ptr<const IHttpHandler> handler); | 233 | void setHttpHandler(std::shared_ptr<const IHttpHandler> handler); |
| 234 | + | ||
| 241 | private: | 235 | private: |
| 242 | std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation | 236 | std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation |
| 243 | //!< like "192.168.2.1" | 237 | //!< like "192.168.2.1" |
| @@ -248,11 +242,11 @@ private: | @@ -248,11 +242,11 @@ private: | ||
| 248 | //!< bridge | 242 | //!< bridge |
| 249 | std::chrono::steady_clock::duration refreshDuration; | 243 | std::chrono::steady_clock::duration refreshDuration; |
| 250 | std::shared_ptr<APICache> stateCache; | 244 | std::shared_ptr<APICache> stateCache; |
| 251 | - MakeCopyable<LightList> lightList; | ||
| 252 | - MakeCopyable<GroupList> groupList; | ||
| 253 | - MakeCopyable<ScheduleList> scheduleList; | ||
| 254 | - MakeCopyable<SceneList> sceneList; | ||
| 255 | - MakeCopyable<BridgeConfig> bridgeConfig; | 245 | + detail::MakeCopyable<LightList> lightList; |
| 246 | + detail::MakeCopyable<GroupList> groupList; | ||
| 247 | + detail::MakeCopyable<ScheduleList> scheduleList; | ||
| 248 | + detail::MakeCopyable<SceneList> sceneList; | ||
| 249 | + detail::MakeCopyable<BridgeConfig> bridgeConfig; | ||
| 256 | }; | 250 | }; |
| 257 | } // namespace hueplusplus | 251 | } // namespace hueplusplus |
| 258 | 252 |
include/hueplusplus/Utils.h
| @@ -95,6 +95,23 @@ nlohmann::json safeGetMember(const nlohmann::json& json, Paths&&... paths) | @@ -95,6 +95,23 @@ nlohmann::json safeGetMember(const nlohmann::json& json, Paths&&... paths) | ||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | } // namespace utils | 97 | } // namespace utils |
| 98 | + | ||
| 99 | +namespace detail | ||
| 100 | +{ | ||
| 101 | +//! \brief Makes a class with protected copy constructor copyable. | ||
| 102 | +//! | ||
| 103 | +//! Used in private members to expose mutable references to \c T | ||
| 104 | +//! while not allowing them to be assigned to. | ||
| 105 | +//! Make sure \c T is actually designed to be used this way! | ||
| 106 | +template <typename T> | ||
| 107 | +class MakeCopyable : public T | ||
| 108 | +{ | ||
| 109 | +public: | ||
| 110 | + // Make copy constructor and assignment operator public | ||
| 111 | + using T::T; | ||
| 112 | + using T::operator=; | ||
| 113 | +}; | ||
| 114 | +} // namespace detail | ||
| 98 | } // namespace hueplusplus | 115 | } // namespace hueplusplus |
| 99 | 116 | ||
| 100 | #endif | 117 | #endif |
| 101 | \ No newline at end of file | 118 | \ No newline at end of file |
src/CMakeLists.txt
| 1 | set(hueplusplus_SOURCES | 1 | set(hueplusplus_SOURCES |
| 2 | APICache.cpp | 2 | APICache.cpp |
| 3 | BaseHttpHandler.cpp | 3 | BaseHttpHandler.cpp |
| 4 | + BridgeConfig.cpp | ||
| 4 | ColorUnits.cpp | 5 | ColorUnits.cpp |
| 5 | ExtendedColorHueStrategy.cpp | 6 | ExtendedColorHueStrategy.cpp |
| 6 | ExtendedColorTemperatureStrategy.cpp | 7 | ExtendedColorTemperatureStrategy.cpp |
| @@ -19,7 +20,7 @@ set(hueplusplus_SOURCES | @@ -19,7 +20,7 @@ set(hueplusplus_SOURCES | ||
| 19 | StateTransaction.cpp | 20 | StateTransaction.cpp |
| 20 | TimePattern.cpp | 21 | TimePattern.cpp |
| 21 | UPnP.cpp | 22 | UPnP.cpp |
| 22 | - Utils.cpp "BridgeConfig.cpp") | 23 | + Utils.cpp) |
| 23 | 24 | ||
| 24 | # on windows we want to compile the WinHttpHandler | 25 | # on windows we want to compile the WinHttpHandler |
| 25 | if(WIN32) | 26 | if(WIN32) |
test/CMakeLists.txt
| @@ -32,6 +32,8 @@ target_compile_features(gtest PUBLIC cxx_std_14) | @@ -32,6 +32,8 @@ target_compile_features(gtest PUBLIC cxx_std_14) | ||
| 32 | set(TEST_SOURCES | 32 | set(TEST_SOURCES |
| 33 | test_APICache.cpp | 33 | test_APICache.cpp |
| 34 | test_BaseHttpHandler.cpp | 34 | test_BaseHttpHandler.cpp |
| 35 | + test_BridgeConfig.cpp | ||
| 36 | + test_ColorUnits.cpp | ||
| 35 | test_ExtendedColorHueStrategy.cpp | 37 | test_ExtendedColorHueStrategy.cpp |
| 36 | test_ExtendedColorTemperatureStrategy.cpp | 38 | test_ExtendedColorTemperatureStrategy.cpp |
| 37 | test_Group.cpp | 39 | test_Group.cpp |
| @@ -48,7 +50,7 @@ set(TEST_SOURCES | @@ -48,7 +50,7 @@ set(TEST_SOURCES | ||
| 48 | test_SimpleColorHueStrategy.cpp | 50 | test_SimpleColorHueStrategy.cpp |
| 49 | test_SimpleColorTemperatureStrategy.cpp | 51 | test_SimpleColorTemperatureStrategy.cpp |
| 50 | test_StateTransaction.cpp | 52 | test_StateTransaction.cpp |
| 51 | - test_TimePattern.cpp "test_ColorUnits.cpp" "test_BridgeConfig.cpp") | 53 | + test_TimePattern.cpp) |
| 52 | 54 | ||
| 53 | set(HuePlusPlus_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include") | 55 | set(HuePlusPlus_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include") |
| 54 | 56 |