17 #ifndef _GAZEBO_ENUMITERATOR_HH_ 18 #define _GAZEBO_ENUMITERATOR_HH_ 38 #define GZ_ENUM(enumType, begin, end, ...) \ 39 template<> enumType common::EnumIface<enumType>::range[] = {begin, end}; \ 40 template<> std::vector<std::string> common::EnumIface<enumType>::names = \ 50 public:
static T Begin()
57 public:
static T End()
67 static std::string Str(T
const &_e)
69 if (_e < names.size())
80 static void Set(T &_e,
const std::string &_str)
82 static auto begin = std::begin(names);
83 static auto end = std::end(names);
85 auto find = std::find(begin, end, _str);
88 _e =
static_cast<T
>(std::distance(begin, find));
94 public:
static T range[2];
99 public:
static std::vector<std::string> names;
130 template<
typename Enum>
132 : std::iterator<std::bidirectional_iterator_tag, Enum>
135 public: EnumIterator() : c(this->End())
141 public: EnumIterator(
const Enum _c) : c(_c)
143 GZ_ASSERT(this->c >= this->Begin() && this->c <= this->End(),
144 "Invalid enum value in EnumIterator constructor");
149 public: EnumIterator &operator=(
const Enum _c)
151 GZ_ASSERT(_c >= this->Begin() && _c <= this->End(),
152 "Invalid operator= value in EnumIterator");
159 public:
static Enum Begin()
161 return EnumIface<Enum>::Begin();
166 public:
static Enum End()
168 return EnumIface<Enum>::End();
173 public: EnumIterator &operator++()
175 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
176 this->c =
static_cast<Enum
>(this->c + 1);
182 public: EnumIterator operator++(
const int)
184 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
185 EnumIterator cpy(*
this);
192 public: EnumIterator &operator--()
194 GZ_ASSERT(this->c != this->Begin(),
"decrementing beyond begin?");
195 this->c =
static_cast<Enum
>(this->c - 1);
201 public: EnumIterator operator--(
const int)
203 GZ_ASSERT(this->c != this->Begin(),
"Decrementing beyond beginning.");
204 EnumIterator cpy(*
this);
211 public: Enum operator*()
const 213 GZ_ASSERT(this->c != this->End(),
"Cannot dereference end iterator");
219 public: Enum Value()
const 234 template<
typename Enum>
235 bool operator==(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
237 return _e1.Value() == _e2.Value();
244 template<
typename Enum>
245 bool operator!=(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
247 return !(_e1 == _e2);
#define GZ_ASSERT(_expr, _msg)
This macro define the standard way of launching an exception inside gazebo.
Definition: Assert.hh:24
Forward declarations for the common classes.
Definition: Animation.hh:33
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.