#ifndef MSP_DATAFILE_OBJECTLOADER_H_
#define MSP_DATAFILE_OBJECTLOADER_H_
-#include <typeinfo>
+#include "except.h"
#include "loader.h"
namespace Msp {
namespace DataFile {
-class no_collection: public std::runtime_error
-{
-public:
- no_collection(const std::type_info &);
-};
-
class Collection;
/**
allows loading values directly into member variables of the objects.
*/
template<typename O>
-class ObjectLoader: public Loader
+class ObjectLoader: virtual public Loader
{
public:
typedef O Object;
};
+/**
+Convenience class for loading derived objects. Inherits from the base class
+loader and shadows its members with ones for the derived type.
+*/
+template<typename O, typename B>
+class DerivedObjectLoader: public B
+{
+public:
+ typedef O Object;
+
+protected:
+ O &obj;
+
+ DerivedObjectLoader(O &o): B(o), obj(o) { }
+
+ template<typename T>
+ DerivedObjectLoader(O &o, T &a): B(o, a), obj(o) { }
+
+public:
+ O &get_object() const { return obj; }
+};
+
+
/**
Provides functionality for loading objects with a Collection. Deriving from
this allows loading pointers to objects in the collection automatically.