blob: a27591dc43321255ddbbf55ae64b43bc64b0d48f (
plain) (
blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#ifndef REGISTER_IMPLEMENT_H_
#define REGISTER_IMPLEMENT_H_
#include <map>
#include <vector>
namespace meow{
template<class T>
class ImplementInterface{
private:
T identify_;
protected:
ImplementInterface(T const& id): identify_(id) { }
public:
T const& identify() const { return identify_; }
virtual ~ImplementInterface(){ }
};
//
template<class T>
class RegisterInterface{
private:
std::map<T, ImplementInterface<T>*> implements;
protected:
RegisterInterface();
public:
virtual bool regImplement(ImplementInterface<T>*imp);
virtual ImplementInterface<T>* getImplement(T const& identify);
virtual ~RegisterInterface(){ }
std::vector<T> getIdentifys() const;
};
//#
//# === meow:: *ImplementInterface/RegisterInterface* (C++ Class)
//# ==== Description
//# Assume there is a problem which can be solved by different algorithms.
//# Then you can write multiple classes to approach this problem. +
//# Now if you want to decide which algorithm to use in runtime, you can just
//# approach this case by a simple way:
//#
//# * Let all the problem-solving classes inherit from
//# `class ImplementInterface<T>` , and call the constructure with giving
//# `identify` (type `T` ) .
//# * Create an class inherit from `RegisterInterface<T>` ,
//# and register all your implement class to it by call
//# `regImplement(pointer to the class)`.
//# * Select which implement class you want by call
//# `getImplement(identify)` , which will return the pointer
//# to the corresponding class.
//#
//# '''
//#
}
#include "Register_Implement.hpp"
#endif // REGISTER_IMPLEMENT_H_
|