@@ -86,36 +86,6 @@ namespace internal
8686 };
8787} // namespace internal
8888
89- namespace detail
90- {
91- /*
92- * This converts the key (first parameter) to its string name within the
93- * openPMD hierarchy.
94- * If the key is found to be equal to RecordComponent::SCALAR, the parentKey
95- * will be returned, adding RecordComponent::SCALAR to its back.
96- * Reason: Scalar record components do not link their containing record as
97- * parent, but rather the parent's parent, so the own key within the
98- * "apparent" parent must be given as two steps.
99- */
100- template <typename T>
101- std::vector<std::string>
102- keyAsString (T &&key, std::vector<std::string> const &parentKey)
103- {
104- (void )parentKey;
105- return {std::to_string (std::forward<T>(key))};
106- }
107-
108- // moved to a *.cpp file so we don't need to include RecordComponent.hpp
109- // here
110- template <>
111- std::vector<std::string> keyAsString<std::string const &>(
112- std::string const &key, std::vector<std::string> const &parentKey);
113-
114- template <>
115- std::vector<std::string> keyAsString<std::string>(
116- std::string &&key, std::vector<std::string> const &parentKey);
117- } // namespace detail
118-
11989/* * @brief Map-like container that enforces openPMD requirements and handles IO.
12090 *
12191 * @see http://en.cppreference.com/w/cpp/container/map
@@ -328,8 +298,14 @@ class Container : virtual public Attributable
328298 T t = T ();
329299 t.linkHierarchy (writable ());
330300 auto &ret = container ().insert ({key, std::move (t)}).first ->second ;
331- ret.writable ().ownKeyWithinParent =
332- detail::keyAsString (key, writable ().ownKeyWithinParent );
301+ if constexpr (std::is_same_v<T_key, std::string>)
302+ {
303+ ret.writable ().ownKeyWithinParent = key;
304+ }
305+ else
306+ {
307+ ret.writable ().ownKeyWithinParent = std::to_string (key);
308+ }
333309 traits::GenerationPolicy<T> gen;
334310 gen (ret);
335311 return ret;
@@ -363,8 +339,15 @@ class Container : virtual public Attributable
363339 T t = T ();
364340 t.linkHierarchy (writable ());
365341 auto &ret = container ().insert ({key, std::move (t)}).first ->second ;
366- ret.writable ().ownKeyWithinParent = detail::keyAsString (
367- std::move (key), writable ().ownKeyWithinParent );
342+ if constexpr (std::is_same_v<T_key, std::string>)
343+ {
344+ ret.writable ().ownKeyWithinParent = std::move (key);
345+ }
346+ else
347+ {
348+ ret.writable ().ownKeyWithinParent =
349+ std::to_string (std::move (key));
350+ }
368351 traits::GenerationPolicy<T> gen;
369352 gen (ret);
370353 return ret;
0 commit comments