#include "condition_nodes.hpp" //TODO obezlicka #define null 0 #include // node base CNodeBase::CNodeBase() { } // node base CNodeBase::~CNodeBase() { } bool CNodeBase::GetValue() { return m_value; } void CNodeBase::SetParent(CNodeBase* parent) { m_parent = parent; return; } // AND node CNodeAnd::CNodeAnd(CNodeBase* lchld, CNodeBase* rchld) : m_lchild(lchld), m_rchild(rchld) { } CNodeAnd::~CNodeAnd() { delete m_lchild; delete m_rchild; } void CNodeAnd::Reevaluate() { bool new_value = m_lchild->GetValue() && m_rchild->GetValue(); if(m_value != new_value) { m_value = new_value; assert(m_parent != null); m_parent->Reevaluate(); } return; } // OR node CNodeOr::CNodeOr(CNodeBase* lchld, CNodeBase* rchld) : m_lchild(lchld), m_rchild(rchld) { } CNodeOr::~CNodeOr() { delete m_lchild; delete m_rchild; } void CNodeOr::Reevaluate() { bool new_value = m_lchild->GetValue() || m_rchild->GetValue(); if(m_value != new_value) { m_value = new_value; assert(m_parent != null); m_parent->Reevaluate(); } return; } // NOT node CNodeNot::CNodeNot(CNodeBase* chld) : m_child(chld), m_first(false) { } CNodeNot::~CNodeNot() { delete m_child; } void CNodeNot::Reevaluate() { bool new_value = !m_child->GetValue(); //if(m_first || (m_value != new_value)) { if((m_value != new_value)) { m_first = false; m_value = new_value; assert(m_parent != null); m_parent->Reevaluate(); } return; } // ELEM node void CElement::SetValue(bool val) { m_value = val; m_parent->Reevaluate(); } void CElement::Reevaluate() { assert(false); //leaf nodes are not reevaluated! return; }