NLLOGIC::CLogicConditionNode Class Reference

#include <logic_condition.h>


Detailed Description

CLogicConditionNode

Author:
Stephane Coutelas

Nevrax France

Date:
2001

Definition at line 187 of file logic_condition.h.

Public Types

enum  TConditionNodeType { TERMINATOR = 0, LOGIC_NODE }
 all condition node types More...


Public Member Functions

void addNode (CLogicConditionNode *node)
 CLogicConditionNode ()
void fillVarSet (std::set< std::string > &condVars)
void read (xmlNodePtr node)
void setLogicStateMachine (CLogicStateMachine *logicStateMachine)
bool testLogic ()
void write (xmlNodePtr node) const
 ~CLogicConditionNode ()

Data Fields

std::vector< CLogicConditionNode * > _Nodes
 condition nodes

CLogicConditionLogicBlock LogicBlock
 condition logic node

TConditionNodeType Type
 type of this condition node


Private Attributes

CLogicStateMachine_LogicStateMachine
 state machine managing this logic block


Member Enumeration Documentation

enum NLLOGIC::CLogicConditionNode::TConditionNodeType
 

all condition node types

Enumeration values:
TERMINATOR 
LOGIC_NODE 

Definition at line 195 of file logic_condition.h.

Referenced by read().

00196         {
00197                 TERMINATOR = 0, 
00198                 LOGIC_NODE
00199         };


Constructor & Destructor Documentation

NLLOGIC::CLogicConditionNode::CLogicConditionNode  )  [inline]
 

Default constructor

Definition at line 214 of file logic_condition.h.

References TERMINATOR.

Referenced by read().

00215         {
00216                 _LogicStateMachine = 0;
00217                 Type = TERMINATOR;
00218         }

NLLOGIC::CLogicConditionNode::~CLogicConditionNode  ) 
 

Destructor

Definition at line 507 of file logic_condition.cpp.

00508 {
00509         vector<CLogicConditionNode *>::iterator itNodes;
00510         for( itNodes = _Nodes.begin(); itNodes != _Nodes.end(); ++itNodes )
00511         {
00512                 delete (*itNodes);
00513         }
00514 
00515 } // ~CLogicConditionNode //


Member Function Documentation

void NLLOGIC::CLogicConditionNode::addNode CLogicConditionNode node  ) 
 

add a node in the subtree

Parameters:
node is the new node to add

Definition at line 325 of file logic_condition.cpp.

References setLogicStateMachine().

00326 {
00327         node->setLogicStateMachine( _LogicStateMachine );
00328         _Nodes.push_back( node );
00329 
00330 } // addToSubNodes //

void NLLOGIC::CLogicConditionNode::fillVarSet std::set< std::string > &  condVars  ) 
 

Fill a set with all the variables name referenced by this condition

Parameters:
condVars is a set to store the variable names

Definition at line 388 of file logic_condition.cpp.

References NLLOGIC::CLogicConditionLogicBlock::fillVarSet(), LOGIC_NODE, and LogicBlock.

00389 {
00390         if( Type == LOGIC_NODE )
00391         {
00392                 LogicBlock.fillVarSet( condVars );
00393         }
00394 
00395         vector<CLogicConditionNode *>::iterator itNode;
00396         for( itNode = _Nodes.begin(); itNode != _Nodes.end(); ++itNode )
00397         {
00398                 (*itNode)->fillVarSet( condVars );
00399         }
00400 
00401 } // fillVarSet //

void NLLOGIC::CLogicConditionNode::read xmlNodePtr  node  ) 
 

Definition at line 470 of file logic_condition.cpp.

References CLogicConditionNode(), NLLOGIC::getXMLProp(), LOGIC_NODE, LogicBlock, NLLOGIC::CLogicConditionLogicBlock::read(), TConditionNodeType, TERMINATOR, uint, v, and NLLOGIC::xmlCheckNodeName().

00471 {
00472         xmlCheckNodeName (node, "CONDITION_NODE");
00473 
00474         Type = (TConditionNodeType )atoi(getXMLProp (node, "Type").c_str());
00475         switch( Type )
00476         {
00477                 case TERMINATOR : break;
00478                 case LOGIC_NODE :
00479                 {
00480                         LogicBlock.read (node);
00481 
00482                         {
00483                                 // Count the parent
00484                                 uint nb = CIXml::countChildren (node, "CONDITION_NODE");
00485                                 uint i = 0;
00486                                 xmlNodePtr parent = CIXml::getFirstChildNode (node, "CONDITION_NODE");
00487                                 while (i<nb)
00488                                 {
00489                                         CLogicConditionNode *v = new CLogicConditionNode();
00490                                         v->read(parent);
00491                                         _Nodes.push_back (v);
00492 
00493                                         // Next parent
00494                                         parent = CIXml::getNextChildNode (parent, "CONDITION_NODE");
00495                                         i++;
00496                                 }
00497                         }
00498                 }
00499                 break;
00500         };
00501 }

void NLLOGIC::CLogicConditionNode::setLogicStateMachine CLogicStateMachine logicStateMachine  ) 
 

Set the logic state machine

Parameters:
logicStateMachine is the state machine containing this block

Definition at line 296 of file logic_condition.cpp.

References LogicBlock, nlwarning, and NLLOGIC::CLogicConditionLogicBlock::setLogicStateMachine().

Referenced by addNode().

00297 { 
00298         if( logicStateMachine == 0 )
00299         {
00300                 nlwarning("(LOGIC)<CLogicConditionNode::setLogicStateMachine> The state machine is null");
00301         }
00302         else
00303         {
00304                 // set the state machine of this node
00305                 _LogicStateMachine = logicStateMachine; 
00306 
00307                 // set the state machine of the logic block 
00308                 LogicBlock.setLogicStateMachine( logicStateMachine );
00309                 
00310                 // set the state machine for the sub nodes
00311                 vector<CLogicConditionNode *>::iterator itNodes;
00312                 for( itNodes = _Nodes.begin(); itNodes != _Nodes.end(); ++itNodes )
00313                 {
00314                         (*itNodes)->setLogicStateMachine( logicStateMachine );
00315                 }
00316         }
00317 
00318 } // setLogicStateMachine //

bool NLLOGIC::CLogicConditionNode::testLogic  ) 
 

Test the condition

Returns:
true if this condition is fulfiled, false else

Definition at line 337 of file logic_condition.cpp.

References NLLOGIC::CLogicConditionLogicBlock::isNotBlock(), LogicBlock, and NLLOGIC::CLogicConditionLogicBlock::testLogic().

00338 {
00339         // test the logic block
00340         if( LogicBlock.testLogic() == false )
00341         {
00342                 return false;
00343         }
00344 
00345         // if there's no subtree we assess the subtree is true
00346         if( _Nodes.size() == 0 )
00347         {
00348                 return true;
00349         }
00350 
00351         // test the subtree
00352         if( LogicBlock.isNotBlock() )
00353         {
00354                 // the subtree is false if at least one node is true
00355                 vector<CLogicConditionNode *>::iterator itNodes;
00356                 for( itNodes = _Nodes.begin(); itNodes != _Nodes.end(); ++itNodes )
00357                 {
00358                         if( (*itNodes)->testLogic() == true )
00359                         {
00360                                 return false;
00361                         }
00362                 }
00363 
00364                 return true;
00365         }
00366         else
00367         {
00368                 // the subtree is true if at least one node is true
00369                 vector<CLogicConditionNode *>::iterator itNodes;
00370                 for( itNodes = _Nodes.begin(); itNodes != _Nodes.end(); ++itNodes )
00371                 {
00372                         if( (*itNodes)->testLogic() == true )
00373                         {
00374                                 return true;
00375                         }
00376                 }
00377 
00378                 return false;
00379         }
00380 
00381 } // testLogic //

void NLLOGIC::CLogicConditionNode::write xmlNodePtr  node  )  const
 

Definition at line 449 of file logic_condition.cpp.

References LOGIC_NODE, LogicBlock, TERMINATOR, uint32, and NLLOGIC::CLogicConditionLogicBlock::write().

00450 {
00451         xmlNodePtr elmPtr = xmlNewChild ( node, NULL, (const xmlChar*)"CONDITION_NODE", NULL);
00452         xmlSetProp (elmPtr, (const xmlChar*)"Type", (const xmlChar*)toString((uint32)Type).c_str());
00453 
00454         switch( Type )
00455         {
00456                 case TERMINATOR : break;
00457                 case LOGIC_NODE :
00458                 {
00459                         LogicBlock.write(elmPtr);
00460                         vector<CLogicConditionNode *>::const_iterator itNode = _Nodes.begin();
00461                         for( ; itNode != _Nodes.end(); ++itNode )
00462                         {
00463                                 (*itNode)->write(elmPtr);
00464                         }
00465                 }
00466                 break;
00467         };
00468 }


Field Documentation

CLogicStateMachine* NLLOGIC::CLogicConditionNode::_LogicStateMachine [private]
 

state machine managing this logic block

Definition at line 190 of file logic_condition.h.

std::vector<CLogicConditionNode *> NLLOGIC::CLogicConditionNode::_Nodes
 

condition nodes

Definition at line 209 of file logic_condition.h.

CLogicConditionLogicBlock NLLOGIC::CLogicConditionNode::LogicBlock
 

condition logic node

Definition at line 206 of file logic_condition.h.

Referenced by fillVarSet(), read(), setLogicStateMachine(), testLogic(), and write().

TConditionNodeType NLLOGIC::CLogicConditionNode::Type
 

type of this condition node

Definition at line 202 of file logic_condition.h.


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 12:53:22 2004 for NeL by doxygen 1.3.6