messageparser_base.h
Go to the documentation of this file.
1 #ifndef MESSAGEPARSER_TEMPLATE_H
2 #define MESSAGEPARSER_TEMPLATE_H
3 
4 #include <QtPlugin>
5 #include <array>
6 #include <unordered_map>
7 #include <unordered_set>
8 #include <functional>
9 #include "PlotJuggler/plotdata.h"
10 
11 
13 {
14 public:
15  explicit
16  MessageRef(const uint8_t* first_ptr, size_t size):
17  _first_ptr(first_ptr),
18  _size(size) { }
19 
20  explicit
21  MessageRef(const std::vector<uint8_t>& vect):
22  _first_ptr(vect.data()),
23  _size(vect.size()) { }
24 
25  const uint8_t* data() const { return _first_ptr; }
26 
27  size_t size() const { return _size; }
28 
29 private:
30  const uint8_t* _first_ptr;
31  size_t _size;
32 };
33 
34 
45 
46 public:
47 
48  virtual ~MessageParser() {}
49 
50  virtual const std::unordered_set<std::string>& getCompatibleKeys() const = 0;
51 
52  virtual void pushMessageRef(const std::string& key,
53  const MessageRef& msg,
54  double timestamp) = 0;
55 
56  virtual void extractData(PlotDataMapRef& destination,
57  const std::string& prefix) = 0;
58 
59 protected:
60 
61  static void appendData(PlotDataMapRef& destination_plot_map,
62  const std::string& field_name,
63  PlotData& in_data)
64  {
65  if( in_data.size() == 0 )
66  {
67  return;
68  }
69  auto plot_pair = destination_plot_map.numeric.find( field_name );
70  if( (plot_pair == destination_plot_map.numeric.end()) )
71  {
72  plot_pair = destination_plot_map.addNumeric( field_name );
73  plot_pair->second.swapData( in_data );
74  }
75  else{
76  PlotData& plot_data = plot_pair->second;
77  for(size_t i=0; i < in_data.size(); i++)
78  {
79  double val = in_data[i].y;
80  if( !std::isnan(val) && !std::isinf(val) )
81  {
82  plot_data.pushBack( in_data[i] );
83  }
84  }
85  }
86  in_data.clear();
87  }
88 };
89 
90 QT_BEGIN_NAMESPACE
91 
92 #define MessageParser_iid "com.icarustechnology.PlotJuggler.MessageParser"
93 Q_DECLARE_INTERFACE(MessageParser, MessageParser_iid)
94 
95 QT_END_NAMESPACE
96 
97 
98 #endif
99 
std::unordered_map< std::string, PlotData > numeric
Definition: plotdata.h:144
void pushBack(Point p)
Definition: plotdata.h:214
size_t size() const
MessageRef(const uint8_t *first_ptr, size_t size)
MessageRef(const std::vector< uint8_t > &vect)
void clear()
Definition: plotdata.h:301
const uint8_t * data() const
virtual size_t size() const
Definition: plotdata.h:308
const char * msg
#define MessageParser_iid
std::unordered_map< std::string, PlotData >::iterator addNumeric(const std::string &name)
Definition: plotdata.h:147
virtual ~MessageParser()
static void appendData(PlotDataMapRef &destination_plot_map, const std::string &field_name, PlotData &in_data)
int i
const uint8_t * _first_ptr
The MessageParser is the base class to create plugins that are able to parse one or multiple Message ...


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