From 66341d5717f5d7d5e5bce45504cfc7dcd57ab19f Mon Sep 17 00:00:00 2001 From: Guglielmo Boi Date: Wed, 3 Apr 2024 14:35:55 +0200 Subject: [PATCH] fix: TopicNode incomplete type --- src/templates/message_parser.cpp.j2 | 32 ++++++++++++++--------------- src/templates/message_parser.h.j2 | 10 ++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/templates/message_parser.cpp.j2 b/src/templates/message_parser.cpp.j2 index c0ceb61..e337e58 100644 --- a/src/templates/message_parser.cpp.j2 +++ b/src/templates/message_parser.cpp.j2 @@ -26,15 +26,15 @@ void MessageParser::TopicNode::addNode(const std::string& topic) { auto iter = this->adjacent.find(subTopic); if(iter == this->adjacent.end()) { - iter = this->adjacent.emplace(subTopic, TopicNode()).first; + iter = this->adjacent.emplace(subTopic, std::make_unique(TopicNode())).first; } if(slash != topic.end()) { - iter->second.addNode(std::string(slash + 1, topic.end())); + iter->second->addNode(std::string(slash + 1, topic.end())); } } -MessageParser::TopicNode* MessageParser::TopicNode::findNode(const std::string& topic) { +std::unique_ptr* MessageParser::TopicNode::findNode(const std::string& topic) { auto slash = std::find(topic.begin(), topic.end(), '/'); std::string subTopic = std::string(topic.begin(), slash); @@ -47,18 +47,18 @@ MessageParser::TopicNode* MessageParser::TopicNode::findNode(const std::string& if(slash == topic.end()) { return &(iter->second); } else { - return iter->second.findNode(std::string(slash + 1, topic.end())); + return iter->second->findNode(std::string(slash + 1, topic.end())); } } -std::vector MessageParser::TopicNode::findNodesVariables(const std::string& topic, const Variables& variables) { - std::vector ret; +std::vector*> MessageParser::TopicNode::findNodesVariables(const std::string& topic, const Variables& variables) { + std::vector*> ret; this->findNodesVariablesRec(topic, variables, false, ret); return ret; } -void MessageParser::TopicNode::findNodesVariablesRec(const std::string& topic, const Variables& variables, bool hashtag, std::vector& ret) { +void MessageParser::TopicNode::findNodesVariablesRec(const std::string& topic, const Variables& variables, bool hashtag, std::vector*>& ret) { auto slash = std::find(topic.begin(), topic.end(), '/'); std::string subTopic = std::string(topic.begin(), slash); @@ -69,7 +69,7 @@ void MessageParser::TopicNode::findNodesVariablesRec(const std::string& topic, c if(hashtag) { for(auto& next : this->adjacent) { ret.push_back(&(next.second)); - next.second.findNodesVariablesRec("", variables, hashtag, ret); + next.second->findNodesVariablesRec("", variables, hashtag, ret); } } else { for(auto& next : this->adjacent) { @@ -87,7 +87,7 @@ void MessageParser::TopicNode::findNodesVariablesRec(const std::string& topic, c if(slash == topic.end()) { ret.push_back(&(next.second)); } else { - next.second.findNodesVariablesRec(std::string(slash + 1, topic.end()), variables, hashtag, ret); + next.second->findNodesVariablesRec(std::string(slash + 1, topic.end()), variables, hashtag, ret); } } } @@ -96,30 +96,30 @@ void MessageParser::TopicNode::findNodesVariablesRec(const std::string& topic, c MessageParser::MessageParser() { {% for topic in topics -%} - this->tree.addNode("{{ topic['topic'] }}"); + this->tree->addNode("{{ topic['topic'] }}"); {%- if not loop.last%} {%endif -%} {%- endfor %} } void MessageParser::setMessageParse(Topic topic, parse_t parse, void* argument) { - auto node = this->tree.findNode(GetTopic(topic).topic); + auto node = this->tree->findNode(GetTopic(topic).topic); if(node != nullptr) { - node->parse = std::make_unique(parse); + (*node)->parse = std::make_unique(parse); if(argument != nullptr) { - node->argument = argument; + (*node)->argument = argument; } } } void MessageParser::parseMessage(const Variables& variables, const std::string& topic, const std::string& payload) { - auto nodes = this->tree.findNodesVariables(topic, variables); + auto nodes = this->tree->findNodesVariables(topic, variables); for(auto& node : nodes) { - if(node->parse != nullptr) { - (*node->parse)(payload, node->argument); + if((*node)->parse != nullptr) { + (*(*node)->parse)(payload, (*node)->argument); } } } diff --git a/src/templates/message_parser.h.j2 b/src/templates/message_parser.h.j2 index 151804e..ede8a31 100644 --- a/src/templates/message_parser.h.j2 +++ b/src/templates/message_parser.h.j2 @@ -35,12 +35,12 @@ private: { std::unique_ptr parse; void* argument = nullptr; - std::unordered_map adjacent; + std::unordered_map> adjacent; void addNode(const std::string& topic); - TopicNode* findNode(const std::string& topic); - std::vector findNodesVariables(const std::string& topic, const Variables& variables); - void findNodesVariablesRec(const std::string& topic, const Variables& variables, bool hashtag, std::vector& ret); + std::unique_ptr* findNode(const std::string& topic); + std::vector*> findNodesVariables(const std::string& topic, const Variables& variables); + void findNodesVariablesRec(const std::string& topic, const Variables& variables, bool hashtag, std::vector*>& ret); }; public: @@ -50,7 +50,7 @@ public: void parseMessage(const Variables& variables, const std::string& topic, const std::string& payload); private: - MessageParser::TopicNode tree; + std::unique_ptr tree; }; }