predicate_dependent_entity.cpp
Go to the documentation of this file.
00001 
00025 #include <predicate_manager/predicate_dependent_entity.h>
00026 
00027 #include <ros/ros.h>
00028 
00029 using namespace std;
00030 using namespace predicate_manager;
00031 
00032 
00033 PredicateDependentEntity::
00034 PredicateDependentEntity ( const Dependencies& deps )
00035 {
00036     foreach ( NameID dep, deps.dependency_set_ )
00037         dep_value_map_[dep] = NULL; 
00038     dep_set_ = deps.dependency_set_;
00039 }
00040 
00041 PredicateDependentEntity::
00042 PredicateDependentEntity()
00043 {}
00044 
00045 void
00046 PredicateDependentEntity::
00047 declareDependency ( const std::string& dep_name, const int pm_id )
00048 {
00049     NameID dep_name_id ( pm_id, dep_name );
00050     declareDependency ( dep_name_id );
00051 }
00052 
00053 void
00054 PredicateDependentEntity::
00055 declareDependency ( const NameID dep_name_id )
00056 {
00057     dep_set_.insert ( dep_name_id );
00058 }
00059 
00060 void
00061 PredicateDependentEntity::
00062 bindDependency ( const NameID dep_name_id, const bool* value_ref )
00063 {
00064     dep_value_map_[dep_name_id] = value_ref;
00065 }
00066 
00067 
00068 bool
00069 PredicateDependentEntity::
00070 getDependencyValue ( const string& dep_name, const int pm_id, DEP_STATUS* status )
00071 {
00072     bool val_declared = true;
00073     boost::unordered_map<NameID,const bool*>::const_iterator it;
00074     NameID dep_name_id ( pm_id, dep_name );
00075 
00076     it = dep_value_map_.find ( dep_name_id );
00077 
00078     if ( it == dep_value_map_.end() )
00079     {
00080         ROS_ERROR_STREAM ( "PredicateDependentEntity attempted to access undeclared dependency "
00081                            << dep_name );
00082         ROS_ERROR ( "Continuing, but returning a 'false' value for this dependency." );
00083 
00084         if ( status )
00085             *status = UNDECLARED;
00086 
00087         return false;
00088     }
00089 
00090     if ( ! ( it->second ) )
00091     {
00092         ROS_WARN_STREAM ( "Requested the value of predicate '" << dep_name << "' which is still unknown."
00093                           << " Using a default 'false' value." );
00094 
00095         if ( status )
00096             *status = UNKNOWN_VALUE;
00097 
00098         return false;
00099     }
00100 
00101     if ( status )
00102         *status = OK;
00103 
00104     return * ( it->second );
00105 }
00106 
00107 NameIDSet PredicateDependentEntity::getDependencies ()
00108 {
00109     return dep_set_;
00110 }
00111 


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