summaryrefslogtreecommitdiff
path: root/project2/common/genLoader.h
blob: 2e4300bcf013ccd1d00f000ca38e77d47a131e7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef GENLOADER_H
#define GENLOADER_H

#include "componentLoader.h"
#include "plugable.h"

template <class Impl, class Key, typename... Params>
class GenLoader : public ComponentLoader {
	public:
		typedef Key KeyType;
		typedef GenLoader<Impl, KeyType, Params...> Self;

		template <class T, class BaseLoader = Self>
		class For : public BaseLoader {
			public:
				inline Impl * create(const Params & ... p) const
				{
					return new T(p...);
				}
		};

		virtual Impl * create(const Params & ...) const = 0;

		template <class E = NotSupported>
		inline static Impl * createNew(const KeyType & n, const Params & ... p)
		{
			return InstanceMap<Self, KeyType>::template Get<E>(n)->create(p...);
		}

		template <class E = NotSupported>
		inline static boost::shared_ptr<Self> getFor(const KeyType & n)
		{
			return InstanceMap<Self, KeyType>::template Get<E>(n);
		}
};

#endif