00001 00025 #ifndef _OBSERVATION_DEP_H_ 00026 #define _OBSERVATION_DEP_H_ 00027 00028 #include <string> 00029 00030 #include <boost/unordered_map.hpp> 00031 00032 #include <ros/ros.h> 00033 00034 #include <predicate_manager/common_defs.h> 00035 00036 00037 namespace mdm_library 00038 { 00039 class ObservationDep 00040 { 00041 public: 00042 typedef std::vector< predicate_manager::NameID > ObsFactorLocalDeps; 00043 typedef std::vector< std::string > ObsFactorGlobalDeps; 00044 typedef boost::unordered_map< std::string, uint32_t > DepIndexMap; 00045 00046 ObservationDep 00047 add ( uint32_t pm_id, std::string event_name ) 00048 { 00049 registerDependencyName ( event_name ); 00050 ObsFactorLocalDeps::value_type odep ( pm_id, event_name ); 00051 local_deps_.push_back ( odep ); 00052 return *this; 00053 } 00054 00055 ObservationDep 00056 add ( std::string event_name ) 00057 { 00058 registerDependencyName ( event_name ); 00059 ObsFactorGlobalDeps::value_type odep ( event_name ); 00060 global_deps_.push_back ( odep ); 00061 return *this; 00062 } 00063 00064 const ObsFactorLocalDeps getLocalDependencies() const 00065 { 00066 return local_deps_; 00067 } 00068 const ObsFactorGlobalDeps getGlobalDependencies() const 00069 { 00070 return global_deps_; 00071 } 00072 uint32_t getDependencyIndex ( const std::string& event_name ) 00073 { 00074 DepIndexMap::const_iterator it = dep_index_map_.find ( event_name ); 00075 if ( it == dep_index_map_.end() ) 00076 { 00077 ROS_ERROR_STREAM ( "ObservationDep:: Dependency '" << event_name << "' not present for this factor." ); 00078 abort(); 00079 } 00080 return it->second; 00081 } 00082 uint32_t getNumberOfValues() const 00083 { 00084 return local_deps_.size() + global_deps_.size(); 00085 } 00086 private: 00087 void registerDependencyName ( const std::string& event_name ) 00088 { 00089 if ( dep_index_map_.count ( event_name ) ) 00090 { 00091 ROS_ERROR_STREAM ( "ObservationDep:: Attempt to re-include dependency '" << event_name << "'" ); 00092 abort(); 00093 } 00094 dep_index_map_[event_name] = getNumberOfValues(); 00095 } 00096 00097 ros::NodeHandle nh_; 00098 00099 ObsFactorLocalDeps local_deps_; 00100 ObsFactorGlobalDeps global_deps_; 00101 00102 DepIndexMap dep_index_map_; 00103 }; 00104 } 00105 #endif