protected:
virtual void type(const Symbol &);
-private:
- template<typename U>
- typename std::enable_if<NeedsCollection<typename U::Loader>::value, std::unique_ptr<typename U::Loader>>::type create_object_loader(U &obj) const;
-
- template<typename U>
- typename std::enable_if<!NeedsCollection<typename U::Loader>::value, std::unique_ptr<typename U::Loader>>::type create_object_loader(U &obj) const;
-
-protected:
virtual const TypeRegistry &get_type_registry() const = 0;
};
get_type_registry().invoke(t.name, *this);
}
-template<typename T, typename C>
-template<typename U>
-typename std::enable_if<NeedsCollection<typename U::Loader>::value, std::unique_ptr<typename U::Loader>>::type DynamicObjectLoader<T, C>::create_object_loader(U &obj) const
-{
- if(!coll)
- throw no_collection(typeid(U));
- return std::make_unique<typename U::Loader>(obj, *coll);
-}
-
-template<typename T, typename C>
-template<typename U>
-typename std::enable_if<!NeedsCollection<typename U::Loader>::value, std::unique_ptr<typename U::Loader>>::type DynamicObjectLoader<T, C>::create_object_loader(U &obj) const
-{
- return std::make_unique<typename U::Loader>(obj);
-}
-
template<typename T, typename C>
template<typename U>
void DynamicObjectLoader<T, C>::CreateObject<U>::operator()(const std::string &, DynamicObjectLoader &ldr) const
{
ldr.object = std::make_unique<U>();
- ldr.obj_loader = ldr.create_object_loader<U>(static_cast<U &>(*ldr.object));
+ if constexpr(NeedsCollection<typename U::Loader>::value)
+ {
+ if(!ldr.coll)
+ throw no_collection(typeid(U));
+ ldr.obj_loader = std::make_unique<typename U::Loader>(static_cast<U &>(*ldr.object), *ldr.coll);
+ }
+ else
+ ldr.obj_loader = std::make_unique<typename U::Loader>(static_cast<U &>(*ldr.object));
ldr.add_auxiliary_loader(*ldr.obj_loader);
ldr.store_func = [](Collection &c, const std::string &n, std::unique_ptr<T> o){ c.add(n, std::unique_ptr<U>(static_cast<U *>(o.release()))); };
}