summaryrefslogtreecommitdiff
path: root/project2/common/scriptLoader.h
diff options
context:
space:
mode:
Diffstat (limited to 'project2/common/scriptLoader.h')
-rw-r--r--project2/common/scriptLoader.h39
1 files changed, 24 insertions, 15 deletions
diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h
index b2faecd..ccc7afb 100644
--- a/project2/common/scriptLoader.h
+++ b/project2/common/scriptLoader.h
@@ -8,16 +8,18 @@
#include <boost/shared_ptr.hpp>
#include "intrusivePtrBase.h"
#include "sourceObject.h"
+#include "scripts_fwd.h"
#include "exceptions.h"
#include <glibmm/ustring.h>
#include <map>
#include <vector>
-class ElementLoader;
class ComponentLoader;
class CommonObjects;
class Storer;
class ScriptReader;
+class SourceObject;
+typedef boost::intrusive_ptr<SourceObject> SourceObjectPtr;
class LoaderBase {
public:
@@ -90,7 +92,7 @@ class LoaderBase {
static ScriptNodePtr getSub(ScriptNodePtr root, const Glib::ustring & name, bool required);
Targets targets;
static unsigned int depth;
- template <class X> friend class ElementLoaderImpl;
+ friend class SourceObject;
static std::set<SourceObjectPtr> loadedObjects;
const bool recursive;
@@ -107,9 +109,11 @@ class LoaderBase {
#define DECLARE_CUSTOM_LOADER(N, T) \
DECLARE_CUSTOM_COMPONENT_LOADER(N, T, T, ElementLoader)
#define DECLARE_COMPONENT_LOADER(N, T, B) \
- DECLARE_CUSTOM_COMPONENT_LOADER(N, T, B##Impl<T>, B)
+ DECLARE_CUSTOM_COMPONENT_LOADER(N, T, B::For<T>, B)
#define DECLARE_LOADER(N, T) \
DECLARE_COMPONENT_LOADER(N, T, ElementLoader)
+#define DECLARE_GENERIC_LOADER(N, B, T) \
+ DECLARE_CUSTOM_COMPONENT_LOADER(N, T, B::For<T>, B);
/// Helper for loading and maintaining Project2 components
class Options;
@@ -123,22 +127,27 @@ class ComponentLoader {
virtual void onPeriodic(); // When the app engine feels like it
virtual const Options * options() const; // Options to be populated from the common config file/env/etc
};
-/// Helper for loading and maintaining Project2 script components
-class ElementLoader : public ComponentLoader {
- public:
- virtual SourceObjectPtr createFrom(ScriptNodePtr) const = 0;
-};
-/// Helper for loading and maintaining Project2 script components (typed implementation)
-template <class X>
-class ElementLoaderImpl : public ElementLoader {
+template <class Impl, typename... Params>
+class GenLoader : public ComponentLoader {
public:
- SourceObjectPtr createFrom(ScriptNodePtr sn) const
+ template <class T>
+ class For : public GenLoader<Impl, Params...> {
+ public:
+ inline Impl * create(const Params & ... p) const
+ {
+ return new T(p...);
+ }
+ };
+ virtual Impl * create(const Params & ...) const = 0;
+ inline static boost::shared_ptr<GenLoader<Impl, Params...>> getFor(const std::string & n)
{
- SourceObjectPtr sop = new X(sn);
- LoaderBase::loadedObjects.insert(sop);
- return sop;
+ return LoaderBase::getLoader<GenLoader<Impl, Params...>, NotSupported>(n);
}
};
+
+/// Helper for loading and maintaining Project2 script components
+typedef GenLoader<SourceObject, ScriptNodePtr> ElementLoader;
+
#endif