GenericWaypointManager.h 7.74 KB
Newer Older
1 2
#pragma once

3
#include <iostream>
4

5
#include "Slicer.h"
6 7 8 9

namespace WaypointManager {

template<class WaypointType,
10 11 12
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
13
class GenericWaypointManager : public Slicer
14 15
{
public:
16 17 18
    typedef ContainerType<WaypointType>  WaypointList;

    GenericWaypointManager() = delete;
19
    GenericWaypointManager(SettingsType &settings);
20 21

    // Waypoint editing.
22 23 24 25 26 27 28
    virtual void            setWaypoints(const WaypointList &waypoints);
    virtual void            push_back   (const WaypointType &wp);
    virtual void            push_front  (const WaypointType &wp);
    virtual void            clear       ();
    virtual void            insert      (std::size_t i, const WaypointType &wp);
    virtual std::size_t     size        ()  const;
    virtual void            remove      (std::size_t i);
29 30 31


    const WaypointList      &waypoints() const;
32
    const WaypointList      &currentWaypoints() const;
33
    const MissionItemList   &missionItems() const;
34 35 36 37
    const MissionItemList   &currentMissionItems() const;

    const QVariantList &waypointsVariant() const;
    const QVariantList &currentWaypointsVariant() const;
38 39 40 41 42 43 44 45

    virtual bool update() = 0;
    virtual bool next() = 0;
    virtual bool previous() = 0;
    virtual bool reset() = 0;

protected:
    WaypointList        _waypoints;
46 47
    WaypointList        _currentWaypoints;
    MissionItemList     _currentMissionItems;
48 49
    MissionItemList     _missionItems;
    SettingsType       *_settings;
50 51 52
    bool                _dirty;
    QVariantList        _waypointsVariant;
    QVariantList        _currentWaypointsVariant;
53
};
54 55


56 57 58 59 60 61 62
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
GenericWaypointManager<WaypointType,
                       ContainerType,
                       MissionItemList,
63 64 65 66
                       SettingsType>::GenericWaypointManager(SettingsType &settings)
  : Slicer()
  , _settings(&settings)
  , _dirty(true)
67
{}
68

69 70 71 72 73 74 75 76 77
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
void GenericWaypointManager<WaypointType,
                            ContainerType,
                            MissionItemList,
                            SettingsType>::push_back(const WaypointType &wp)
{
78
    _dirty = true;
79 80
    _waypoints.push_back(wp);
}
81

82 83 84 85 86 87 88 89 90 91
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
void GenericWaypointManager<WaypointType,
                            ContainerType,
                            MissionItemList,
                            SettingsType>::push_front(
        const WaypointType &wp)
{
92
    _dirty = true;
93 94
    _waypoints.push_front(wp);
}
95

96 97 98 99 100 101 102 103 104
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
void GenericWaypointManager<WaypointType,
                            ContainerType,
                            MissionItemList,
                            SettingsType>::clear()
{
105
    _dirty = true;
106
    _waypoints.clear();
107 108 109 110 111
    _currentWaypoints.clear();
    _missionItems.clear();
    _currentMissionItems.clear();
    _waypointsVariant.clear();
    _currentWaypointsVariant.clear();
112
}
113

114 115 116 117 118 119 120 121 122 123
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
void GenericWaypointManager<WaypointType,
                            ContainerType,
                            MissionItemList,
                            SettingsType>::insert(std::size_t i,
                                                  const WaypointType &wp)
{
124
    _dirty = true;
125 126
    _waypoints.insert(i, wp);
}
127 128

template<class WaypointType,
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
std::size_t GenericWaypointManager<WaypointType,
                                   ContainerType,
                                   MissionItemList,
                                   SettingsType>::size() const
{
    return _waypoints.size();
}

template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
144 145 146 147
void GenericWaypointManager<WaypointType,
                            ContainerType,
                            MissionItemList,
                            SettingsType>::remove(std::size_t i)
148
{
149
    return _waypoints.remove(i);
150 151
}

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
const QVariantList  &GenericWaypointManager<WaypointType,
                                            ContainerType,
                                            MissionItemList,
                                            SettingsType>::waypointsVariant() const
{
    return _waypointsVariant;
}

template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
const QVariantList  &GenericWaypointManager<WaypointType,
                                            ContainerType,
                                            MissionItemList,
                                            SettingsType>::currentWaypointsVariant() const
{
    return _currentWaypointsVariant;
}

176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
const ContainerType<WaypointType>  &GenericWaypointManager<WaypointType,
                                                           ContainerType,
                                                           MissionItemList,
                                                           SettingsType>::waypoints() const
{
    return _waypoints;
}

template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
const ContainerType<WaypointType> &GenericWaypointManager<WaypointType,
                                                          ContainerType,
                                                          MissionItemList,
195
                                                          SettingsType>::currentWaypoints() const
196
{
197
    return _currentWaypoints;
198 199 200 201 202 203 204 205 206 207 208 209 210 211
}

template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
const MissionItemList &GenericWaypointManager<WaypointType,
                                              ContainerType,
                                              MissionItemList,
                                              SettingsType>::missionItems() const
{
    return _missionItems;
}

212 213 214 215 216 217 218 219 220 221 222 223
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
const MissionItemList &GenericWaypointManager<WaypointType,
                                              ContainerType,
                                              MissionItemList,
                                              SettingsType>::currentMissionItems() const
{
    return _currentMissionItems;
}

224 225 226 227 228 229 230 231 232 233 234
template<class WaypointType,
         template<class, class...> class ContainerType,
         class MissionItemList,
         class SettingsType>
void GenericWaypointManager<WaypointType,
                            ContainerType,
                            MissionItemList,
                            SettingsType>::setWaypoints(const ContainerType<WaypointType> &waypoints)
{
    _waypoints = waypoints;
}
235 236 237 238 239



} // namespace WaypointManager