From 967b7515987cfacac60964f20d676619a2f6608e Mon Sep 17 00:00:00 2001 From: Jojo-1000 <33495614+Jojo-1000@users.noreply.github.com> Date: Sat, 20 Jun 2020 21:16:59 +0200 Subject: [PATCH] Move MakeCopyable helper class into detail namespace. --- include/hueplusplus/BridgeConfig.h | 8 ++++++-- include/hueplusplus/Hue.h | 22 ++++++++-------------- include/hueplusplus/Utils.h | 17 +++++++++++++++++ src/CMakeLists.txt | 3 ++- test/CMakeLists.txt | 4 +++- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/include/hueplusplus/BridgeConfig.h b/include/hueplusplus/BridgeConfig.h index bf00e57..b252346 100644 --- a/include/hueplusplus/BridgeConfig.h +++ b/include/hueplusplus/BridgeConfig.h @@ -19,6 +19,9 @@ along with hueplusplus. If not, see . **/ +#ifndef INCLUDE_HUEPLUSPLUS_BRIDGE_CONFIG_H +#define INCLUDE_HUEPLUSPLUS_BRIDGE_CONFIG_H + #include #include @@ -55,7 +58,6 @@ public: //! \brief Construct BridgeConfig BridgeConfig(std::shared_ptr baseCache, std::chrono::steady_clock::duration refreshDuration); - //! \brief Refreshes internal cached state. //! \throws std::system_error when system or socket operations fail //! \throws HueException when response contained no body @@ -102,4 +104,6 @@ protected: private: APICache cache; }; -} // namespace hueplusplus \ No newline at end of file +} // namespace hueplusplus + +#endif diff --git a/include/hueplusplus/Hue.h b/include/hueplusplus/Hue.h index cacfec6..4b69abd 100644 --- a/include/hueplusplus/Hue.h +++ b/include/hueplusplus/Hue.h @@ -42,6 +42,7 @@ #include "ResourceList.h" #include "Scene.h" #include "Schedule.h" +#include "Utils.h" #include "json/json.hpp" @@ -118,14 +119,6 @@ private: std::shared_ptr http_handler; }; -template -class MakeCopyable : public T -{ -public: - using T::T; - using T::operator=; -}; - //! \brief Hue class for a bridge. //! //! This is the main class used to interact with the Hue bridge. @@ -204,7 +197,7 @@ public: //! \brief Provides access to the configuration of the bridge. //! \note Does not refresh state. const BridgeConfig& config() const; - + //! \brief Provides access to the HueLight%s on the bridge. LightList& lights(); //! \brief Provides access to the HueLight%s on the bridge. @@ -238,6 +231,7 @@ private: //! before Hue is used. //! Resets all caches and resource lists. void setHttpHandler(std::shared_ptr handler); + private: std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation //!< like "192.168.2.1" @@ -248,11 +242,11 @@ private: //!< bridge std::chrono::steady_clock::duration refreshDuration; std::shared_ptr stateCache; - MakeCopyable lightList; - MakeCopyable groupList; - MakeCopyable scheduleList; - MakeCopyable sceneList; - MakeCopyable bridgeConfig; + detail::MakeCopyable lightList; + detail::MakeCopyable groupList; + detail::MakeCopyable scheduleList; + detail::MakeCopyable sceneList; + detail::MakeCopyable bridgeConfig; }; } // namespace hueplusplus diff --git a/include/hueplusplus/Utils.h b/include/hueplusplus/Utils.h index ed51703..ecb989a 100644 --- a/include/hueplusplus/Utils.h +++ b/include/hueplusplus/Utils.h @@ -95,6 +95,23 @@ nlohmann::json safeGetMember(const nlohmann::json& json, Paths&&... paths) } } // namespace utils + +namespace detail +{ +//! \brief Makes a class with protected copy constructor copyable. +//! +//! Used in private members to expose mutable references to \c T +//! while not allowing them to be assigned to. +//! Make sure \c T is actually designed to be used this way! +template +class MakeCopyable : public T +{ +public: + // Make copy constructor and assignment operator public + using T::T; + using T::operator=; +}; +} // namespace detail } // namespace hueplusplus #endif \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ef94e2b..9754d5c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ set(hueplusplus_SOURCES APICache.cpp BaseHttpHandler.cpp + BridgeConfig.cpp ColorUnits.cpp ExtendedColorHueStrategy.cpp ExtendedColorTemperatureStrategy.cpp @@ -19,7 +20,7 @@ set(hueplusplus_SOURCES StateTransaction.cpp TimePattern.cpp UPnP.cpp - Utils.cpp "BridgeConfig.cpp") + Utils.cpp) # on windows we want to compile the WinHttpHandler if(WIN32) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5681156..cbfe729 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,6 +32,8 @@ target_compile_features(gtest PUBLIC cxx_std_14) set(TEST_SOURCES test_APICache.cpp test_BaseHttpHandler.cpp + test_BridgeConfig.cpp + test_ColorUnits.cpp test_ExtendedColorHueStrategy.cpp test_ExtendedColorTemperatureStrategy.cpp test_Group.cpp @@ -48,7 +50,7 @@ set(TEST_SOURCES test_SimpleColorHueStrategy.cpp test_SimpleColorTemperatureStrategy.cpp test_StateTransaction.cpp - test_TimePattern.cpp "test_ColorUnits.cpp" "test_BridgeConfig.cpp") + test_TimePattern.cpp) set(HuePlusPlus_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include") -- libgit2 0.21.4