17 #ifndef _GAZEBO_ENUMITERATOR_HH_ 18 #define _GAZEBO_ENUMITERATOR_HH_ 40 #define GZ_ENUM(enumType, begin, end, ...) \ 41 template<> GZ_COMMON_VISIBLE enumType \ 42 common::EnumIface<enumType>::range[] = {begin, end}; \ 43 template<> GZ_COMMON_VISIBLE \ 44 std::vector<std::string> common::EnumIface<enumType>::names = {__VA_ARGS__}; 57 #define GZ_ENUM_VISIBILITY(visibility, enumType, begin, end, ...) \ 58 template<> visibility enumType \ 59 common::EnumIface<enumType>::range[] = {begin, end}; \ 60 template<> visibility std::vector<std::string> \ 61 common::EnumIface<enumType>::names = {__VA_ARGS__}; 63 #define GZ_ENUM_VISIBILITY(visibility, enumType, begin, end, ...) \ 65 common::EnumIface<enumType>::range[] = {begin, end}; \ 66 template<> std::vector<std::string> \ 67 common::EnumIface<enumType>::names = {__VA_ARGS__}; \ 68 template class visibility common::EnumIface<enumType>; 77 #define GZ_ENUM_DECLARE(visibility, enumType) 79 #define GZ_ENUM_DECLARE(visibility, enumType) \ 80 template class visibility common::EnumIface<enumType>; 84 #pragma clang diagnostic push 85 #pragma clang diagnostic ignored "-Wundefined-var-template" 94 public:
static T Begin()
101 public:
static T End()
111 static std::string Str(T
const &_e)
113 if (static_cast<unsigned int>(_e) < names.size())
114 return names[static_cast<unsigned int>(_e)];
124 static void Set(T &_e,
const std::string &_str)
126 static auto begin = std::begin(names);
127 static auto end = std::end(names);
129 auto find = std::find(begin, end, _str);
132 _e =
static_cast<T
>(std::distance(begin, find));
138 public:
static T range[2];
143 public:
static std::vector<std::string> names;
146 #pragma clang diagnostic pop 178 template<
typename Enum>
180 : std::iterator<std::bidirectional_iterator_tag, Enum>
183 public: EnumIterator() : c(this->End())
190 public: EnumIterator(
const Enum _c) : c(_c)
192 GZ_ASSERT(this->c >= this->Begin() && this->c <= this->End(),
193 "Invalid enum value in EnumIterator constructor");
198 public: EnumIterator &operator=(
const Enum _c)
200 GZ_ASSERT(_c >= this->Begin() && _c <= this->End(),
201 "Invalid operator= value in EnumIterator");
208 public:
static Enum Begin()
210 return EnumIface<Enum>::Begin();
215 public:
static Enum End()
217 return EnumIface<Enum>::End();
222 public: EnumIterator &operator++()
224 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
225 this->c =
static_cast<Enum
>(
static_cast<int>(this->c) + 1);
231 public: EnumIterator operator++(
const int)
233 GZ_ASSERT(this->c != this->End(),
"Incrementing past end of enum");
234 EnumIterator cpy(*
this);
241 public: EnumIterator &operator--()
243 GZ_ASSERT(this->c != this->Begin(),
"decrementing beyond begin?");
244 this->c =
static_cast<Enum
>(
static_cast<int>(this->c) - 1);
250 public: EnumIterator operator--(
const int)
252 GZ_ASSERT(this->c != this->Begin(),
"Decrementing beyond beginning.");
253 EnumIterator cpy(*
this);
260 public: Enum operator*()
const 262 GZ_ASSERT(this->c != this->End(),
"Cannot dereference end iterator");
268 public: Enum Value()
const 283 template<
typename Enum>
284 bool operator==(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
286 return _e1.Value() == _e2.Value();
293 template<
typename Enum>
294 bool operator!=(EnumIterator<Enum> _e1, EnumIterator<Enum> _e2)
296 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.
common
Definition: FuelModelDatabase.hh:37