-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
43 lines (35 loc) · 1.08 KB
/
example.cpp
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
#include <iostream>
#include "include/sfath.h"
using namespace sfath;
struct Base {
virtual void print()=0;
};
struct D0: Base {
static Base *create_object() { std::cout << "do something" << std::endl; return new D0(); }
void print() { std::cout << "D0" << std::endl; }
};
struct D1: Base {
void print() { std::cout << "D1" << std::endl; }
};
struct D0p: Base {
static Base *create_object(int i) { return new D0p(i); }
D0p(int i): i_(i) {}
void print() { std::cout << "D0p. Saved number " << i_ << std::endl; }
int i_;
};
struct D1p: Base {
static Base *create_object(int i) { return new D1p(i); }
D1p(int i): i_(2*i) {}
void print() { std::cout << "D1p. Saved number " << i_ << std::endl; }
int i_;
};
typedef FactoryMethod<Base, TL::MakeTypelist<D0, D1>::Result > DFactory1;
typedef FactoryMethod<Base, TL::MakeTypelist<D0p, D1p>::Result, Base *(int) > DFactory2;
int main() {
DFactory1 &f1 = DFactory1::getInstance();
f1.createObj(0)()->print();
f1.createObj(1)()->print();
DFactory2 &f2 = DFactory2::getInstance();
f2.createObj(0)(3)->print();
f2.createObj(1)(3)->print();
}