22 #ifndef __M2ETIS_PUBSUB_FILTER_DECISIONTREE_ATTRIBUTEDECISIONTREENODE_H__
23 #define __M2ETIS_PUBSUB_FILTER_DECISIONTREE_ATTRIBUTEDECISIONTREENODE_H__
30 #include "boost/shared_ptr.hpp"
39 template<
typename EventType,
typename NetworkType>
class DecisionTreePreProcessVisitor;
44 template<
typename EventType,
typename NetworkType,
typename AttributeType>
53 virtual void visit(
const EventType & event, std::set<typename NetworkType::Key> & matching_subscribers)
override {
55 auto attribute_value_iterator = attributes_accessor_map.find(attribute_id_);
57 if (attribute_value_iterator == attributes_accessor_map.end()) {
58 M2ETIS_THROW_API(
"AttributeDecisionTreeNode function visit",
"Attribute not found in attribute map.");
65 if (result_subnode_iterator != result_subnodes_.end()) {
67 result_subnode_iterator->second->visit(event, matching_subscribers);
70 if (dont_care_subnode_ptr_) {
71 dont_care_subnode_ptr_->visit(event, matching_subscribers);
79 if (other_tree_node->dont_care_subnode_ptr_) {
80 if (dont_care_subnode_ptr_) {
82 dont_care_subnode_ptr_->merge(other_tree_node->dont_care_subnode_ptr_, subscriber);
84 dont_care_subnode_ptr_ = other_tree_node->dont_care_subnode_ptr_;
85 dont_care_subnode_ptr_->changeSubscriber(subscriber);
90 for (
auto other_tree_node_subnodes : other_tree_node->result_subnodes_) {
91 if (result_subnodes_.find(other_tree_node_subnodes.first) != result_subnodes_.end()) {
94 result_subnodes_[other_tree_node_subnodes.first]->merge(other_tree_node_subnodes.second, subscriber);
96 result_subnodes_[other_tree_node_subnodes.first] = other_tree_node_subnodes.second;
97 result_subnodes_[other_tree_node_subnodes.first]->changeSubscriber(subscriber);
103 for (
auto subnodes : result_subnodes_) {
104 subnodes.second->changeSubscriber(subscriber);
107 if (dont_care_subnode_ptr_) {
108 dont_care_subnode_ptr_->changeSubscriber(subscriber);
114 for (
auto subnodes : result_subnodes_) {
115 subnodes.second->removeSubscriber(subscriber);
118 if (dont_care_subnode_ptr_) {
119 dont_care_subnode_ptr_->removeSubscriber(subscriber);
125 bool hasSubscriptionResult =
false;
126 for (
auto subnodes : result_subnodes_) {
127 hasSubscriptionResult = hasSubscriptionResult
128 || subnodes.second->hasSubscription(subscriber);
131 if (dont_care_subnode_ptr_) {
132 hasSubscriptionResult = hasSubscriptionResult
133 || dont_care_subnode_ptr_->hasSubscription(subscriber);
136 return hasSubscriptionResult;
139 virtual operator std::string()
const {
140 std::string temp =
"attribute node with attribute_id: " + std::to_string(attribute_id_) +
"subnodes:";
141 for (
auto subnodes : result_subnodes_) {
142 temp +=
"edge: with value (not computable) next node:" + std::string(*(subnodes.second));
154 std::map<AttributeType, boost::shared_ptr<DecisionTreeNode<EventType, NetworkType> > > result_subnodes_;
159 boost::shared_ptr<DecisionTreeNode<EventType, NetworkType> > dont_care_subnode_ptr_;
161 AttributeName attribute_id_;
164 template<
typename Archive>
165 void serialize(Archive & ar,
const unsigned int version) {
166 ar & boost::serialization::base_object<DecisionTreeNode<EventType, NetworkType> >(*this);
167 ar & result_subnodes_;
168 ar & dont_care_subnode_ptr_;
AttributeDecisionTreeNode(AttributeName attribute_id)
virtual void merge(boost::shared_ptr< DecisionTreeNode< EventType, NetworkType > > &other_tree, typename NetworkType::Key subscriber) override
virtual ~AttributeDecisionTreeNode()
AttributeDecisionTreeNode()
virtual void changeSubscriber(typename NetworkType::Key subscriber) override
M2ETIS_API std::map< filter::AttributeName, std::shared_ptr< filter::AttributeAccessor_Basic > > attributes_accessor_map
virtual void visit(const EventType &event, std::set< typename NetworkType::Key > &matching_subscribers) override
virtual bool hasSubscription(typename NetworkType::Key subscriber) override
virtual void removeSubscriber(const typename NetworkType::Key &subscriber) override
#define M2ETIS_THROW_API(module, message)
throws on wrong API usage
friend class boost::serialization::access