From 3eb3c5cce35d3d6193afadecc3707f9c2448f370 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 4 Feb 2010 17:58:31 +0000 Subject: [PATCH] Create improvement replacements for BasicLoader* in objectloader.h Mark the old ones as deprecated --- source/loader.h | 6 ++-- source/objectloader.h | 65 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 source/objectloader.h diff --git a/source/loader.h b/source/loader.h index 5c8726a..6f7e614 100644 --- a/source/loader.h +++ b/source/loader.h @@ -156,8 +156,7 @@ protected: /** -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 class BasicLoader: public Loader @@ -175,8 +174,7 @@ public: /** -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 class BasicLoader2: public BasicLoader 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 -- 2.43.0