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_);
184 template<
typename attribute_t>
185 bool equals(attribute_t
value)
const noexcept {
return false;}
189 enum_object<enum_type>().init();
192 for (
auto item :
enum_object<enum_type>().entries()) {
194 return static_cast<enum_type
>(item.first);
197 return to_enum(xtd::parse<int64>(str));
201 std::vector<xtd::ustring> values =
value.split({
','});
205 if (values.size() == 1) {
206 for (
auto item :
enum_object<enum_type>().entries()) {
208 return to_enum(item.first);
210 return to_enum(xtd::parse<int64>(
value));
216 for (
auto item :
enum_object<enum_type>().entries()) {
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_);
249 enum_collection<enum_type> reversed_entries = entries();
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);}
270 if (attribute_.has_value())
return attribute_.value();
272 return attribute_.value();
275 static enum_collection<enum_type>& entries() noexcept {
276 if (entries_.has_value())
return entries_.value();
277 entries_ = enum_collection<enum_type>(enum_register<enum_type>());
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_;
307 template<
typename enum_t>
314 template<
typename enum_t>
323 template<
typename enum_t>
332 template<
typename enum_t>
341 template<
typename enum_t>
350 template<
typename enum_t>
359 template<
typename enum_t>
368 template<
typename enum_t>
377 template<
typename enum_t>
388 template<
typename enum_t>
394 template<
typename enum_t>
400 template<
typename enum_t>
406 template<
typename enum_t>
412 template<
typename enum_t>
414 std::vector<xtd::ustring> names;
422 template<
typename enum_t>
424 std::vector<enum_t> values;
432 template<
typename enum_t>
434 std::vector<xtd::byte> values;
442 template<
typename enum_t>
444 std::vector<int16> values;
452 template<
typename enum_t>
454 std::vector<int32> values;
462 template<
typename enum_t>
464 std::vector<int64> values;
472 template<
typename enum_t>
474 std::vector<sbyte> values;
482 template<
typename enum_t>
484 std::vector<uint16> values;
492 template<
typename enum_t>
494 std::vector<uint32> values;
502 template<
typename enum_t>
504 std::vector<uint64> values;
513 template<
typename enum_t>
519 template<
typename enum_t>
526 template<
typename enum_t>
533 template<
typename enum_t>
541 template<
typename enum_t>
547 template<
typename enum_t>
553 template<
typename enum_t>
559 template<
typename enum_t>
565 template<
typename enum_t>
571 template<
typename enum_t>
577 template<
typename enum_t>
583 template<
typename enum_t>
589 template<
typename enum_t>
596 template<
typename enum_t>
604 template<
typename enum_t>
607 result = parse<enum_t>(
value, ignore_case);
618 template<
typename type_t>
626template<
typename enum_t>
627inline std::string __enum_to_string(enum_t value)
noexcept {
631template<
typename value_t>
632value_t __parse_enum(
const std::string& str) {
Represents the base class for custom attributes.
Definition attribute.h:23
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:463
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:407
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:369
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:333
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:483
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:453
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:527
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:395
static int16 to_int16(enum_t value) noexcept
Converts this instance to int16.
Definition enum_object.h:548
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:342
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:443
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:473
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:534
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:597
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:493
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:423
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:401
static sbyte to_sbyte(enum_t value) noexcept
Converts this instance to signed byte.
Definition enum_object.h:566
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:389
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:308
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:605
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:514
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:503
static xtd::byte to_byte(enum_t value) noexcept
Converts this instance to byte.
Definition enum_object.h:542
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:360
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:315
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:520
static xtd::ustring to_string(enum_t value) noexcept
Converts this instance to string.
Definition enum_object.h:572
static int32 to_int32(enum_t value) noexcept
Converts this instance to int32.
Definition enum_object.h:554
static uint32 to_uint32(enum_t value) noexcept
Converts this instance to unsigned int32.
Definition enum_object.h:584
static int64 to_int64(enum_t value) noexcept
Converts this instance to int64.
Definition enum_object.h:560
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:433
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:413
static uint16 to_uint16(enum_t value) noexcept
Converts this instance to unsigned int16.
Definition enum_object.h:578
static uint64 to_uint64(enum_t value) noexcept
Converts this instance to unsigned int64.
Definition enum_object.h:590
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:351
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:378
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:324
Provides the base class for enumerations.
Definition enum_object.h:38
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
int64 to_int64() const noexcept
Converts this instance to int64.
Definition enum_object.h:114
uint32 to_uint32() const noexcept
Converts this instance to unsigned int32.
Definition enum_object.h:126
uint16 to_uint16() const noexcept
Converts this instance to unsigned int16.
Definition enum_object.h:122
enum_type value() const noexcept
Gets the value of the enum.
Definition enum_object.h:82
sbyte to_sbyte() const noexcept
Converts this instance to signed byte.
Definition enum_object.h:118
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
enum_object & value(enum_type value)
Sets the value of the enum.
Definition enum_object.h:85
xtd::ustring to_string() const noexcept override
Returns a sxd::ustring that represents the current object.
Definition enum_object.h:132
xtd::byte to_byte() const noexcept
Converts this instance to byte.
Definition enum_object.h:102
uint64 to_uint64() const noexcept
Converts this instance to unsigned int64.
Definition enum_object.h:130
int32 to_int32() const noexcept
Converts this instance to int32.
Definition enum_object.h:110
enum_object() noexcept=default
Initializes a new instance of the xtd::enum_object class.
int16 to_int16() const noexcept
Converts this instance to int16.
Definition enum_object.h:106
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.h:17
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:18
virtual bool equals(const type_t &) const noexcept=0
Indicates whether the current object is equal to another object of the same type.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
bool is_empty() const noexcept
Indicates whether this string is an empty string ("").
Definition ustring.h:597
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...
Contains xtd::enum_attribute enum class.
Contains xtd::enum_collection.
Contains xtd::enum_register.
Contains xtd::enum_set_attribute strcut.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h:37
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
int_least16_t int16
Represents a 16-bit signed integer.
Definition types.h:120
int_least8_t sbyte
Represents a 8-bit signed integer.
Definition types.h:175
int_least64_t int64
Represents a 64-bit signed integer.
Definition types.h:142
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition types.h:230
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
uint_least64_t uint64
Represents a 64-bit unsigned integer.
Definition types.h:252
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition types.h:241
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition types.h:41
enum_attribute
Specifies the enum attribute.
Definition enum_attribute.h:20
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
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition date_time.h:1080
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.h:34
@ flags
Enum flags attribute.
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::number_styles enum class.
Contains std::optional type and std::bad_optional_access exception.
Contains xtd::static_object class.
Contains xtd::string_comparison enum class.
Contains xtd::string_split_options enum class.