Modules work based on structures
This commit is contained in:
parent
2720ffdf19
commit
d8c2aafaa3
|
@ -10,9 +10,8 @@
|
|||
int main(int argc, const char* argv[]) {
|
||||
using namespace boost::program_options;
|
||||
using namespace std;
|
||||
std::map<string, Module> lmodules;
|
||||
modules::init::_mod init;
|
||||
lmodules["init"] = init;
|
||||
std::map<string, Module*> lmodules;
|
||||
lmodules["init"] = new modules::init::_mod;
|
||||
|
||||
try {
|
||||
options_description general("General Options");
|
||||
|
@ -44,7 +43,7 @@ int main(int argc, const char* argv[]) {
|
|||
exit(1);
|
||||
}
|
||||
auto module = lmodules[name];
|
||||
std::cout << module._desc << "\n";
|
||||
std::cout << module->_desc << "\n";
|
||||
}
|
||||
else if (vm.count("module")) {
|
||||
auto name = vm["module"].as<string>();
|
||||
|
@ -60,7 +59,7 @@ int main(int argc, const char* argv[]) {
|
|||
args = vm["module-args"].as<string>();
|
||||
|
||||
if (args != "")
|
||||
module._dispatcher(args);
|
||||
module->dispatch(args);
|
||||
}
|
||||
else {
|
||||
std::cout << general << "\n";
|
||||
|
|
17
src/module.h
17
src/module.h
|
@ -12,22 +12,21 @@
|
|||
#define MODFNIMPL(name, code) \
|
||||
void name(std::string arguments) {code}
|
||||
|
||||
#define MODDISPATCHFN(name, code) \
|
||||
void name(std::string arguments) {code}
|
||||
#define MODDISPATCHFNSIG(name) \
|
||||
void name(std::string arguments);
|
||||
#define MODDISPATCHFNIMPL(name, code) \
|
||||
void name(std::string arguments) {code}
|
||||
#define MODDISPATCHFNSIG() \
|
||||
virtual void dispatch(std::string arguments) = 0;
|
||||
#define MODDISPATCHFNIMPL(code) \
|
||||
void _mod::dispatch(std::string arguments) {code}
|
||||
#define MODDISPATCHFN() \
|
||||
void dispatch(std::string arguments) override;
|
||||
|
||||
#define MODARGS(code) \
|
||||
struct _args {code}
|
||||
#define MAKEMOD(code) \
|
||||
struct _mod : _args, Module {code}
|
||||
#define DEFMOD(name, desc, dispatcher) \
|
||||
#define DEFMOD(name, desc) \
|
||||
_mod() { \
|
||||
this->_name = name; \
|
||||
this->_desc = desc; \
|
||||
this->_dispatcher = dispatcher; \
|
||||
} \
|
||||
|
||||
using ModuleFn = std::function<void(std::string arguments)>;
|
||||
|
@ -37,7 +36,7 @@ struct Module {
|
|||
std::string _name;
|
||||
std::string _desc;
|
||||
std::map<std::string, ModuleFn> _funcs;
|
||||
ModuleFnDispatcher _dispatcher;
|
||||
MODDISPATCHFNSIG();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,8 +6,7 @@ namespace modules {
|
|||
MODFNIMPL(init_create, {
|
||||
std::cout << "CREATE";
|
||||
});
|
||||
|
||||
MODDISPATCHFNIMPL(init__dispatch, {
|
||||
MODDISPATCHFNIMPL({
|
||||
std::cout << arguments;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,13 +8,12 @@ namespace modules {
|
|||
MODARGS(
|
||||
std::string _location;
|
||||
);
|
||||
MODDISPATCHFNSIG(init__dispatch);
|
||||
MAKEMOD(MODFNSIG(init__create);
|
||||
MODDISPATCHFN();
|
||||
DEFMOD("init",
|
||||
"Creates a skidjular directory in $(pwd)");
|
||||
);
|
||||
|
||||
MODFNSIG(init__create);
|
||||
|
||||
MAKEMOD(DEFMOD("init",
|
||||
"Creates a skidjular directory in $(pwd)",
|
||||
init__dispatch));
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue