Go to the documentation of this file.00001 #ifndef MESSAGEPARSER_TEMPLATE_H
00002 #define MESSAGEPARSER_TEMPLATE_H
00003
00004 #include <QtPlugin>
00005 #include <array>
00006 #include <unordered_map>
00007 #include <unordered_set>
00008 #include <functional>
00009 #include "PlotJuggler/plotdata.h"
00010
00011
00012 class MessageRef
00013 {
00014 public:
00015 explicit
00016 MessageRef(const uint8_t* first_ptr, size_t size):
00017 _first_ptr(first_ptr),
00018 _size(size) { }
00019
00020 explicit
00021 MessageRef(const std::vector<uint8_t>& vect):
00022 _first_ptr(vect.data()),
00023 _size(vect.size()) { }
00024
00025 const uint8_t* data() const { return _first_ptr; }
00026
00027 size_t size() const { return _size; }
00028
00029 private:
00030 const uint8_t* _first_ptr;
00031 size_t _size;
00032 };
00033
00034
00044 class MessageParser{
00045
00046 public:
00047
00048 virtual ~MessageParser() {}
00049
00050 virtual const std::unordered_set<std::string>& getCompatibleKeys() const = 0;
00051
00052 virtual void pushMessageRef(const std::string& key,
00053 const MessageRef& msg,
00054 double timestamp) = 0;
00055
00056 virtual void extractData(PlotDataMapRef& destination,
00057 const std::string& prefix) = 0;
00058
00059 protected:
00060
00061 static void appendData(PlotDataMapRef& destination_plot_map,
00062 const std::string& field_name,
00063 PlotData& in_data)
00064 {
00065 if( in_data.size() == 0 )
00066 {
00067 return;
00068 }
00069 auto plot_pair = destination_plot_map.numeric.find( field_name );
00070 if( (plot_pair == destination_plot_map.numeric.end()) )
00071 {
00072 plot_pair = destination_plot_map.addNumeric( field_name );
00073 plot_pair->second.swapData( in_data );
00074 }
00075 else{
00076 PlotData& plot_data = plot_pair->second;
00077 for(size_t i=0; i < in_data.size(); i++)
00078 {
00079 double val = in_data[i].y;
00080 if( !std::isnan(val) && !std::isinf(val) )
00081 {
00082 plot_data.pushBack( in_data[i] );
00083 }
00084 }
00085 }
00086 in_data.clear();
00087 }
00088 };
00089
00090 QT_BEGIN_NAMESPACE
00091
00092 #define MessageParser_iid "com.icarustechnology.PlotJuggler.MessageParser"
00093 Q_DECLARE_INTERFACE(MessageParser, MessageParser_iid)
00094
00095 QT_END_NAMESPACE
00096
00097
00098 #endif
00099