6663b6c9
adorian
projet complet av...
|
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
|
#include "command_handler.h"
#include <string.h>
namespace Ion {
namespace Device {
namespace Bench {
bool CommandHandler::valid() const {
return (m_name != nullptr && m_function != nullptr);
}
bool CommandHandler::handle(const char * command) const {
if (matches(command)) {
size_t nameLength = strlen(m_name);
if (command[nameLength] == '=') {
m_function(command+nameLength+1); // Skip the "Equal character"
} else {
m_function(nullptr);
}
return true;
}
return false;
}
bool CommandHandler::matches(const char * command) const {
const char * c = command;
const char * n = m_name;
while (true) {
if (*n == NULL) {
if (*c == NULL || *c == '=') {
return true;
}
}
if (*c != *n) {
return false;
}
c++;
n++;
}
}
}
}
}
|