prop_logic_event.cpp
Go to the documentation of this file.
00001 
00025 #include <predicate_manager/prop_logic_event.h>
00026 
00027 #include <ros/ros.h>
00028 
00029 using namespace std;
00030 using namespace predicate_manager;
00031 
00032 
00033 PropLogicEvent::
00034 PropLogicEvent ( const string& name,
00035                  const PropLogic& pl ) :
00036     Event ( name ),
00037     prop_logic_ ( pl.clone() ),
00038     val_ ( false )
00039 {
00040     declareAllDependencies();
00041 }
00042 
00043 PropLogicEvent::
00044 PropLogicEvent ( const string& name ) :
00045     Event ( name ),
00046     prop_logic_ (),
00047     val_ ( false )
00048 {}
00049 
00050 void
00051 PropLogicEvent::
00052 bindPropLogic ( const PropLogic& pl )
00053 {
00054     if ( prop_logic_ != 0 )
00055     {
00056         ROS_ERROR_STREAM ( "Overwriting the Propositional Logic formula associated with event " << getName() );
00057     }
00058     prop_logic_ = pl.clone();
00059     declareAllDependencies();
00060 
00061     update();
00062 }
00063 
00064 void
00065 PropLogicEvent::
00066 update()
00067 {
00068     if ( prop_logic_ != 0 )
00069     {
00070         bool val = prop_logic_->evaluate ( boost::bind ( &PropLogicEvent::evaluate,this,_1 ) );
00071         if ( val && !val_ )
00072             triggerEvent(); 
00073 
00074         val_ = val;
00075     }
00076 }
00077 
00078 void
00079 PropLogicEvent::
00080 declareAllDependencies()
00081 {
00082     if ( prop_logic_!=0 )
00083     {
00084         NameIDSet dep_set;
00085         prop_logic_->printVariables ( dep_set );
00086         foreach ( NameID dep_name_id, dep_set )
00087         {
00088             declareDependency ( dep_name_id );
00089         }
00090     }
00091 }
00092 
00093 bool
00094 PropLogicEvent::
00095 evaluate ( const NameID& dep_name_id )
00096 {
00097     return getDependencyValue ( dep_name_id.second, dep_name_id.first );
00098 }


predicate_manager
Author(s): Joao Reis and Joao Messias
autogenerated on Wed Aug 26 2015 12:28:34