shape_shifter_factory.hpp
Go to the documentation of this file.
1 #ifndef SHAPE_SHIFTER_FACTORY_HPP
2 #define SHAPE_SHIFTER_FACTORY_HPP
3 
5 #include "PlotJuggler/any.hpp"
6 
7 
9 
10 public:
11  static RosIntrospectionFactory &get();
12 
13  static void registerMessage(const std::string& topic_name,
14  const std::string &md5sum,
15  const std::string& datatype,
16  const std::string& definition );
17 
18  static RosIntrospection::ShapeShifter* getShapeShifter(const std::string& topic_name);
19 
20  static std::vector<const std::string*> getTopicList();
21 
23  {
24  return get()._parser;
25  }
26 
27  static bool isRegistered(const std::string& topic_name);
28 
29  static void reset();
30 
31 private:
32  RosIntrospectionFactory() = default;
33  std::map<std::string, RosIntrospection::ShapeShifter> _ss_map;
35 
36 };
37 //---------------------------------------------
38 
40 {
41  static RosIntrospectionFactory instance;
42  return instance;
43 }
44 
45 // return true if added
46 inline void RosIntrospectionFactory::registerMessage(const std::string &topic_name,
47  const std::string &md5sum,
48  const std::string &datatype,
49  const std::string &definition)
50 {
51  auto& instance = get();
52  auto it = instance._ss_map.find(topic_name);
53  if( it == instance._ss_map.end() || it->second.getMD5Sum() != md5sum )
54  {
56  msg.morph(md5sum, datatype,definition);
57  instance._ss_map.insert( std::make_pair(topic_name, std::move(msg) ));
58  parser().registerMessageDefinition( topic_name, RosIntrospection::ROSType(datatype), definition);
59  }
60 }
61 
63 {
64  auto& instance = get();
65  auto it = instance._ss_map.find( topic_name );
66  return ( it == instance._ss_map.end()) ? nullptr : &(it->second);
67 }
68 
69 inline std::vector<const std::string*> RosIntrospectionFactory::getTopicList()
70 {
71  std::vector<const std::string*> out;
72  auto& instance = get();
73  out.reserve( instance._ss_map.size() );
74 
75  for (const auto& ss: instance._ss_map)
76  {
77  out.push_back( &(ss.first) );
78  }
79  return out;
80 }
81 
82 inline bool RosIntrospectionFactory::isRegistered(const std::string &topic_name)
83 {
84  return get()._ss_map.count(topic_name) != 0;
85 }
86 
88 {
89  get()._ss_map.clear();
90 }
91 
92 #endif // SHAPE_SHIFTER_FACTORY_HPP
93 
94 
95 
static void registerMessage(const std::string &topic_name, const std::string &md5sum, const std::string &datatype, const std::string &definition)
NodeSet out
static bool isRegistered(const std::string &topic_name)
std::map< std::string, RosIntrospection::ShapeShifter > _ss_map
static RosIntrospectionFactory & get()
void morph(const std::string &md5sum, const std::string &datatype_, const std::string &msg_def_)
static RosIntrospection::Parser & parser()
static std::vector< const std::string * > getTopicList()
const char * msg
RosIntrospectionFactory()=default
static RosIntrospection::ShapeShifter * getShapeShifter(const std::string &topic_name)
RosIntrospection::Parser _parser
void registerMessageDefinition(const std::string &message_identifier, const ROSType &main_type, const std::string &definition)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:18