-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtension.hpp
More file actions
80 lines (63 loc) · 2.44 KB
/
Extension.hpp
File metadata and controls
80 lines (63 loc) · 2.44 KB
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
72
73
74
75
76
77
78
79
#ifndef ___FCF__PARALLEL__EXTENSION_HPP___
#define ___FCF__PARALLEL__EXTENSION_HPP___
#include <memory>
#include <map>
#include <set>
#include "macro.hpp"
#include "include.hpp"
namespace fcf {
namespace Parallel {
class Extension;
class BaseEngine;
namespace Details {
FCF_PARALLEL_DELC_EXTERN FCF_PARALLEL_DECL_EXPORT std::map<std::string, Extension*(*)()> __fcf_parallel_extensions;
template <typename Ty>
Extension* createExtension(){
return new Ty();
}
} // Details namespace
class FCF_PARALLEL_DECL_EXPORT Extension {
public:
virtual ~Extension();
struct PrepareCodeInfo {
BaseEngine* engine;
size_t deviceIndex;
std::list< std::pair<std::string, std::string> > functions;
std::string prefix;
std::string body;
std::string suffix;
std::string code;
};
virtual void prepareCode(const Union& a_options, PrepareCodeInfo& a_info) = 0;
template <typename Ty>
static void add(const std::string& a_name) {
Details::__fcf_parallel_extensions[a_name] = Details::createExtension<Ty>;
}
static std::shared_ptr<Extension> create(const std::string& a_name);
};
#ifdef FCF_PARALLEL_IMPLEMENTATION
Extension::~Extension(){
}
#endif // #ifdef FCF_PARALLEL_IMPLEMENTATION
#ifdef FCF_PARALLEL_IMPLEMENTATION
std::shared_ptr<Extension> Extension::create(const std::string& a_name){
auto it = Details::__fcf_parallel_extensions.find(a_name);
if (it == Details::__fcf_parallel_extensions.end()) {
throw std::runtime_error(std::string() + "Extension with the name '" + a_name + "' is not available");
}
return std::shared_ptr<Extension>(it->second());
}
#endif // #ifdef FCF_PARALLEL_IMPLEMENTATION
struct ExtensionInfo {
std::shared_ptr<Extension> extension;
Union options;
};
template <typename Ty>
struct ExtensionRegistrator {
ExtensionRegistrator(const char* a_name) {
Extension::add<Ty>(a_name);
}
};
} // Parallel namespace
} // fcf namespace
#endif // #ifndef ___FCF__PARALLEL__EXTENSION_HPP___