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