]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/objectloader.h
Make Loader a virtual base of ObjectLoader to permit diamond inheritance
[libs/datafile.git] / source / objectloader.h
index f1cb6ffe051c5f8405fa652a67d36b3001dee380..76fc412abed60db13c7b7e4b80837ffad0ca93df 100644 (file)
@@ -20,7 +20,7 @@ Provides the basic functionality of an object loader.  Deriving from this
 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;
@@ -35,6 +35,29 @@ public:
 };
 
 
+/**
+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.