/
create_component.cpp
85 lines (60 loc) · 2.03 KB
/
create_component.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
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
80
81
82
83
84
85
#include <iostream>
#include <iomanip>
#include <string>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
void output_interface(const std::string& name){
boost::uuids::random_generator r;
auto u = r();
std::cout << "struct " << name << "{\n";
std::cout << "\t// {" << std::uppercase << u << "}" << std::endl;
std::cout << "\t typedef cppcomponents::uuid<\n";
std::cout << "\t";
int counter = 0;
for(auto k:u){
if(counter==0)
std::cout << "0x";
if(counter==4)
std::cout << ",0x";
if(counter==6)
std::cout << ",0x";
if(counter==8)
std::cout << ",0x";
if(counter>8)
std::cout << ",0x";
++counter;
std::cout<< std::setw(2) << std::setfill('0') << std::hex << (unsigned int)k;
}
std::cout << std::endl;
std::cout << "\t> uuid;";
std::cout << "\n\t";
std::cout << "\n\n\n\n\n";
std::cout << "\t" << "CPPCOMPONENTS_CONSTRUCT(" << name << ",);\n\n\n};\n";
}
int main(int argc, char** argv){
std::string name;
std::string options;
if(argc > 1){
name = argv[1];
}
if(argc > 2){
options = argv[2];
}
if(name.size() == 0) name="TestComponent";
output_interface("Interface" + name);
if(options.find('f')==std::string::npos){
std::cout << "typedef cppcomponents::DefaultFactoryInterface " << name << "FactoryInterface;\n\n";
}else{
output_interface(name + "FactoryInterface");
}
if(options.find('s')==std::string::npos){
std::cout << "typedef cppcomponents::static_interfaces<> " << name << "StaticInterface;\n\n";
}else{
output_interface(name + "StaticInterface");
}
std::cout << "inline std::string " << name << "ComponentName(){return \"" << name << "\";}\n\n";
std::cout << "typedef cppcomponents::runtime_class<" << name << "ComponentName" << "," << "Interface"
<< name << "," << name << "FactoryInterface," << name << "StaticInterface>\n" << name << "_t;" << "\n";
std::cout << "typedef cppcomponents::use_runtime_class<" << name << "_t> " << name << ";\n";
}