-
Notifications
You must be signed in to change notification settings - Fork 3
/
Parameter.cpp
78 lines (61 loc) · 1.51 KB
/
Parameter.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
#include "Parameter.h"
#include <algorithm>
namespace sargp {
Task::~Task() {
_command.deregisterTask(*this);
}
ParameterBase::ParameterBase(std::string const& argName, DescribeFunc const& describeFunc, Callback cb, ValueHintFunc const& hintFunc, Command& command, std::type_info const& _type_info)
: _argName{argName}
, _describeFunc{describeFunc}
, _cb{cb}
, _hintFunc{hintFunc}
, _command{command}
, type_info{_type_info}
{
_command.registerParameter(*this);
}
ParameterBase::~ParameterBase() {
_command.deregisterParameter(*this);
}
Command& Command::getDefaultCommand() {
static Command instance{Command::DefaultCommand{}};
return instance;
}
Command::Command(DefaultCommand)
{}
Command& getDefaultCommand() {
return Command::getDefaultCommand();
}
auto Command::findSubCommand(std::string const& subcommand) const -> Command const* {
for (auto sub : subcommands) {
if (sub->getName() == subcommand) {
return sub;
}
}
return nullptr;
}
auto Command::findSubCommand(std::string const& subcommand) -> Command* {
for (auto sub : subcommands) {
if (sub->getName() == subcommand) {
return sub;
}
}
return nullptr;
}
auto Command::findParameter(std::string const& parameter) const -> ParameterBase const* {
for (auto p : parameters) {
if (p->getArgName() == parameter) {
return p;
}
}
return nullptr;
}
auto Command::findParameter(std::string const& parameter) -> ParameterBase* {
for (auto p : parameters) {
if (p->getArgName() == parameter) {
return p;
}
}
return nullptr;
}
}