23 #ifndef INCLUDE_HUEPLUSPLUS_UTILS_H 24 #define INCLUDE_HUEPLUSPLUS_UTILS_H 26 #include "json/json.hpp" 36 template <
typename KeyT,
typename... Paths>
37 nlohmann::json safeGetMemberHelper(
const nlohmann::json& json, std::size_t index, Paths&&... otherPaths);
39 inline nlohmann::json safeGetMemberHelper(
const nlohmann::json& json)
44 template <
typename KeyT,
typename... Paths,
45 std::enable_if_t<!std::is_integral<std::remove_reference_t<KeyT>>::value>* =
nullptr>
46 nlohmann::json safeGetMemberHelper(
const nlohmann::json& json, KeyT&& key, Paths&&... otherPaths)
48 auto memberIt = json.find(std::forward<KeyT>(key));
49 if (memberIt == json.end())
53 return safeGetMemberHelper(*memberIt, std::forward<Paths>(otherPaths)...);
57 template <
typename... Paths>
58 nlohmann::json safeGetMemberHelper(
const nlohmann::json& json, std::size_t index, Paths&&... otherPaths)
60 if (!json.is_array() || json.size() <= index)
64 return safeGetMemberHelper(json[index], std::forward<Paths>(otherPaths)...);
74 bool validatePUTReply(
const std::string& path,
const nlohmann::json& request,
const nlohmann::json& reply);
83 return std::abs(lhs - rhs) <= 1E-4f;
91 template <
typename... Paths>
92 nlohmann::json
safeGetMember(
const nlohmann::json& json, Paths&&... paths)
94 return detail::safeGetMemberHelper(json, std::forward<Paths>(paths)...);
106 template <
typename T>
107 class MakeCopyable :
public T
Namespace for the hueplusplus library.
Definition: Action.h:27
bool validateReplyForLight(const nlohmann::json &request, const nlohmann::json &reply, int lightId)
Definition: Utils.cpp:89
bool validatePUTReply(const std::string &path, const nlohmann::json &request, const nlohmann::json &reply)
Function for validating that a request was executed correctly.
Definition: Utils.cpp:31
bool floatEquals(float lhs, float rhs)
Checks equality to 4 decimal places.
Definition: Utils.h:81
nlohmann::json safeGetMember(const nlohmann::json &json, Paths &&... paths)
Returns the object/array member or null if it does not exist.
Definition: Utils.h:92