summaryrefslogtreecommitdiff
path: root/project2/common/genLoader.h
blob: e5ff43ea653182efc390c9b4263d0a7c37a682d6 (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
#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;

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

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

#endif