forked from 1flei/aws_alsh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
register.h
48 lines (37 loc) · 1.13 KB
/
register.h
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
#pragma once
#include <string>
#include <functional>
#include <map>
#include <iostream>
#include <boost/program_options.hpp>
#include <boost/any.hpp>
#include "util.h"
namespace MyCallbackRegister
{
struct AlgCallback{
std::string name;
std::vector<std::string> params;
std::function<void()> callback;
AlgCallback(const std::string &name, const std::string ¶mString, std::function<void()> callback)
:name(name), callback(callback){
std::istringstream ss(paramString);
std::string token;
while(ss>>token){
params.push_back(token);
}
}
};
//use ordered map to show in alphabetical order
extern std::map<std::string, AlgCallback> eventMap;
extern boost::program_options::variables_map vm;
bool registerCallback(const std::string &name, const std::string ¶ms, const std::function<void()> &callback);
void showAllRegisteredCallback();
void setvm(boost::program_options::variables_map& vm_);
void addArg(const std::string &name, const boost::any& anyArg);
void run(const std::string &name);
template<typename T>
T algAs(const std::string& name){
assert(vm.find(name)!=vm.end());
return vm[name].as<T>();
}
};