start on CommandMap::get_command()
This commit is contained in:
parent
25806993f9
commit
a07e9eb46b
@ -32,7 +32,53 @@ void CommandMap::add(const char * s, uint32_t id,
|
||||
node->next_map = next_map;
|
||||
}
|
||||
|
||||
std::shared_ptr<Command> CommandMap::get_command(uint32_t * command_characters, uint32_t count)
|
||||
std::shared_ptr<Command> CommandMap::get_command(uint32_t * command_characters,
|
||||
uint32_t length) const
|
||||
{
|
||||
if (length < 1u)
|
||||
return nullptr;
|
||||
const Node * node = &m_root_node;
|
||||
bool in_motion = false;
|
||||
Command command;
|
||||
for (size_t i = 0u; i < length; i++)
|
||||
{
|
||||
uint32_t c = command_characters[i];
|
||||
auto it = node->next_chars.find(c);
|
||||
if (it != node->next_chars.end())
|
||||
{
|
||||
node = &*it->second;
|
||||
if (node->flags & Node::FLAG_TERMINATOR)
|
||||
{
|
||||
if (in_motion)
|
||||
command.motion.id = node->id;
|
||||
else
|
||||
command.id = node->id;
|
||||
if (node->flags & Node::FLAG_FOLLOWING_CHAR)
|
||||
{
|
||||
if (i < (length - 1u))
|
||||
{
|
||||
if (in_motion)
|
||||
command.motion.following_char = command_characters[i + 1u];
|
||||
else
|
||||
command.following_char = command_characters[i + 1u];
|
||||
return std::make_shared<Command>(command);
|
||||
}
|
||||
}
|
||||
else if (node->next_map)
|
||||
{
|
||||
in_motion = true;
|
||||
node = &node->next_map->m_root_node;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::make_shared<Command>(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ class CommandMap
|
||||
public:
|
||||
void add(const char * s, uint32_t id, std::shared_ptr<CommandMap> next_map,
|
||||
bool following_char);
|
||||
std::shared_ptr<Command> get_command(uint32_t * command_characters, uint32_t count);
|
||||
std::shared_ptr<Command> get_command(uint32_t * command_characters,
|
||||
uint32_t length) const;
|
||||
|
||||
protected:
|
||||
struct Node
|
||||
|
Loading…
x
Reference in New Issue
Block a user