Skip to content

Commit 0cb4b7f

Browse files
committed
add new name function and remove manual namespacing
1 parent cfa3002 commit 0cb4b7f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

config_utilities/include/config_utilities/config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ namespace config {
5353
*/
5454
inline void name(const std::string& name) { internal::Visitor::visitName(name); }
5555

56+
/**
57+
* @brief Set the name of a config from the template parameter type.
58+
* @tparam T type to get the name from
59+
*
60+
* This is for cases where you may not have a static config struct name (i.e., with a templated config struct)
61+
*/
62+
template <typename T>
63+
void name() {
64+
internal::Visitor::visitName(internal::typeName<T>());
65+
}
66+
5667
/**
5768
* @brief Declare string-named fields of the config. This string will be used to get the configs field values during
5869
* creation, and for checking of validity.

config_utilities/include/config_utilities/internal/visitor_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void Visitor::visitField(std::vector<ConfigT>& config, const std::string& field_
252252
}
253253

254254
if (visitor.mode == Visitor::Mode::kSet) {
255-
const auto array_ns = visitor.name_space.empty() ? field_name : visitor.name_space + "/" + field_name;
255+
const auto array_ns = joinNamespace(visitor.name_space, field_name);
256256
const auto subnode = lookupNamespace(visitor.data.data, array_ns);
257257
if (!subnode) {
258258
return; // don't override the field if not present
@@ -330,7 +330,7 @@ void Visitor::visitField(OrderedMap<K, ConfigT>& config, const std::string& fiel
330330
}
331331

332332
if (visitor.mode == Visitor::Mode::kSet) {
333-
const auto map_ns = visitor.name_space.empty() ? field_name : visitor.name_space + "/" + field_name;
333+
const auto map_ns = joinNamespace(visitor.name_space, field_name);
334334
const auto subnode = lookupNamespace(visitor.data.data, map_ns);
335335
if (!subnode) {
336336
return; // don't override the field if not present

0 commit comments

Comments
 (0)