37 template<
typename enum_t = std::
nullptr_t>
43 using enum_type = enum_t;
68 operator enum_type()
const noexcept {
return value_;}
78 bool has_flag(enum_type flag)
const noexcept {
return (to_int(value_) & to_int(flag)) == to_int(flag);}
82 enum_type
value() const noexcept {
return value_;}
95 if (to_int(value_) == to_int(value.value_))
return 0;
96 if (to_int(value_) < to_int(value.value_))
return -1;
136 auto iterator = std::find_if(entries().begin(), entries().
end(), [&](
auto value)->
bool {
return value.first == value_;});
139 return iterator->second;
161 if (fmt.empty()) fmt =
"G";
171 case 'X':
return __numeric_formatter(fmt, static_cast<long long int>(value_), std::locale());
175 case 'G':
return __format_stringer<char>(value_);
182 bool equals(
const enum_object& value)
const noexcept
override {
return value_ == value.value_;}
183 bool equals(enum_type value)
const noexcept {
return value_ ==
value;}
184 template<
typename attribute_t>
185 bool equals(attribute_t value)
const noexcept {
return false;}
194 return static_cast<enum_type
>(item.first);
197 return to_enum(xtd::parse<int64>(str));
200 static enum_type parse_flags(
const xtd::ustring& value,
bool ignore_case) {
201 std::vector<xtd::ustring> values = value.
split({
','});
205 if (values.size() == 1) {
208 return to_enum(item.first);
210 return to_enum(xtd::parse<int64>(value));
219 result |= to_int(item.first);
227 return to_enum(result);
235 auto iterator = std::find_if(entries().begin(), entries().
end(), [&](
auto value)->
bool {
return value.first == value_;});
237 return iterator->second;
241 auto iterator = std::find_if(entries().begin(), entries().
end(), [&](
auto value)->
bool {
return value.first == value_;});
242 if (to_int(value_) == 0 && iterator == entries().
end())
return "0";
244 iterator = std::find_if(entries().begin(), entries().
end(), [&](
auto value)->
bool {
return value.first == to_enum(0);});
245 if (to_int(value_) == 0)
return iterator == entries().end() ?
"0" : iterator->second;
248 int64 rest = to_int(value_);
250 std::reverse(reversed_entries.begin(), reversed_entries.end());
252 for (
auto item : reversed_entries) {
253 if (to_int(item.first) != 0 && (rest & to_int(item.first)) == to_int(item.first)) {
254 rest -= to_int(item.first);
256 str = item.second + str;
265 template<
typename attribute_t>
266 static enum_type to_enum(attribute_t value) noexcept {
return static_cast<enum_type
>(
value);}
267 static int64 to_int(enum_type value) noexcept {
return static_cast<int64>(
value);}
270 if (attribute_.has_value())
return attribute_.
value();
272 return attribute_.value();
276 if (entries_.has_value())
return entries_.
value();
278 return entries_.value();
281 static void init() noexcept {
286 inline static std::optional<xtd::enum_attribute> attribute_;
287 inline static std::optional<enum_collection<enum_type>> entries_;
304 template<
typename enum_t>
311 template<
typename enum_t>
320 template<
typename enum_t>
329 template<
typename enum_t>
338 template<
typename enum_t>
347 template<
typename enum_t>
356 template<
typename enum_t>
365 template<
typename enum_t>
374 template<
typename enum_t>
385 template<
typename enum_t>
391 template<
typename enum_t>
397 template<
typename enum_t>
403 template<
typename enum_t>
409 template<
typename enum_t>
411 std::vector<xtd::ustring> names;
419 template<
typename enum_t>
421 std::vector<enum_t> values;
429 template<
typename enum_t>
431 std::vector<xtd::byte> values;
439 template<
typename enum_t>
441 std::vector<int16> values;
449 template<
typename enum_t>
451 std::vector<int32> values;
459 template<
typename enum_t>
461 std::vector<int64> values;
469 template<
typename enum_t>
471 std::vector<sbyte> values;
479 template<
typename enum_t>
481 std::vector<uint16> values;
489 template<
typename enum_t>
491 std::vector<uint32> values;
499 template<
typename enum_t>
501 std::vector<uint64> values;
510 template<
typename enum_t>
516 template<
typename enum_t>
523 template<
typename enum_t>
530 template<
typename enum_t>
538 template<
typename enum_t>
544 template<
typename enum_t>
550 template<
typename enum_t>
556 template<
typename enum_t>
562 template<
typename enum_t>
568 template<
typename enum_t>
574 template<
typename enum_t>
580 template<
typename enum_t>
586 template<
typename enum_t>
593 template<
typename enum_t>
601 template<
typename enum_t>
604 result = parse<enum_t>(
value, ignore_case);
614 template<
typename type_t>
622 template<
typename enum_t>
623 inline std::string __enum_to_string(enum_t
value) noexcept {
627 template<
typename value_t>
628 value_t __parse_enum(
const std::string& str) {
int64 to_int64() const noexcept
Converts this instance to int64.
Definition: enum_object.h:114
static xtd::ustring get_name(int64 value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value...
Definition: enum_object.h:404
static xtd::ustring to_string(enum_t value) noexcept
Converts this instance to string.
Definition: enum_object.h:569
Contains xtd::static_object class.
static xtd::ustring get_name(enum_t value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value...
Definition: enum_object.h:386
Contains xtd::enum_set_attribute strcut.
static std::vector< sbyte > get_values_as_sbyte() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:470
int16 to_int16() const noexcept
Converts this instance to int16.
Definition: enum_object.h:106
static bool is_defined(enum_object< enum_t > value) noexcept
Returns an indication whether a constant with a specified value exists in a specified enumeration...
Definition: enum_object.h:517
xtd::ustring to_string(const xtd::ustring &format) const
Converts the value of this instance to its equivalent string representation using the specified forma...
Definition: enum_object.h:158
static std::vector< xtd::ustring > get_names() noexcept
Retrieves an array of the names of the constants in a specified enumeration.
Definition: enum_object.h:410
Contains std::optional type and std::bad_optional_access exception.
static xtd::enum_collection< uint32 > get_entries_as_uint32() noexcept
Retrieves an array of the std::pair<uint32, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:366
Contains xtd::iequatable interface.
int_least8_t sbyte
Represents a 8-bit signed integer.
Definition: types.h:173
value_t parse(const std::string &str)
Convert a string into a type.
Definition: parse.h:23
static int16 to_int16(enum_t value) noexcept
Converts this instance to int16.
Definition: enum_object.h:545
enum_attribute
Specifies the enum attribute.
Definition: enum_attribute.h:20
Contains xtd::icomparable interface.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition: static.h:37
sbyte to_sbyte() const noexcept
Converts this instance to signed byte.
Definition: enum_object.h:118
static uint32 to_uint32(enum_t value) noexcept
Converts this instance to unsigned int32.
Definition: enum_object.h:581
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition: icomparable.h:17
static std::vector< int16 > get_values_as_int16() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:440
Represents the base class for custom attributes.
Definition: attribute.h:23
bool has_flag(enum_type flag) const noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:78
enum_object & value(enum_type value)
Sets the value of the enum.
Definition: enum_object.h:85
uint64 to_uint64() const noexcept
Converts this instance to unsigned int64.
Definition: enum_object.h:130
static std::vector< int32 > get_values_as_int32() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:450
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
static uint64 to_uint64(enum_t value) noexcept
Converts this instance to unsigned int64.
Definition: enum_object.h:587
static std::vector< uint16 > get_values_as_uint16() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:480
Contains xtd::enum_attribute enum class.
static xtd::enum_collection< uint16 > get_entries_as_uint16() noexcept
Retrieves an array of the std::pair<uint16, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:357
static int32 to_int32(enum_t value) noexcept
Converts this instance to int32.
Definition: enum_object.h:551
#define csf_
Provides information about the current stack frame.
Definition: current_stack_frame.h:30
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition: types.h:228
uint32 to_uint32() const noexcept
Converts this instance to unsigned int32.
Definition: enum_object.h:126
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
std::vector< std::pair< enum_t, xtd::ustring > > enum_collection
Represents a pair of an enum_t value and a string of an enum of type enum_t.
Definition: enum_collection.h:19
static int64 to_int64(enum_t value) noexcept
Converts this instance to int64.
Definition: enum_object.h:557
ustring trim() const noexcept
Removes all leading and trailing occurrences of white-space characters from the specified xtd::ustrin...
static uint16 to_uint16(enum_t value) noexcept
Converts this instance to unsigned int16.
Definition: enum_object.h:575
static int32 compare(const ustring &str_a, const ustring &str_b) noexcept
Compares two specified string objects and returns an integer that indicates their relative position i...
static bool is_defined(enum_t value) noexcept
Returns an indication whether a constant with a specified value exists in a specified enumeration...
Definition: enum_object.h:511
uint16 to_uint16() const noexcept
Converts this instance to unsigned int16.
Definition: enum_object.h:122
int32 to_int32() const noexcept
Converts this instance to int32.
Definition: enum_object.h:110
static xtd::enum_collection< sbyte > get_entries_as_sbyte() noexcept
Retrieves an array of the std::pair<sbyte, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:348
static bool try_parse(const xtd::ustring &value, bool ignore_case, enum_t &result) noexcept
Converts the xtd::ustring representation of the name or numeric value of one or more enumerated const...
Definition: enum_object.h:602
bool is_empty() const noexcept
Indicates whether this string is an empty string ("").
Definition: ustring.h:918
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
Provides the set attribute struct for enumerations.
Definition: enum_set_attribute.h:29
std::vector< ustring > split(const std::vector< value_type > &separators, size_t count, string_split_options options) const noexcept
Splits this string into a maximum number of substrings based on the characters in an array...
enum_type value() const noexcept
Gets the value of the enum.
Definition: enum_object.h:82
bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
Contains xtd::enum_register.
static xtd::ustring get_name(enum_object< enum_t > value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value...
Definition: enum_object.h:392
static std::vector< uint64 > get_values_as_uint64() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:500
enum_object(enum_type value)
Initializes a new instance of the xtd::enum_object class with specified value.
Definition: enum_object.h:53
static const xtd::enum_collection< enum_t > & get_entries() noexcept
Retrieves an array of the std::pair<enum_t, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:305
int_least16_t int16
Represents a 16-bit signed integer.
Definition: types.h:118
static enum_t parse(const xtd::ustring &value)
Converts the xtd::ustring representation of the name or numeric value of one or more enumerated const...
Definition: enum_object.h:524
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Provides the base class for enumerations.
Definition: enum_object.h:38
int32 compare_to(const enum_object &value) const noexcept override
Compares the current instance with another object of the same type.
Definition: enum_object.h:94
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains xtd::string_split_options enum class.
static xtd::ustring get_name(int32 value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value...
Definition: enum_object.h:398
static enum_t parse(const xtd::ustring &str, bool ignore_case)
Converts the xtd::ustring representation of the name or numeric value of one or more enumerated const...
Definition: enum_object.h:531
static xtd::enum_collection< int64 > get_entries_as_int64() noexcept
Retrieves an array of the std::pair<int64, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:339
static sbyte to_sbyte(enum_t value) noexcept
Converts this instance to signed byte.
Definition: enum_object.h:563
enum_object() noexcept=default
Initializes a new instance of the xtd::enum_object class.
static std::vector< xtd::byte > get_values_as_byte() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:430
static xtd::enum_collection< xtd::byte > get_entries_as_byte() noexcept
Retrieves an array of the std::pair<xtd::byte, xtd::ustring> of the constants in a specified enumerat...
Definition: enum_object.h:312
xtd::byte to_byte() const noexcept
Converts this instance to byte.
Definition: enum_object.h:102
Contains xtd::enum_collection.
static std::vector< int64 > get_values_as_int64() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:460
static std::vector< enum_t > get_values() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:420
static xtd::enum_collection< int16 > get_entries_as_int16() noexcept
Retrieves an array of the std::pair<int16, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:321
static std::vector< uint32 > get_values_as_uint32() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:490
xtd::ustring to_string() const noexcept override
Returns a sxd::ustring that represents the current object.
Definition: enum_object.h:132
uint_least64_t uint64
Represents a 64-bit unsigned integer.
Definition: types.h:250
int_least64_t int64
Represents a 64-bit signed integer.
Definition: types.h:140
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition: types.h:39
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:239
static xtd::enum_collection< int32 > get_entries_as_int32() noexcept
Retrieves an array of the std::pair<int32, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:330
Contains xtd::number_styles enum class.
Contains xtd::string_comparison enum class.
static xtd::enum_collection< uint64 > get_entries_as_uint64() noexcept
Retrieves an array of the std::pair<uint64, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:375
Provides the registration struct for enumerations.
Definition: enum_register.h:36
static xtd::byte to_byte(enum_t value) noexcept
Converts this instance to byte.
Definition: enum_object.h:539
static bool try_parse(const xtd::ustring &value, enum_t &result) noexcept
Converts the xtd::ustring representation of the name or numeric value of one or more enumerated const...
Definition: enum_object.h:594