#ifndef PSEARCH_PATTERN_H_
#define PSEARCH_PATTERN_H_
#include "psearch_core.h"
namespace psearch {
/////////////////////////////////////////////////////////////////////////////////////////
// class Pattern
//
// Contains 3 set of associated nodes:
// o nodes defining the pattern's neccessairy and sufficient criteria (c1 nodes)
// o nodes defining the pattern's neccessairy criteria (c2 nodes; c2 includes c1 nodes.)
// o nodes explicitly excluded from pattern - negated nodes.
/////////////////////////////////////////////////////////////////////////////////////////
class Pattern: public PSBase
{
public:
inline Pattern(PSearchDB * db_p, index_type index):
PSBase(db_p, index),
m_weight(0),
m_c1_nodes(),
m_c2_nodes(),
m_negated_nodes(),
m_is_active(true),
m_rule_index()
{};
inline pattern_index_type
get_pattern_index()const
{
return this;
};
inline bool
is_active() const
{
return m_is_active;
};
inline unsigned int
get_weight() const
{
return m_weight;
};
// this consider only nodes (not negated_nodes)
inline bool
is_c1_node(node_index_type node_index)const
{
return m_c1_nodes.find(node_index) != m_c1_nodes.end();
};
// which includes c1 nodes.
inline bool
is_c2_node(node_index_type node_index)const
{
return m_c2_nodes.find(node_index) != m_c2_nodes.end();
};
// based on negated_node
inline bool
is_negated_by_node(node_index_type node_index)const
{
return m_negated_nodes.find(node_index) != m_negated_nodes.end();
};
inline node_const_iterator_type
get_c1_nodes_begin()const
{
return m_c1_nodes.begin();
};
inline node_const_iterator_type
get_c1_nodes_end()const
{
return m_c1_nodes.end();
};
inline node_set_const_iterator
get_c1_nodes_iterator()const
{
return node_set_const_iterator(get_c1_nodes_begin(), get_c1_nodes_end());
};
inline node_const_iterator_type
get_c2_nodes_begin()const
{
return m_c2_nodes.begin();
};
inline node_const_iterator_type
get_c2_nodes_end()const
{
return m_c2_nodes.end();
};
inline node_set_const_iterator
get_c2_nodes_iterator()const
{
return node_set_const_iterator(get_c2_nodes_begin(), get_c2_nodes_end());
};
inline node_const_iterator_type
get_negated_nodes_begin()const
{
return m_negated_nodes.begin();
};
inline node_const_iterator_type
get_negated_nodes_end()const
{
return m_negated_nodes.end();
};
inline node_set_const_iterator
get_negated_nodes_iterator()const
{
return node_set_const_iterator(get_negated_nodes_begin(), get_negated_nodes_end());
};
inline rule_index_type
get_rule_index()const
{
return m_rule_index;
};
protected:
inline void
set_active(bool b)
{
m_is_active = b;
};
inline void
set_weight(unsigned int weight)
{
m_weight = weight;
};
inline void
add_c1_node(node_index_type node_index)
{
if(!node_index) return;
m_c1_nodes.insert(node_index);
m_c2_nodes.insert(node_index);
};
inline void
add_c2_node(node_index_type node_index)
{
if(!node_index) return;
m_c2_nodes.insert(node_index);
};
inline void
add_negated_node(node_index_type node_index)
{
if(!node_index) return;
m_negated_nodes.insert(node_index);
};
inline void
remove_c1_node(node_index_type node_index)
{
m_c1_nodes.erase(node_index);
m_c2_nodes.erase(node_index);
};
inline void
remove_c2_node(node_index_type node_index)
{
m_c2_nodes.erase(node_index);
};
inline void
remove_negated_node(node_index_type node_index)
{
m_negated_nodes.erase(node_index);
};
inline void
remove_all_nodes()
{
m_c1_nodes.clear();
m_c2_nodes.clear();
m_negated_nodes.clear();
};
inline void
set_rule_index(rule_index_type rule_index)
{
m_rule_index = rule_index;
};
private:
friend class PSearchDB;
friend class Rule;
friend class Category;
friend std::ostream& operator<<(std::ostream& out, Pattern const& pattern);
friend std::ostream& operator<<(std::ostream& out, pattern_index_type pattern_index);
unsigned int m_weight;
node_set_type m_c1_nodes;
node_set_type m_c2_nodes;
node_set_type m_negated_nodes;
bool m_is_active;
rule_index_type m_rule_index;
};
inline std::ostream& operator<<(std::ostream& out, pattern_index_type pattern_index)
{
out << *pattern_index;
return out;
};
}; /* psearch namespace */
#endif /*PSEARCH_PATTERN_H_*/