forked from lffpires/funcperf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IFunctionTest.hpp
71 lines (56 loc) · 1.19 KB
/
IFunctionTest.hpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include "ITest.hpp"
#include <iostream>
#include <map>
#include <memory>
#include <vector>
namespace funcperf {
class IFunctionTest
{
public:
virtual ~IFunctionTest() = default;
void setLength(TestLength len)
{
this->len = len;
}
virtual std::string headers() const = 0;
virtual ITest* nextTest() = 0;
std::string sep;
protected:
TestLength len;
};
class FunctionTestFactory
{
public:
static FunctionTestFactory& instance()
{
static FunctionTestFactory _instance;
return _instance;
}
std::unique_ptr<IFunctionTest>
getFTest(const std::string& id)
{
auto it = _funcs.find(id);
if (it == _funcs.end())
return nullptr;
return std::unique_ptr<IFunctionTest>((*it->second)());
}
void registerFunction(const std::string& name,
IFunctionTest* (*factory)())
{
_funcs[name] = factory;
}
std::vector<std::string> ids() const
{
std::vector<std::string> vec;
for (const auto& p : _funcs)
vec.push_back(p.first);
return vec;
}
private:
FunctionTestFactory() = default;
FunctionTestFactory(const FunctionTestFactory&) = delete;
FunctionTestFactory& operator=(const FunctionTestFactory&) = delete;
std::map<std::string, IFunctionTest* (*)()> _funcs;
};
}