WimaPolygonArray.h 1.38 KB
Newer Older
1
#pragma once
2 3
#include "ros_bridge/include/MessageBaseClass.h"
#include "ros_bridge/include/MessageGroups.h"
4 5 6 7 8 9

#include "QmlObjectListModel.h"

#include <QVector>
#include <QString>

Valentin Platzgummer's avatar
Valentin Platzgummer committed
10
typedef ROSBridge::MessageBaseClass ROSMsg;
11 12
namespace MsgGroups = ROSBridge::MessageGroups;
typedef MsgGroups::EmptyGroup EmptyGroup;
13 14 15 16 17 18 19 20 21 22 23
template <class PolygonType, template <class, class...> class ContainerType = QVector, typename GroupType = EmptyGroup>
class WimaPolygonArray : public ROSMsg
{
public:
    typedef GroupType Group;
    WimaPolygonArray() {}
    WimaPolygonArray(const WimaPolygonArray &other) :
        ROSMsg()
      , _polygons(other._polygons), _dirty(true)
    {}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
24
    virtual WimaPolygonArray *Clone() const override{
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        return new WimaPolygonArray(*this);
    }

    class QmlObjectListModel *QmlObjectListModel(){
        if (_dirty)
            _updateObjects();
        _dirty = false;
        return &_objs;
    }

    const ContainerType<PolygonType> &polygons() const {
        return _polygons;
    }

    ContainerType<PolygonType> &polygons(){
        _dirty = true;
        return _polygons;
    }



private:
    void _updateObjects(void){
        _objs.clear();
        for (long i=0; i<_polygons.size(); ++i){
            _objs.append(&_polygons[i]);
        }
    }

    ContainerType<PolygonType> _polygons;
    class QmlObjectListModel   _objs;
    bool                       _dirty;

};