X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobjectloader.h;fp=source%2Fobjectloader.h;h=515ea6b8b81c6d51338735a704f960a0f27b802a;hb=3eb3c5cce35d3d6193afadecc3707f9c2448f370;hp=0000000000000000000000000000000000000000;hpb=b34b46788d69853eabdbbd9e71ca82f2f5c09df8;p=libs%2Fdatafile.git diff --git a/source/objectloader.h b/source/objectloader.h new file mode 100644 index 0000000..515ea6b --- /dev/null +++ b/source/objectloader.h @@ -0,0 +1,65 @@ +/* $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 "loader.h" + +namespace Msp { +namespace DataFile { + +class Collection; + +/** +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 +{ +public: + typedef O Object; + +protected: + O &obj; + + ObjectLoader(O &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. +*/ +template +class CollectionObjectLoader: public ObjectLoader +{ +public: + typedef C Collection; + +protected: + C *coll; + + CollectionObjectLoader(O &o, C *c): ObjectLoader(o), coll(c) { } + +public: + C &get_collection() const + { + if(!coll) + throw InvalidState("No collection"); + return *coll; + } +}; + +} // namespace DataFile +} // namespace Msp + +#endif