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__}; 46 #pragma clang diagnostic push 47 #pragma clang diagnostic ignored "-Wundefined-var-template" 56 public:
static T Begin()
63 public:
static T End()
73 static std::string Str(T
const &_e)
75 if (static_cast<unsigned int>(_e) < names.size())
76 return names[static_cast<unsigned int>(_e)];
86 static void Set(T &_e,
const std::string &_str)
88 static auto begin = std::begin(names);
89 static auto end = std::end(names);
91 auto find = std::find(begin, end, _str);
94 _e =
static_cast<T
>(std::distance(begin, find));
100 public:
static T range[2];
105 public:
static std::vector<std::string> names;
108 #pragma clang diagnostic pop 139 template<
typename Enum>
141 : std::iterator<std::bidirectional_iterator_tag, Enum>
144 public: EnumIterator() : c(this->End())
151 public: EnumIterator(
const Enum _c) : c(_c)
153 GZ_ASSERT(this->c >= this->Begin() && this->c <= this->End(),
154 "Invalid enum value in EnumIterator constructor");
159 public: EnumIterator &operator=(
const Enum _c)
161 GZ_ASSERT(_c >= this->Begin() && _c <= this->End(),
162 "Invalid operator= value in EnumIterator");
169 public:
static Enum Begin()
171 return EnumIface<Enum>::Begin();
176 public:
static Enum End()
178 return EnumIface<Enum>::End();
183 public: EnumIterator &operator++()
185 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
186 this->c =
static_cast<Enum
>(
static_cast<int>(this->c) + 1);
192 public: EnumIterator operator++(
const int)
194 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
195 EnumIterator cpy(*
this);
202 public: EnumIterator &operator--()
204 GZ_ASSERT(this->c != this->Begin(),
"decrementing beyond begin?");
205 this->c =
static_cast<Enum
>(
static_cast<int>(this->c) - 1);
211 public: EnumIterator operator--(
const int)
213 GZ_ASSERT(this->c != this->Begin(),
"Decrementing beyond beginning.");
214 EnumIterator cpy(*
this);
221 public: Enum operator*()
const 223 GZ_ASSERT(this->c != this->End(),
"Cannot dereference end iterator");
229 public: Enum Value()
const 244 template<
typename Enum>
245 bool operator==(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
247 return _e1.Value() == _e2.Value();
254 template<
typename Enum>
255 bool operator!=(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
257 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:26
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.