Commit 967b7515987cfacac60964f20d676619a2f6608e

Authored by Jojo-1000
Committed by Moritz Wirger
1 parent bc52722a

Move MakeCopyable helper class into detail namespace.

include/hueplusplus/BridgeConfig.h
... ... @@ -19,6 +19,9 @@
19 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 25 #include <string>
23 26 #include <vector>
24 27  
... ... @@ -55,7 +58,6 @@ public:
55 58 //! \brief Construct BridgeConfig
56 59 BridgeConfig(std::shared_ptr<APICache> baseCache, std::chrono::steady_clock::duration refreshDuration);
57 60  
58   -
59 61 //! \brief Refreshes internal cached state.
60 62 //! \throws std::system_error when system or socket operations fail
61 63 //! \throws HueException when response contained no body
... ... @@ -102,4 +104,6 @@ protected:
102 104 private:
103 105 APICache cache;
104 106 };
105   -} // namespace hueplusplus
106 107 \ No newline at end of file
  108 +} // namespace hueplusplus
  109 +
  110 +#endif
... ...
include/hueplusplus/Hue.h
... ... @@ -42,6 +42,7 @@
42 42 #include "ResourceList.h"
43 43 #include "Scene.h"
44 44 #include "Schedule.h"
  45 +#include "Utils.h"
45 46  
46 47 #include "json/json.hpp"
47 48  
... ... @@ -118,14 +119,6 @@ private:
118 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 122 //! \brief Hue class for a bridge.
130 123 //!
131 124 //! This is the main class used to interact with the Hue bridge.
... ... @@ -204,7 +197,7 @@ public:
204 197 //! \brief Provides access to the configuration of the bridge.
205 198 //! \note Does not refresh state.
206 199 const BridgeConfig& config() const;
207   -
  200 +
208 201 //! \brief Provides access to the HueLight%s on the bridge.
209 202 LightList& lights();
210 203 //! \brief Provides access to the HueLight%s on the bridge.
... ... @@ -238,6 +231,7 @@ private:
238 231 //! before Hue is used.
239 232 //! Resets all caches and resource lists.
240 233 void setHttpHandler(std::shared_ptr<const IHttpHandler> handler);
  234 +
241 235 private:
242 236 std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation
243 237 //!< like "192.168.2.1"
... ... @@ -248,11 +242,11 @@ private:
248 242 //!< bridge
249 243 std::chrono::steady_clock::duration refreshDuration;
250 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 251 } // namespace hueplusplus
258 252  
... ...
include/hueplusplus/Utils.h
... ... @@ -95,6 +95,23 @@ nlohmann::json safeGetMember(const nlohmann::json&amp; json, Paths&amp;&amp;... paths)
95 95 }
96 96  
97 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 115 } // namespace hueplusplus
99 116  
100 117 #endif
101 118 \ No newline at end of file
... ...
src/CMakeLists.txt
1 1 set(hueplusplus_SOURCES
2 2 APICache.cpp
3 3 BaseHttpHandler.cpp
  4 + BridgeConfig.cpp
4 5 ColorUnits.cpp
5 6 ExtendedColorHueStrategy.cpp
6 7 ExtendedColorTemperatureStrategy.cpp
... ... @@ -19,7 +20,7 @@ set(hueplusplus_SOURCES
19 20 StateTransaction.cpp
20 21 TimePattern.cpp
21 22 UPnP.cpp
22   - Utils.cpp "BridgeConfig.cpp")
  23 + Utils.cpp)
23 24  
24 25 # on windows we want to compile the WinHttpHandler
25 26 if(WIN32)
... ...
test/CMakeLists.txt
... ... @@ -32,6 +32,8 @@ target_compile_features(gtest PUBLIC cxx_std_14)
32 32 set(TEST_SOURCES
33 33 test_APICache.cpp
34 34 test_BaseHttpHandler.cpp
  35 + test_BridgeConfig.cpp
  36 + test_ColorUnits.cpp
35 37 test_ExtendedColorHueStrategy.cpp
36 38 test_ExtendedColorTemperatureStrategy.cpp
37 39 test_Group.cpp
... ... @@ -48,7 +50,7 @@ set(TEST_SOURCES
48 50 test_SimpleColorHueStrategy.cpp
49 51 test_SimpleColorTemperatureStrategy.cpp
50 52 test_StateTransaction.cpp
51   - test_TimePattern.cpp "test_ColorUnits.cpp" "test_BridgeConfig.cpp")
  53 + test_TimePattern.cpp)
52 54  
53 55 set(HuePlusPlus_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
54 56  
... ...