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 
7 
8 public:
10 
11  static void registerMessage(const std::string& topic_name,
12  const std::string &md5sum,
13  const std::string& datatype,
14  const std::string& definition );
15 
16  static RosIntrospection::ShapeShifter* getShapeShifter(const std::string& topic_name);
17 
18  static std::vector<const std::string*> getTopicList();
19 
21  {
22  return get()._parser;
23  }
24 
25  static bool isRegistered(const std::string& topic_name);
26 
27  static void reset();
28 
29 private:
30  RosIntrospectionFactory() = default;
31  std::map<std::string, RosIntrospection::ShapeShifter> _ss_map;
33 
34 };
35 //---------------------------------------------
36 
38 {
39  static RosIntrospectionFactory instance;
40  return instance;
41 }
42 
43 // return true if added
44 inline void RosIntrospectionFactory::registerMessage(const std::string &topic_name,
45  const std::string &md5sum,
46  const std::string &datatype,
47  const std::string &definition)
48 {
49  auto& instance = get();
50  auto it = instance._ss_map.find(topic_name);
51  if( it == instance._ss_map.end() || it->second.getMD5Sum() != md5sum )
52  {
54  msg.morph(md5sum, datatype,definition);
55  instance._ss_map.insert( std::make_pair(topic_name, std::move(msg) ));
57  }
58 }
59 
61 {
62  auto& instance = get();
63  auto it = instance._ss_map.find( topic_name );
64  return ( it == instance._ss_map.end()) ? nullptr : &(it->second);
65 }
66 
67 inline std::vector<const std::string*> RosIntrospectionFactory::getTopicList()
68 {
69  std::vector<const std::string*> out;
70  auto& instance = get();
71  out.reserve( instance._ss_map.size() );
72 
73  for (const auto& ss: instance._ss_map)
74  {
75  out.push_back( &(ss.first) );
76  }
77  return out;
78 }
79 
80 inline bool RosIntrospectionFactory::isRegistered(const std::string &topic_name)
81 {
82  return get()._ss_map.count(topic_name) != 0;
83 }
84 
86 {
87  get()._ss_map.clear();
88 }
89 
90 #endif // SHAPE_SHIFTER_FACTORY_HPP
91 
92 
93 
md5sum
const char * md5sum()
RosIntrospection::ROSType
RosIntrospectionFactory::_ss_map
std::map< std::string, RosIntrospection::ShapeShifter > _ss_map
Definition: shape_shifter_factory.hpp:31
definition
const char * definition()
RosIntrospectionFactory::get
static RosIntrospectionFactory & get()
Definition: shape_shifter_factory.hpp:37
RosIntrospectionFactory::registerMessage
static void registerMessage(const std::string &topic_name, const std::string &md5sum, const std::string &datatype, const std::string &definition)
Definition: shape_shifter_factory.hpp:44
msg
msg
RosIntrospectionFactory::isRegistered
static bool isRegistered(const std::string &topic_name)
Definition: shape_shifter_factory.hpp:80
RosIntrospectionFactory::parser
static RosIntrospection::Parser & parser()
Definition: shape_shifter_factory.hpp:20
RosIntrospectionFactory::getTopicList
static std::vector< const std::string * > getTopicList()
Definition: shape_shifter_factory.hpp:67
out
std::add_lvalue_reference< decltype(std::declval< FormatContext >).out())>::type out
RosIntrospectionFactory
Definition: shape_shifter_factory.hpp:6
RosIntrospection::Parser::registerMessageDefinition
void registerMessageDefinition(const std::string &message_identifier, const ROSType &main_type, const std::string &definition)
it
iterator it
RosIntrospection::Parser
shape_shifter.hpp
RosIntrospectionFactory::reset
static void reset()
Definition: shape_shifter_factory.hpp:85
datatype
const char * datatype()
RosIntrospection::ShapeShifter
RosIntrospectionFactory::RosIntrospectionFactory
RosIntrospectionFactory()=default
RosIntrospectionFactory::_parser
RosIntrospection::Parser _parser
Definition: shape_shifter_factory.hpp:32
nullptr
#define nullptr
RosIntrospectionFactory::getShapeShifter
static RosIntrospection::ShapeShifter * getShapeShifter(const std::string &topic_name)
Definition: shape_shifter_factory.hpp:60


plotjuggler_ros
Author(s): Davide Faconti
autogenerated on Wed Feb 21 2024 03:22:56