#define MSP_DATAFILE_DYNAMICOBJECTLOADER_H_
#include <msp/core/typeregistry.h>
+#include "collection.h"
#include "except.h"
#include "loader.h"
private:
T *object;
Loader *obj_loader;
+ std::function<void(Collection &, const std::string &, T *)> store_func;
static ActionMap shared_actions;
public:
~DynamicObjectLoader() { delete object; delete obj_loader; }
- T *get_object() { T *o = object; object = 0; return o; }
private:
virtual void init_actions();
+public:
+ T *get_object() { T *o = object; object = 0; return o; }
+ void store_object(Collection &, const std::string &);
+
+private:
void type(const Symbol &);
template<typename U>
add("type", &DynamicObjectLoader::type);
}
+template<typename T, typename C>
+void DynamicObjectLoader<T, C>::store_object(Collection &c, const std::string &name)
+{
+ if(!store_func)
+ throw std::logic_error("no store function");
+
+ store_func(c, name, object);
+ object = 0;
+}
+
template<typename T, typename C>
void DynamicObjectLoader<T, C>::type(const Symbol &t)
{
ldr.object = obj;
ldr.obj_loader = ldr.create_object_loader<U>(*obj);
ldr.add_auxiliary_loader(*ldr.obj_loader);
+ ldr.store_func = [&ldr](Collection &c, const std::string &n, T *o){ c.add(n, static_cast<U *>(o)); };
}
} // namespace DataFile