X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobjectloader.h;h=4dcb981864e7c2d924a61dcbd44e552dfffa6cb0;hb=8955db30f9cd1c1566b349da29e669f065f84e36;hp=515ea6b8b81c6d51338735a704f960a0f27b802a;hpb=3eb3c5cce35d3d6193afadecc3707f9c2448f370;p=libs%2Fdatafile.git diff --git a/source/objectloader.h b/source/objectloader.h index 515ea6b..4dcb981 100644 --- a/source/objectloader.h +++ b/source/objectloader.h @@ -1,18 +1,18 @@ -/* $Id$ - -This file is part of libmspdatafile -Copyright © 2010 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_DATAFILE_OBJECTLOADER_H_ #define MSP_DATAFILE_OBJECTLOADER_H_ +#include #include "loader.h" namespace Msp { namespace DataFile { +class no_collection: public std::runtime_error +{ +public: + no_collection(const std::type_info &); +}; + class Collection; /** @@ -35,6 +35,26 @@ 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; + + DerivedObjectLoader(O &o): B(o), 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. @@ -54,7 +74,7 @@ public: C &get_collection() const { if(!coll) - throw InvalidState("No collection"); + throw no_collection(typeid(O)); return *coll; } };