/**
-Provides the basic functionality of an object loader. Deriving from this
-allows loading values directly into member variables of the objects.
+Deprecated. See ObjectLoader in objectloader.h.
*/
template<typename O>
class BasicLoader: public Loader
/**
-Provides functionality for loading objects with a Collection. Deriving from
-this allows loading pointers to objects in the collection automatically.
+Deprecated. See CollectionObjectLoader in objectloader.h.
*/
template<typename O, typename C>
class BasicLoader2: public BasicLoader<O>
--- /dev/null
+/* $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<typename O>
+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<typename O, typename C = Collection>
+class CollectionObjectLoader: public ObjectLoader<O>
+{
+public:
+ typedef C Collection;
+
+protected:
+ C *coll;
+
+ CollectionObjectLoader(O &o, C *c): ObjectLoader<O>(o), coll(c) { }
+
+public:
+ C &get_collection() const
+ {
+ if(!coll)
+ throw InvalidState("No collection");
+ return *coll;
+ }
+};
+
+} // namespace DataFile
+} // namespace Msp
+
+#endif