17 #ifndef _GAZEBO_ENUMITERATOR_HH_
18 #define _GAZEBO_ENUMITERATOR_HH_
39 #define GZ_ENUM(enumType, begin, end, ...) \
40 template<> GZ_COMMON_VISIBLE enumType \
41 common::EnumIface<enumType>::range[] = {begin, end}; \
42 template<> GZ_COMMON_VISIBLE \
43 std::vector<std::string> common::EnumIface<enumType>::names = {__VA_ARGS__};
52 public:
static T Begin()
59 public:
static T End()
69 static std::string Str(T
const &_e)
71 if (static_cast<unsigned int>(_e) < names.size())
72 return names[static_cast<unsigned int>(_e)];
82 static void Set(T &_e,
const std::string &_str)
84 static auto begin = std::begin(names);
85 static auto end = std::end(names);
87 auto find = std::find(begin, end, _str);
90 _e =
static_cast<T
>(std::distance(begin, find));
96 public:
static T range[2];
101 public:
static std::vector<std::string> names;
132 template<
typename Enum>
134 : std::iterator<std::bidirectional_iterator_tag, Enum>
137 public: EnumIterator() : c(this->End())
143 public: EnumIterator(
const Enum _c) : c(_c)
145 GZ_ASSERT(this->c >= this->Begin() && this->c <= this->End(),
146 "Invalid enum value in EnumIterator constructor");
151 public: EnumIterator &operator=(
const Enum _c)
153 GZ_ASSERT(_c >= this->Begin() && _c <= this->End(),
154 "Invalid operator= value in EnumIterator");
161 public:
static Enum Begin()
163 return EnumIface<Enum>::Begin();
168 public:
static Enum End()
170 return EnumIface<Enum>::End();
175 public: EnumIterator &operator++()
177 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
178 this->c =
static_cast<Enum
>(
static_cast<int>(this->c) + 1);
184 public: EnumIterator operator++(
const int)
186 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
187 EnumIterator cpy(*
this);
194 public: EnumIterator &operator--()
196 GZ_ASSERT(this->c != this->Begin(),
"decrementing beyond begin?");
197 this->c =
static_cast<Enum
>(
static_cast<int>(this->c) - 1);
203 public: EnumIterator operator--(
const int)
205 GZ_ASSERT(this->c != this->Begin(),
"Decrementing beyond beginning.");
206 EnumIterator cpy(*
this);
213 public: Enum operator*()
const
215 GZ_ASSERT(this->c != this->End(),
"Cannot dereference end iterator");
221 public: Enum Value()
const
236 template<
typename Enum>
237 bool operator==(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
239 return _e1.Value() == _e2.Value();
246 template<
typename Enum>
247 bool operator!=(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
249 return !(_e1 == _e2);
#define GZ_ASSERT(_expr, _msg)
This macro define the standard way of launching an exception inside gazebo.
Definition: Assert.hh:24
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.