xtd 0.2.0
enum_object.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "array.hpp"
6#include "enum_attribute.hpp"
7#include "enum_collection.hpp"
8#include "enum_register.hpp"
10#include "format_exception.hpp"
11#include "icomparable.hpp"
12#include "iequatable.hpp"
13#include "iformatable.hpp"
14#include "literals.hpp"
15#include "number_styles.hpp"
16#include "optional.hpp"
17#include "static.hpp"
18#include "string_comparison.hpp"
20
22namespace xtd {
24
48 template<class enum_t = std::nullptr_t>
49 struct enum_object : xtd::object, xtd::icomparable<enum_object<enum_t>>, xtd::iequatable<enum_object<enum_t>>, xtd::iformatable {
51
54 using enum_type = enum_t;
56 using value_type = enum_t;
58
60
63 enum_object() noexcept = default;
68
70 explicit enum_object(xtd::byte value) : value(to_enum(value)) {}
71 explicit enum_object(sbyte value) : value(to_enum(value)) {}
72 explicit enum_object(int16 value) : value(to_enum(value)) {}
73 explicit enum_object(int32 value) : value(to_enum(value)) {}
74 explicit enum_object(int64 value) : value(to_enum(value)) {}
75 explicit enum_object(uint16 value) : value(to_enum(value)) {}
76 explicit enum_object(uint32 value) : value(to_enum(value)) {}
77 explicit enum_object(uint64 value) : value(to_enum(value)) {}
78 enum_object(enum_object&&) noexcept = default;
79 enum_object(const enum_object&) noexcept = default;
80 enum_object& operator =(const enum_object&) noexcept = default;
81 operator enum_type() const noexcept {return value;}
83
85
91 bool has_flag(enum_type flag) const noexcept {return (to_int(value) & to_int(flag)) == to_int(flag);}
92
97
99
111 int32 compare_to(const enum_object& value) const noexcept override {
112 if (to_int(this->value) == to_int(value.value)) return 0;
113 if (to_int(this->value) < to_int(value.value)) return -1;
114 return 1;
115 }
116
120 bool equals(const object& obj) const noexcept override {return dynamic_cast<const enum_object*>(&obj) && equals(static_cast<const enum_object&>(obj));}
124 bool equals(const enum_object& value) const noexcept override {return this->value == value.value;}
128 bool equals(enum_type value) const noexcept {return this->value == value;}
132 template<class attribute_t>
133 bool equals(attribute_t value) const noexcept {return false;}
134
137 xtd::size get_hash_code() const noexcept override {return hash_code::combine(value);}
138
141 xtd::byte to_byte() const noexcept {return static_cast<xtd::byte>(value);}
142
145 int16 to_int16() const noexcept {return static_cast<int16>(value);}
146
149 int32 to_int32() const noexcept {return static_cast<int32>(value);}
150
153 int64 to_int64() const noexcept {return static_cast<int64>(value);}
154
157 sbyte to_sbyte() const noexcept {return static_cast<sbyte>(value);}
158
161 uint16 to_uint16() const noexcept {return static_cast<uint16>(value);}
162
165 uint32 to_uint32() const noexcept {return static_cast<uint32>(value);}
166
169 uint64 to_uint64() const noexcept {return static_cast<uint64>(value);}
170
173 xtd::string to_string() const noexcept override {
174 init();
175 if (attribute() == xtd::enum_attribute::flags) return to_string_flags();
176
177 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
178 if (iterator == entries().end()) return string::format("{}", to_int(value));
179
180 return iterator->second;
181 }
182
199 xtd::string to_string(const xtd::string& format) const {return to_string(format, std::locale {});}
200
218 xtd::string to_string(const xtd::string& format, const std::locale& loc) const override;
220
222
228 static enum_type parse(const xtd::string& str) {return parse(str, false);}
233 static enum_type parse(const xtd::string& str, bool ignore_case) {
234 enum_object<enum_type>().init();
235 if (enum_object<enum_type>().attribute() == xtd::enum_attribute::flags) return parse_flags(str, ignore_case);
236
237 for (auto item : enum_object<enum_type>().entries()) {
238 if (xtd::string::compare(str, item.second, ignore_case) == 0)
239 return static_cast<enum_type>(item.first);
240 }
241
242 return to_enum(xtd::parse<int64>(str));
243 }
245
246 private:
247 friend struct enum_object<std::nullptr_t>;
248
249 xtd::string get_name() const noexcept {
250 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
251 if (iterator == entries().end()) return xtd::string::format("{}", to_int(value));
252 return iterator->second;
253 }
254
255 static enum_type parse_flags(const xtd::string& value, bool ignore_case) {
256 xtd::array<xtd::string> values = value.split(',');
257 for (xtd::string& str : values)
258 str = str.trim(' ');
259
260 if (values.size() == 1) {
261 for (auto item : enum_object<enum_type>().entries()) {
262 if (xtd::string::compare(value, item.second, ignore_case) == 0)
263 return to_enum(item.first);
264 }
265 return to_enum(xtd::parse<int64>(value));
266 }
267
268 int64 result = 0;
269 for (xtd::string str : values) {
270 bool found = false;
271 for (auto item : enum_object<enum_type>().entries()) {
272 if (xtd::string::compare(str, item.second, ignore_case) == 0) {
273 found = true;
274 result |= to_int(item.first);
275 break;
276 }
277 }
278 if (found == false)
280 }
281
282 return to_enum(result);
283 }
284
285 xtd::string to_string_flags() const noexcept {
286 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
287 if (to_int(value) == 0 && iterator == entries().end()) return "0";
288
289 iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == to_enum(0);});
290 if (to_int(value) == 0) return iterator == entries().end() ? "0" : iterator->second;
291
292 xtd::string str;
293 int64 rest = to_int(value);
294 enum_collection<enum_type> reversed_entries = entries();
295 std::reverse(reversed_entries.begin(), reversed_entries.end());
296
297 for (auto item : reversed_entries) {
298 if (to_int(item.first) != 0 && (rest & to_int(item.first)) == to_int(item.first)) {
299 rest -= to_int(item.first);
300 if (!xtd::string::is_empty(str)) str = ", " + str;
301 str = item.second + str;
302 }
303 }
304
305 if (str.empty() || rest > 0) return xtd::string::format("{}", to_int(value));
306
307 return str;
308 }
309
310 template<class attribute_t>
311 static enum_type to_enum(attribute_t value) noexcept {return static_cast<enum_type>(value);}
312 static int64 to_int(enum_type value) noexcept {return static_cast<int64>(value);}
313
314 static xtd::enum_attribute attribute() noexcept {
315 if (attribute_.has_value()) return attribute_.value();
316 attribute_ = xtd::enum_attribute(enum_set_attribute<enum_type>());
317 return attribute_.value();
318 }
319
320 static enum_collection<enum_type>& entries() noexcept {
321 if (entries_.has_value()) return entries_.value();
322 entries_ = enum_collection<enum_type>(enum_register<enum_type>());
323 return entries_.value();
324 };
325
326 static void init() noexcept {
327 attribute();
328 entries();
329 }
330
331 inline static std::optional<xtd::enum_attribute> attribute_;
332 inline static std::optional<enum_collection<enum_type>> entries_;
333 };
334
345 template<>
346 struct enum_object<std::nullptr_t> static_ {
348
351
354
358 template<class enum_t>
359 static const xtd::enum_collection<enum_t>& get_entries() noexcept {
360 return enum_object<enum_t>().entries();
361 }
362
365 template<class enum_t>
368 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_byte(), entry.second);});
369 return entries;
370 }
371
374 template<class enum_t>
377 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_int16(), entry.second);});
378 return entries;
379 }
380
383 template<class enum_t>
386 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_int32(), entry.second);});
387 return entries;
388 }
389
392 template<class enum_t>
395 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_int64(), entry.second);});
396 return entries;
397 }
398
401 template<class enum_t>
404 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_sbyte(), entry.second);});
405 return entries;
406 }
407
410 template<class enum_t>
413 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_uint16(), entry.second);});
414 return entries;
415 }
416
419 template<class enum_t>
422 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_uint32(), entry.second);});
423 return entries;
424 }
425
428 template<class enum_t>
431 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_uint64(), entry.second);});
432 return entries;
433 }
434
439 template<class enum_t>
440 static xtd::string get_name(enum_t value) noexcept {return enum_object<enum_t>(value).to_string();}
445 template<class enum_t>
451 template<class enum_t>
457 template<class enum_t>
459
463 template<class enum_t>
465 auto names = xtd::array<xtd::string> {};
466 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {names.resize(names.size() + 1, entry.second);});
467 return names;
468 }
469
473 template<class enum_t>
474 static xtd::array<enum_t> get_values() noexcept {
475 auto values = xtd::array<enum_t> {};
476 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, entry.first);});
477 return values;
478 }
479
483 template<class enum_t>
485 auto values = xtd::array<xtd::byte> {};
486 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, enum_object<enum_t>(entry.first).to_byte());});
487 return values;
488 }
489
493 template<class enum_t>
495 auto values = xtd::array<xtd::int16> {};
496 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, enum_object<enum_t>(entry.first).to_int16());});
497 return values;
498 }
499
503 template<class enum_t>
505 auto values = xtd::array<xtd::int32> {};
506 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, enum_object<enum_t>(entry.first).to_int32());});
507 return values;
508 }
509
513 template<class enum_t>
515 auto values = xtd::array<xtd::int64> {};
516 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, enum_object<enum_t>(entry.first).to_int64());});
517 return values;
518 }
519
523 template<class enum_t>
525 auto values = xtd::array<xtd::sbyte> {};
526 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, enum_object<enum_t>(entry.first).to_sbyte());});
527 return values;
528 }
529
533 template<class enum_t>
535 auto values = xtd::array<xtd::uint16> {};
536 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, enum_object<enum_t>(entry.first).to_uint16());});
537 return values;
538 }
539
543 template<class enum_t>
545 auto values = xtd::array<xtd::uint32> {};
546 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, enum_object<enum_t>(entry.first).to_uint32());});
547 return values;
548 }
549
553 template<class enum_t>
555 auto values = xtd::array<xtd::uint64> {};
556 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.size() + 1, enum_object<enum_t>(entry.first).to_uint64());});
557 return values;
558 }
559
564 template<class enum_t>
565 static bool is_defined(enum_t value) noexcept {return std::find_if(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto item)->bool {return item.first == value;}) != enum_object<enum_t>().entries().end();}
570 template<class enum_t>
571 static bool is_defined(enum_object<enum_t> value) noexcept {return std::find_if(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto item)->bool {return item.first == value;}) != enum_object<enum_t>().entries().end();}
572
577 template<class enum_t>
578 static enum_t parse(const xtd::string& value) {return parse<enum_t>(value, false);}
584 template<class enum_t>
585 static enum_t parse(const xtd::string& str, bool ignore_case) {
586 return enum_object<enum_t>::parse(str, ignore_case);
587 }
588
592 template<class enum_t>
593 static xtd::byte to_byte(enum_t value) noexcept {return enum_object<enum_t>(value).to_byte();}
594
598 template<class enum_t>
599 static int16 to_int16(enum_t value) noexcept {return enum_object<enum_t>(value).to_int16();}
600
604 template<class enum_t>
605 static int32 to_int32(enum_t value) noexcept {return enum_object<enum_t>(value).to_int32();}
606
610 template<class enum_t>
611 static int64 to_int64(enum_t value) noexcept {return enum_object<enum_t>(value).to_int64();}
612
616 template<class enum_t>
617 static sbyte to_sbyte(enum_t value) noexcept {return enum_object<enum_t>(value).to_sbyte();}
618
622 template<class enum_t>
623 static xtd::string to_string(enum_t value) noexcept {return enum_object<enum_t>(value).to_string();}
624
628 template<class enum_t>
629 static uint16 to_uint16(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint16();}
630
634 template<class enum_t>
635 static uint32 to_uint32(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint32();}
636
640 template<class enum_t>
641 static uint64 to_uint64(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint64();}
642
647 template<class enum_t>
648 static bool try_parse(const xtd::string& value, enum_t& result) noexcept {return try_parse<enum_t>(value, false, result);}
649
655 template<class enum_t>
656 static bool try_parse(const xtd::string& value, bool ignore_case, enum_t& result) noexcept {
657 try {
658 result = parse<enum_t>(value, ignore_case);
659 return true;
660 } catch (...) {
661 return false;
662 }
663 }
665 };
667
669 template<class enum_t>
670 xtd::string enum_object<enum_t>::to_string(const xtd::string& format, const std::locale& loc) const {
671 init();
672 auto fmt = format;
673 if (fmt.empty()) fmt = "G";
674
675 switch (fmt[0]) {
676 case 'b':
677 case 'B':
678 case 'd':
679 case 'D':
680 case 'o':
681 case 'O':
682 case 'x':
683 case 'X': return __numeric_formatter(fmt.chars(), static_cast<long long int>(value), std::locale());
684 case 'f':
685 case 'F':
686 case 'g':
687 case 'G': return xtd::enum_object<>::get_name(value);
688 }
690 }
692}
693
695template<class enum_t>
696inline std::string __enum_to_string__(enum_t value) noexcept {
697 return xtd::enum_object<>::get_name(value);
698}
699
700template<class value_t>
701value_t __parse_enum(const std::string& str) {
703}
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
Represents the base class for custom attributes.
Definition attribute.hpp:25
void resize(size_type new_size)
Resizes the container to contain count elements, does nothing if count == size(). @param new_size The...
Definition basic_array.hpp:377
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::array::begin(),...
Definition basic_array.hpp:229
Represents text as a sequence of character units.
Definition basic_string.hpp:71
bool is_empty() const noexcept
Indicates whether this basic_string is an empty basic_string ("").
Definition basic_string.hpp:1503
int32 compare(const basic_string &str) const
Compares two character sequences.
Definition basic_string.hpp:955
bool empty() const noexcept
Checks if the string has no characters, i.e. whether begin() == end().
Definition basic_string.hpp:896
static xtd::size combine(args_t... values) noexcept
Combines values into a hash code.
Definition hash_code.hpp:70
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:35
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
Contains xtd::enum_attribute enum class.
Contains xtd::enum_collection.
Contains xtd::enum_register.
Contains xtd::enum_set_attribute strcut.
Contains xtd::format_exception exception.
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:20
@ format
The format is not valid.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
enum_attribute
Specifies the enum attribute.
Definition enum_attribute.hpp:22
std::vector< xtd::collections::generic::key_value_pair< enum_t, xtd::string > > enum_collection
Represents a pair of an enum_t value and a string of an enum of type enum_t.
Definition enum_collection.hpp:23
@ flags
Enum flags attribute.
@ begin
Specifies the beginning of a stream.
@ end
The END key.
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
Contains xtd::iformatable interface.
Contains xtd literals.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::number_styles enum class.
Contains xtd::optional type.
Contains xtd::static_object class.
Contains xtd::string_comparison enum class.
Contains xtd::string_split_options enum class.
static enum_t parse(const xtd::string &value)
Converts the xtd::string representation of the name or numeric value of one or more enumerated consta...
Definition enum_object.hpp:578
static xtd::array< xtd::byte > get_values_as_byte() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:484
static xtd::enum_collection< uint32 > get_entries_as_uint32() noexcept
Retrieves an array of the xtd::enum_collection<uint32> of the constants in a specified enumeration.
Definition enum_object.hpp:420
static xtd::array< uint16 > get_values_as_uint16() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:534
static xtd::enum_collection< int32 > get_entries_as_int32() noexcept
Retrieves an array of the xtd::enum_collection<int32> of the constants in a specified enumeration.
Definition enum_object.hpp:384
static xtd::array< int32 > get_values_as_int32() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:504
static xtd::string get_name(int32 value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition enum_object.hpp:452
static bool try_parse(const xtd::string &value, bool ignore_case, enum_t &result) noexcept
Converts the xtd::string representation of the name or numeric value of one or more enumerated consta...
Definition enum_object.hpp:656
static xtd::string to_string(enum_t value) noexcept
Converts this instance to string.
Definition enum_object.hpp:623
static int16 to_int16(enum_t value) noexcept
Converts this instance to int16.
Definition enum_object.hpp:599
static xtd::string 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.hpp:446
static xtd::array< uint64 > get_values_as_uint64() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:554
static xtd::array< sbyte > get_values_as_sbyte() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:524
static xtd::enum_collection< int64 > get_entries_as_int64() noexcept
Retrieves an array of the xtd::enum_collection<int64> of the constants in a specified enumeration.
Definition enum_object.hpp:393
static bool try_parse(const xtd::string &value, enum_t &result) noexcept
Converts the xtd::string representation of the name or numeric value of one or more enumerated consta...
Definition enum_object.hpp:648
static xtd::array< xtd::string > get_names() noexcept
Retrieves an array of the names of the constants in a specified enumeration.
Definition enum_object.hpp:464
static sbyte to_sbyte(enum_t value) noexcept
Converts this instance to signed byte.
Definition enum_object.hpp:617
static xtd::array< int16 > get_values_as_int16() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:494
static xtd::string get_name(int64 value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition enum_object.hpp:458
static const xtd::enum_collection< enum_t > & get_entries() noexcept
Retrieves an array of the xtd::enum_collection<enum_t> of the constants in a specified enumeration.
Definition enum_object.hpp:359
static xtd::array< enum_t > get_values() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:474
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.hpp:565
static xtd::byte to_byte(enum_t value) noexcept
Converts this instance to byte.
Definition enum_object.hpp:593
static xtd::enum_collection< uint16 > get_entries_as_uint16() noexcept
Retrieves an array of the xtd::enum_collection<uint16> of the constants in a specified enumeration.
Definition enum_object.hpp:411
static xtd::enum_collection< xtd::byte > get_entries_as_byte() noexcept
Retrieves an array of the xtd::enum_collection<xtd::byte> of the constants in a specified enumeration...
Definition enum_object.hpp:366
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.hpp:571
static int32 to_int32(enum_t value) noexcept
Converts this instance to int32.
Definition enum_object.hpp:605
static uint32 to_uint32(enum_t value) noexcept
Converts this instance to unsigned int32.
Definition enum_object.hpp:635
static int64 to_int64(enum_t value) noexcept
Converts this instance to int64.
Definition enum_object.hpp:611
static enum_t parse(const xtd::string &str, bool ignore_case)
Converts the xtd::string representation of the name or numeric value of one or more enumerated consta...
Definition enum_object.hpp:585
static uint16 to_uint16(enum_t value) noexcept
Converts this instance to unsigned int16.
Definition enum_object.hpp:629
static uint64 to_uint64(enum_t value) noexcept
Converts this instance to unsigned int64.
Definition enum_object.hpp:641
static xtd::array< int64 > get_values_as_int64() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:514
static xtd::enum_collection< sbyte > get_entries_as_sbyte() noexcept
Retrieves an array of the xtd::enum_collection<sbyte> of the constants in a specified enumeration.
Definition enum_object.hpp:402
static xtd::string get_name(enum_t value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition enum_object.hpp:440
static xtd::enum_collection< uint64 > get_entries_as_uint64() noexcept
Retrieves an array of the xtd::enum_collection<uint64> of the constants in a specified enumeration.
Definition enum_object.hpp:429
static xtd::enum_collection< int16 > get_entries_as_int16() noexcept
Retrieves an array of the xtd::enum_collection<int16> of the constants in a specified enumeration.
Definition enum_object.hpp:375
static xtd::array< uint32 > get_values_as_uint32() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:544
Provides the base class for enumerations.
Definition enum_object.hpp:49
bool has_flag(enum_type flag) const noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:91
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition enum_object.hpp:120
int64 to_int64() const noexcept
Converts this instance to int64.
Definition enum_object.hpp:153
uint32 to_uint32() const noexcept
Converts this instance to unsigned int32.
Definition enum_object.hpp:165
xtd::string to_string(const xtd::string &format) const
Converts the value of this instance to its equivalent string representation using the specified forma...
Definition enum_object.hpp:199
uint16 to_uint16() const noexcept
Converts this instance to unsigned int16.
Definition enum_object.hpp:161
sbyte to_sbyte() const noexcept
Converts this instance to signed byte.
Definition enum_object.hpp:157
enum_t value_type
Represents the enumeration type.
Definition enum_object.hpp:56
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
Definition enum_object.hpp:137
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition enum_object.hpp:173
bool equals(const enum_object &value) const noexcept override
Determines whether the specified object is equal to the current object.
Definition enum_object.hpp:124
static enum_type parse(const xtd::string &str)
Converts the string to its enum_type equivalent.
Definition enum_object.hpp:228
enum_t enum_type
Represents the enumeration type.
Definition enum_object.hpp:54
xtd::byte to_byte() const noexcept
Converts this instance to byte.
Definition enum_object.hpp:141
uint64 to_uint64() const noexcept
Converts this instance to unsigned int64.
Definition enum_object.hpp:169
bool equals(attribute_t value) const noexcept
Indicates whether the current object is equal to another object with defferent type.
Definition enum_object.hpp:133
int32 to_int32() const noexcept
Converts this instance to int32.
Definition enum_object.hpp:149
enum_object() noexcept=default
Initializes a new instance of the xtd::enum_object class.
bool equals(enum_type value) const noexcept
Indicates whether the current object is equal to another object of the same type.
Definition enum_object.hpp:128
enum_type value
Gets or sets the value of the enum.
Definition enum_object.hpp:95
static enum_type parse(const xtd::string &str, bool ignore_case)
Converts the string to its enum_type equivalent with a specified boolean to ignore case.
Definition enum_object.hpp:233
int16 to_int16() const noexcept
Converts this instance to int16.
Definition enum_object.hpp:145
int32 compare_to(const enum_object &value) const noexcept override
Compares the current instance with another object of the same type.
Definition enum_object.hpp:111
xtd::string to_string(const xtd::string &format, const std::locale &loc) const override
Converts the value of this instance to its equivalent string representation using the specified forma...