Skip to content

Commit ead82b7

Browse files
committed
fable: Use references instead of pointers for Conf::try_from*
This is recommended by clang-tidy as a less error prone approach. BREAKING CHANGE: If you use `Conf::try_from` or `Conf::try_from_pointer`, you need to update your call from passing a pointer to passing a value. That means you may need to use one of these transformations: conf.try_from(key, value) -> conf.try_from(key, *value) conf.try_from(key, &value) -> conf.try_from(key, value)
1 parent da80c52 commit ead82b7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

fable/include/fable/conf.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,16 @@ class Conf {
258258
* - Throws a ConfError if the value is of the wrong type.
259259
*/
260260
template <typename T>
261-
void try_from(const std::string& key, T* val) const {
261+
void try_from(const std::string& key, T& val) const {
262262
if (data_.count(key)) {
263-
*val = get<T>(key);
263+
val = get<T>(key);
264264
}
265265
}
266266

267267
template <typename T>
268-
void try_from(const JsonPointer& key, T* val) const {
268+
void try_from(const JsonPointer& key, T& val) const {
269269
try {
270-
*val = data_.at(key).get<T>();
270+
val = data_.at(key).get<T>();
271271
} catch (nlohmann::detail::out_of_range& e) {
272272
return;
273273
} catch (nlohmann::detail::type_error& e) {
@@ -276,7 +276,7 @@ class Conf {
276276
}
277277

278278
template <typename T>
279-
void try_from_pointer(const std::string& key, T* val) const {
279+
void try_from_pointer(const std::string& key, T& val) const {
280280
try_from(JsonPointer(key), val);
281281
}
282282

plugins/basic/src/hmi_contact.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class ContactMap : public Confable {
194194

195195
void from_conf(const Conf& c) override {
196196
for (auto& elem : buttons_) {
197-
c.try_from(elem.first, &elem.second.state);
197+
c.try_from(elem.first, elem.second.state);
198198
}
199199
}
200200

0 commit comments

Comments
 (0)