20 template<
class EnumType>
24 static const std::unique_ptr<std::string[]> names_;
28 typedef EnumType value_type;
33 for(std::size_t i = 0; i < static_cast<uint32_t>(value_type::__LAST); ++i){
34 names.emplace_back(names_[i]);
54 Value(
const EnumType& val = EnumType::__FIRST):
62 explicit operator EnumType()
const
67 operator uint32_t()
const
69 return static_cast<uint32_t
>(val_);
72 operator std::string()
const
83 bool operator==(
const Value& other)
const
85 return (val_ == other.val_);
88 bool operator!=(
const Value& other)
const
90 return (val_ != other.val_);
93 const EnumType & getEnum()
const {
115 val_ =
static_cast<EnumType
>(
static_cast<uint32_t
>(val_) + 1);
118 Value operator*()
const
123 bool operator==(
const iterator& other)
const
125 return (val_ == other.val_);
128 bool operator!=(
const iterator& other)
const
130 return (val_ != other.val_);
141 template<
class...Args>
142 Enum(
const Args&...args)
144 static_assert(std::is_enum<EnumType>::value,
145 "ERROR: EnumType is not an enum");
149 Enum(
const Enum& other)
154 const Value operator()(
const EnumType& val)
const
159 const Value operator()(
const uint32_t i)
const
161 return Value(
static_cast<EnumType
>(i));
164 const Value operator()(
const std::string& s)
const
169 for (uint32_t i = 0; i < static_cast<uint32_t>(EnumType::__LAST); ++i) {
170 if (names_[i] == s) {
171 return this->operator()(i);
175 throw UnknownNameException();
176 return Value(EnumType::__LAST);
179 iterator begin()
const
181 return iterator(EnumType::__FIRST);
186 return iterator(EnumType::__LAST);
189 size_t size()
const {
190 return static_cast<uint32_t
>(EnumType::__LAST);
196 names_[
static_cast<uint32_t
>(EnumType::__LAST)] =
"<<LAST>>";
199 template<
class...Args>
200 void setName_(
const EnumType&
id,
const std::string& name,
const Args&...args)
202 names_[
static_cast<uint32_t
>(id)] = name;
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
SpartaException()
Construct a SpartaException object with empty reason.
Class that wraps a C++ class enum and allows conversion between POD and the enum type....
static void populateNames(std::vector< std::string > &names)
Method which populates an argument vector with string-names of.
Macros for handling exponential backoff.