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())
144 public: EnumIterator(
const Enum _c) : c(_c)
146 GZ_ASSERT(this->c >= this->Begin() && this->c <= this->End(),
147 "Invalid enum value in EnumIterator constructor");
152 public: EnumIterator &operator=(
const Enum _c)
154 GZ_ASSERT(_c >= this->Begin() && _c <= this->End(),
155 "Invalid operator= value in EnumIterator");
162 public:
static Enum Begin()
164 return EnumIface<Enum>::Begin();
169 public:
static Enum End()
171 return EnumIface<Enum>::End();
176 public: EnumIterator &operator++()
178 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
179 this->c =
static_cast<Enum
>(
static_cast<int>(this->c) + 1);
185 public: EnumIterator operator++(
const int)
187 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
188 EnumIterator cpy(*
this);
195 public: EnumIterator &operator--()
197 GZ_ASSERT(this->c != this->Begin(),
"decrementing beyond begin?");
198 this->c =
static_cast<Enum
>(
static_cast<int>(this->c) - 1);
204 public: EnumIterator operator--(
const int)
206 GZ_ASSERT(this->c != this->Begin(),
"Decrementing beyond beginning.");
207 EnumIterator cpy(*
this);
214 public: Enum operator*()
const
216 GZ_ASSERT(this->c != this->End(),
"Cannot dereference end iterator");
222 public: Enum Value()
const
237 template<
typename Enum>
238 bool operator==(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
240 return _e1.Value() == _e2.Value();
247 template<
typename Enum>
248 bool operator!=(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
250 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.