1
0
Fork 0

name matching is protected, and not virtual

This commit is contained in:
Kevin Matz 2023-05-15 11:18:28 -04:00
parent 0c22c70b38
commit 6853a2af5c
2 changed files with 26 additions and 24 deletions

View File

@ -96,26 +96,6 @@ bool Method::setName(std::string name)
}
/**
* @brief Method::matchesName
* @param name
* @return
*/
bool Method::matchesName(std::string &name) const
{
// try to optimize matches before resorting to expensive pattern matching
if (name == name_)
return true; // exact match
if (name.empty())
return false; // reject non-exact nulls
if (name == "*")
return true; // wildcard match
std::regex re(name);
return std::regex_match(name_, re); // regex match
}
/**
* @brief Method::isContainer
* @return
@ -144,9 +124,9 @@ bool Method::dispatch(std::list<std::string> patterns, const std::shared_ptr<Mes
{
if (isContainer()) // containters cannot be leafs
return false;
if (matchesName(name)) // accept the message
if (matchName(name)) // accept the message
{
trigger(msg); // pass it along
trigger(msg); // activate method
return true;
}
}
@ -154,7 +134,7 @@ bool Method::dispatch(std::list<std::string> patterns, const std::shared_ptr<Mes
{
if (!isContainer()) // no children to match to
return false;
if (matchesName(name)) // accept pattern
if (matchName(name)) // accept pattern
{
for (const auto &child: children_) // offer the remaining patterns to children
child->dispatch(std::list<std::string>(patterns), msg);
@ -206,6 +186,28 @@ void Method::trigger(std::shared_ptr<Message> msg) const
}
/**
* @brief Method::matchName
* @param pattern
* @return
*/
bool Method::matchName(const std::string &pattern) const
{
// try to optimize matches before resorting to expensive regex matching
if (isRoot())
return true; // root method matches everything
if (name_.compare(pattern) == 0)
return true; // exact match
if (pattern.empty())
return false; // reject non-exact nulls
if (pattern == "*")
return true; // wildcard match
std::regex re(pattern);
return std::regex_match(name_, re); // regex match
}
/**
* @brief Method::isRoot
* @return

View File

@ -47,7 +47,6 @@ public:
std::string address() const;
std::string name() const;
bool setName(std::string name);
virtual bool matchesName(std::string &name) const;
bool isContainer() const;
bool dispatch(std::list<std::string> patterns, const std::shared_ptr<Message> msg) const;
@ -56,6 +55,7 @@ public:
protected:
void trigger(std::shared_ptr<Message>) const;
bool matchName(std::string &pattern) const;
bool isRoot() const;
private: