messages.h 3.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
#ifndef MESSAGES_H
#define MESSAGES_H

#include <iostream>
#include <vector>
#include <array>

namespace ros_bridge {

    //! @brief C++ representation of ros::Time
    class Time{
    public:
        Time();
        Time(uint32_t secs, uint32_t nsecs);

        uint32_t getSecs()  const;
        uint32_t getNSecs() const;

        void setSecs    (uint32_t secs);
        void setNSecs   (uint32_t nsecs);

    private:
        uint32_t _secs;
        uint32_t _nsecs;
    };

    //! @brief C++ representation of std_msgs/Header
    class Header{
    public:
        Header();
        Header(uint32_t seq, const Time &stamp, const std::string &frame_id);

        uint32_t            getSeq()       const;
        const Time         &getStamp()     const;
        const std::string  &getFrameId()   const;

        void setSeq     (uint32_t seq);
        void setStamp   (const Time & stamp);
        void setFrameId (const std::string  &frame_id);

    private:
        uint32_t    _seq;
        Time        _stamp;
        std::string _frame_id;
    };

    //! @brief C++ representation of geometry_msgs/Point32
    class Point32{
    public:
        Point32();
        Point32(_Float32 x, _Float32 y, _Float32 z);

        template<unsigned int i>
        void set(_Float32 component)
        {
            static_assert (i < 3, "Index out of bonds.");
            _components[i] = component;
        }

        template<unsigned int i>
        _Float32 get(void) const
        {
            static_assert (i < 3, "Index out of bonds.");
            return _components[i];
        }

    private:
        std::array<_Float32, 3> _components;
    };

    //! @brief C++ representation of geometry_msgs/Polygon
    template <class PointType = Point32>
    class Polygon{
    public:
        Polygon(){}
        Polygon(const std::vector<Point32> &points) : _points(points) {}
        Polygon(const Polygon &poly) : _points(poly.get()) {}

        const std::vector<Point32> &get() const
        {
            return _points;
        }

        void set(std::vector<Point32> &points)
        {
            _points = points;
        }

        void clear()
        {
            _points.clear();
        }

        PointType &at(unsigned int i)
        {
            return _points.at(i);
        }

        void push_back(const Point32 &p)
        {
            _points.push_back(p);
        }

        void pop_back()
        {
            _points.pop_back();
        }

    private:
        std::vector<PointType> _points;
    };

    //! @brief C++ representation of geometry_msgs/PolygonStamped
    template <class HeaderType = Header, class PolygonType = Polygon<>>
    class PolygonStamped : public PolygonType{
    public:
        PolygonStamped();
        PolygonStamped(const Header &header, const PolygonType &polygon) :
            _header(header)
          , PolygonType(polygon) {}

    private:
        Header _header;
    };

    //! @brief C++ representation of jsk_recognition_msgs/PolygonArray
    template <class PolygonType = Polygon<>, class HeaderType = Header, template<class> class ContainerType = std::vector >
    class PolygonArray{
    public:
        PolygonArray()
         : PolygonArray(HeaderType()
                        , ContainerType<PolygonType>()
                        , ContainerType<uint32_t>()
                        , ContainerType<_Float32>())
        {}

        PolygonArray(const HeaderType                   &header,
                     const ContainerType<PolygonType>   &polygons,
                     const ContainerType<uint32_t>      &labels,
                     const ContainerType<_Float32>      &likelihood)
          : _header(header)
          , _polygons(polygons)
          , _labels(labels)
          , _likelihood(likelihood)
        {}

    private:
        HeaderType                  _header;
        ContainerType<PolygonType>  _polygons;
        ContainerType<uint32_t>     _labels;
        ContainerType<_Float32>     _likelihood;
    };
}

#endif // MESSAGES_H