Collection &get_object() const { return coll; }
private:
template<typename T>
- void item(const std::string &n) { make_sub<T>().into(dynamic_cast<typename CollectionType<typename T::Loader>::Type &>(coll), n).load(); }
+ void item(const std::string &n) { make_sub<T>().into(dynamic_cast<typename CollectionType<typename T::Loader>::Type &>(coll)).raw_name(n).load(); }
};
private:
#include <map>
#include <optional>
#include <type_traits>
+#include <msp/core/except.h>
#include <msp/io/file.h>
#include "loaderaction.h"
#include "meta.h"
SubOps(Loader &p, P o, C *c, const std::string &n): parent(p), obj(std::move(o)), coll(c) { name(n); }
SubOps &name(const std::string &n) { name_ = parent.context+": "+n; return *this; }
+ SubOps &raw_name(const std::string &n) { name_ = n; return *this; }
/** Stores the object in a collection after loading. The object must be
created by the loader. */
template<typename C2>
SubOps<P, L, C2> into(C2 &c, const std::string &n) { return { parent, std::move(obj), &c, n }; }
+ template<typename C2>
+ SubOps<P, L, C2> into(C2 &c) { return { parent, std::move(obj), &c, {} }; }
+
/** Loads the object. Arguments are passed to the loader's constructor.
If into() was called, a reference to the collection will be passed as
well. */
template<typename... Args>
typename Loader::SubOps<P, L, C>::LoadResult Loader::SubOps<P, L, C>::load(Args &&... args)
{
+ if constexpr(!std::is_same_v<C, void>)
+ if(name_.empty())
+ throw invalid_state("missing name");
+
std::optional<L> ldr;
if constexpr(std::is_same_v<P, std::nullptr_t>)
{