Skip to content

Commit

Permalink
surely this time
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 committed Oct 6, 2023
1 parent 2e0c0a8 commit bb34ad9
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions include/dpp/discordevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,13 @@ void DPP_EXPORT for_each_json(const nlohmann::json* parent, std::string_view key
* @param keyname key name to check for the values
* @param v Value to change
*/
template<class T> void set_object_array_not_null(const nlohmann::json* j, std::string_view key, std::vector<T>& v) {
template<class T> void set_object_array_not_null(nlohmann::json* j, std::string_view key, std::vector<T>& v) {
v.clear();
for_each_json(j, key, [&v](const json& elem) {
for_each_json(j, key, [&v](nlohmann::json* elem) {
v.push_back(T{}.fill_from_json(elem));
});
}

/** @brief Sets an array of objects from a json field value, if defined, else does nothing
* @tparam T The class of which the array consists of. Must be derived from dpp::json_interface
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for the values
* @param v Value to change
*/
template<class T> std::enable_if_t<std::is_base_of_v<json_interface<T>, T>, void> set_object_array_not_null(nlohmann::json* j, const char *keyname, std::vector<T> &v) {
v.clear();
auto k = j->find(keyname);
if (k != j->end() && !k->is_null()) {
v.reserve(j->at(keyname).size());
for (auto &obj : j->at(keyname)) {
v.emplace_back(T().fill_from_json(&obj));
}
}
}

/** @brief Returns a string from a json field value, if defined, else returns an empty string.
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
Expand Down

0 comments on commit bb34ad9

Please sign in to comment.