shape_shifter_factory.hpp
Go to the documentation of this file.
00001 #ifndef SHAPE_SHIFTER_FACTORY_HPP
00002 #define SHAPE_SHIFTER_FACTORY_HPP
00003 
00004 #include <ros_type_introspection/shape_shifter.hpp>
00005 #include "PlotJuggler/any.hpp"
00006 
00007 
00008 class RosIntrospectionFactory{
00009 public:
00010   static RosIntrospectionFactory &get();
00011 
00012   void registerMessage(const std::string& topic_name, const std::string &md5sum, const std::string& datatype, const std::string& definition );
00013 
00014   const RosIntrospection::ShapeShifter* getShapeShifter(const std::string& topic_name);
00015 
00016   const RosIntrospection::ROSTypeList*  getRosTypeList(const std::string& topic_name);
00017 
00018   const std::vector<std::string>& getTopicList() const;
00019 
00020 private:
00021   RosIntrospectionFactory() = default;
00022   std::map<std::string, RosIntrospection::ShapeShifter> _ss_map;
00023   std::map<std::string, RosIntrospection::ROSTypeList> _tl_map;
00024   std::vector<std::string> topics_;
00025 
00026 };
00027 //---------------------------------------------
00028 
00029 inline RosIntrospectionFactory& RosIntrospectionFactory::get()
00030 {
00031   static RosIntrospectionFactory instance;
00032   return instance;
00033 }
00034 
00035 // return true if added
00036 inline void RosIntrospectionFactory::registerMessage(const std::string &topic_name,
00037                                                  const std::string &md5sum,
00038                                                  const std::string &datatype,
00039                                                  const std::string &definition)
00040 {
00041 
00042     if( _ss_map.find(topic_name) == _ss_map.end() )
00043     {
00044         RosIntrospection::ShapeShifter msg;
00045         msg.morph(md5sum, datatype,definition);
00046         _ss_map.insert( std::make_pair(topic_name, std::move(msg) ));
00047         topics_.push_back( topic_name );
00048     }
00049 
00050     if( _tl_map.find(topic_name) == _tl_map.end())
00051     {
00052         auto topic_map = RosIntrospection::buildROSTypeMapFromDefinition( datatype, definition);
00053         _tl_map.insert( std::make_pair(topic_name,topic_map));
00054     }
00055 }
00056 
00057 inline const RosIntrospection::ShapeShifter* RosIntrospectionFactory::getShapeShifter(const std::string &topic_name)
00058 {
00059   auto it = _ss_map.find( topic_name );
00060   return ( it == _ss_map.end()) ? nullptr :  &(it->second);
00061 }
00062 
00063 inline const RosIntrospection::ROSTypeList* RosIntrospectionFactory::getRosTypeList(const std::string &topic_name)
00064 {
00065   auto it = _tl_map.find( topic_name );
00066   return ( it == _tl_map.end()) ? nullptr :  &(it->second);
00067 }
00068 
00069 inline const std::vector<std::string> &RosIntrospectionFactory::getTopicList() const
00070 {
00071   return topics_;
00072 }
00073 
00074 #endif // SHAPE_SHIFTER_FACTORY_HPP
00075 
00076 
00077 


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:57