X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=blobdiff_plain;f=source%2Fobjectloader.h;h=e383109f791937739c7e80e5e3d10486bc1641ff;hp=f1cb6ffe051c5f8405fa652a67d36b3001dee380;hb=HEAD;hpb=302f73123da1194dd91b43138cd880cae9318a14 diff --git a/source/objectloader.h b/source/objectloader.h index f1cb6ff..978366f 100644 --- a/source/objectloader.h +++ b/source/objectloader.h @@ -1,18 +1,12 @@ #ifndef MSP_DATAFILE_OBJECTLOADER_H_ #define MSP_DATAFILE_OBJECTLOADER_H_ -#include +#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; /** @@ -20,7 +14,7 @@ Provides the basic functionality of an object loader. Deriving from this allows loading values directly into member variables of the objects. */ template -class ObjectLoader: public Loader +class ObjectLoader: virtual public Loader { public: typedef O Object; @@ -35,6 +29,27 @@ public: }; +/** +Convenience class for loading derived objects. Inherits from the base class +loader and shadows its members with ones for the derived type. +*/ +template +class DerivedObjectLoader: public B +{ +public: + typedef O Object; + +protected: + O &obj; + + template + DerivedObjectLoader(O &o, Args &&... a): B(o, std::forward(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. @@ -46,7 +61,7 @@ public: typedef C Collection; protected: - C *coll; + C *coll = nullptr; CollectionObjectLoader(O &o, C *c): ObjectLoader(o), coll(c) { }