#pragma once
#include "ros_bridge/include/MessageBaseClass.h"
#include "ros_bridge/include/MessageGroups.h"

#include "QmlObjectListModel.h"

#include <QVector>
#include <QString>

typedef ROSBridge::MessageBaseClass ROSMsg;
namespace MsgGroups = ROSBridge::MessageGroups;
typedef MsgGroups::EmptyGroup EmptyGroup;
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)
    {}

    virtual WimaPolygonArray *Clone() const override{
        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;

};


