xtd 0.2.0
enum_object.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "enum_attribute.hpp"
6#include "enum_collection.hpp"
7#include "enum_register.hpp"
10#include "icomparable.hpp"
11#include "iequatable.hpp"
12#include "iformatable.hpp"
13#include "literals.hpp"
14#include "number_styles.hpp"
15#include "optional.hpp"
16#include "static.hpp"
17#include "string_comparison.hpp"
19
21namespace xtd {
23
47 template<class enum_t = std::nullptr_t>
48 struct enum_object : xtd::object, xtd::icomparable<enum_object<enum_t>>, xtd::iequatable<enum_object<enum_t>>, xtd::iformatable {
50
53 using enum_type = enum_t;
55 using value_type = enum_t;
57
59
62 enum_object() noexcept = default;
67
69 explicit enum_object(xtd::byte value) : value(to_enum(value)) {}
70 explicit enum_object(sbyte value) : value(to_enum(value)) {}
71 explicit enum_object(int16 value) : value(to_enum(value)) {}
72 explicit enum_object(int32 value) : value(to_enum(value)) {}
73 explicit enum_object(int64 value) : value(to_enum(value)) {}
74 explicit enum_object(uint16 value) : value(to_enum(value)) {}
75 explicit enum_object(uint32 value) : value(to_enum(value)) {}
76 explicit enum_object(uint64 value) : value(to_enum(value)) {}
77 enum_object(enum_object&&) noexcept = default;
78 enum_object(const enum_object&) noexcept = default;
79 enum_object& operator =(const enum_object&) noexcept = default;
80 operator enum_type() const noexcept {return value;}
82
84
90 bool has_flag(enum_type flag) const noexcept {return (to_int(value) & to_int(flag)) == to_int(flag);}
91
96
98
110 int32 compare_to(const enum_object& value) const noexcept override {
111 if (to_int(this->value) == to_int(value.value)) return 0;
112 if (to_int(this->value) < to_int(value.value)) return -1;
113 return 1;
114 }
115
119 bool equals(const object& obj) const noexcept override {return dynamic_cast<const enum_object*>(&obj) && equals(static_cast<const enum_object&>(obj));}
123 bool equals(const enum_object& value) const noexcept override {return this->value == value.value;}
127 bool equals(enum_type value) const noexcept {return this->value == value;}
131 template<class attribute_t>
132 bool equals(attribute_t value) const noexcept {return false;}
133
136 xtd::size get_hash_code() const noexcept override {return hash_code::combine(value);}
137
140 xtd::byte to_byte() const noexcept {return static_cast<xtd::byte>(value);}
141
144 int16 to_int16() const noexcept {return static_cast<int16>(value);}
145
148 int32 to_int32() const noexcept {return static_cast<int32>(value);}
149
152 int64 to_int64() const noexcept {return static_cast<int64>(value);}
153
156 sbyte to_sbyte() const noexcept {return static_cast<sbyte>(value);}
157
160 uint16 to_uint16() const noexcept {return static_cast<uint16>(value);}
161
164 uint32 to_uint32() const noexcept {return static_cast<uint32>(value);}
165
168 uint64 to_uint64() const noexcept {return static_cast<uint64>(value);}
169
172 xtd::string to_string() const noexcept override {
173 init();
174 if (attribute() == xtd::enum_attribute::flags) return to_string_flags();
175
176 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
177 if (iterator == entries().end()) return string::format("{}", to_int(value));
178
179 return iterator->second;
180 }
181
198 xtd::string to_string(const xtd::string& format) const {return to_string(format, std::locale {});}
199
217 xtd::string to_string(const xtd::string& format, const std::locale& loc) const override;
219
221
227 static enum_type parse(const xtd::string& str) {return parse(str, false);}
232 static enum_type parse(const xtd::string& str, bool ignore_case) {
233 enum_object<enum_type>().init();
234 if (enum_object<enum_type>().attribute() == xtd::enum_attribute::flags) return parse_flags(str, ignore_case);
235
236 for (auto item : enum_object<enum_type>().entries()) {
237 if (xtd::string::compare(str, item.second, ignore_case) == 0)
238 return static_cast<enum_type>(item.first);
239 }
240
241 return to_enum(xtd::parse<int64>(str));
242 }
244
245 private:
246 friend struct enum_object<std::nullptr_t>;
247
248 xtd::string get_name() const noexcept {
249 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
250 if (iterator == entries().end()) return xtd::string::format("{}", to_int(value));
251 return iterator->second;
252 }
253
254 static enum_type parse_flags(const xtd::string& value, bool ignore_case) {
255 std::vector<xtd::string> values = value.split(',');
256 for (xtd::string& str : values)
257 str = str.trim(' ');
258
259 if (values.size() == 1) {
260 for (auto item : enum_object<enum_type>().entries()) {
261 if (xtd::string::compare(value, item.second, ignore_case) == 0)
262 return to_enum(item.first);
263 }
264 return to_enum(xtd::parse<int64>(value));
265 }
266
267 int64 result = 0;
268 for (xtd::string str : values) {
269 bool found = false;
270 for (auto item : enum_object<enum_type>().entries()) {
271 if (xtd::string::compare(str, item.second, ignore_case) == 0) {
272 found = true;
273 result |= to_int(item.first);
274 break;
275 }
276 }
277 if (found == false)
279 }
280
281 return to_enum(result);
282 }
283
284 xtd::string to_string_flags() const noexcept {
285 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
286 if (to_int(value) == 0 && iterator == entries().end()) return "0";
287
288 iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == to_enum(0);});
289 if (to_int(value) == 0) return iterator == entries().end() ? "0" : iterator->second;
290
291 xtd::string str;
292 int64 rest = to_int(value);
293 enum_collection<enum_type> reversed_entries = entries();
294 std::reverse(reversed_entries.begin(), reversed_entries.end());
295
296 for (auto item : reversed_entries) {
297 if (to_int(item.first) != 0 && (rest & to_int(item.first)) == to_int(item.first)) {
298 rest -= to_int(item.first);
299 if (!xtd::string::is_empty(str)) str = ", " + str;
300 str = item.second + str;
301 }
302 }
303
304 if (str.empty() || rest > 0) return xtd::string::format("{}", to_int(value));
305
306 return str;
307 }
308
309 template<class attribute_t>
310 static enum_type to_enum(attribute_t value) noexcept {return static_cast<enum_type>(value);}
311 static int64 to_int(enum_type value) noexcept {return static_cast<int64>(value);}
312
313 static xtd::enum_attribute attribute() noexcept {
314 if (attribute_.has_value()) return attribute_.value();
315 attribute_ = xtd::enum_attribute(enum_set_attribute<enum_type>());
316 return attribute_.value();
317 }
318
319 static enum_collection<enum_type>& entries() noexcept {
320 if (entries_.has_value()) return entries_.value();
321 entries_ = enum_collection<enum_type>(enum_register<enum_type>());
322 return entries_.value();
323 };
324
325 static void init() noexcept {
326 attribute();
327 entries();
328 }
329
330 inline static std::optional<xtd::enum_attribute> attribute_;
331 inline static std::optional<enum_collection<enum_type>> entries_;
332 };
333
344 template<>
345 struct enum_object<std::nullptr_t> static_ {
347
351 template<class enum_t>
352 static const xtd::enum_collection<enum_t>& get_entries() noexcept {
353 return enum_object<enum_t>().entries();
354 }
355
358 template<class enum_t>
361 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);});
362 return entries;
363 }
364
367 template<class enum_t>
370 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);});
371 return entries;
372 }
373
376 template<class enum_t>
379 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);});
380 return entries;
381 }
382
385 template<class enum_t>
388 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);});
389 return entries;
390 }
391
394 template<class enum_t>
397 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);});
398 return entries;
399 }
400
403 template<class enum_t>
406 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);});
407 return entries;
408 }
409
412 template<class enum_t>
415 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);});
416 return entries;
417 }
418
421 template<class enum_t>
424 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);});
425 return entries;
426 }
427
432 template<class enum_t>
433 static xtd::string get_name(enum_t value) noexcept {return enum_object<enum_t>(value).to_string();}
438 template<class enum_t>
444 template<class enum_t>
450 template<class enum_t>
452
456 template<class enum_t>
457 static std::vector<xtd::string> get_names() noexcept {
458 std::vector<xtd::string> names;
459 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {names.push_back(entry.second);});
460 return names;
461 }
462
466 template<class enum_t>
467 static std::vector<enum_t> get_values() noexcept {
468 std::vector<enum_t> values;
469 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(entry.first);});
470 return values;
471 }
472
476 template<class enum_t>
477 static std::vector<xtd::byte> get_values_as_byte() noexcept {
478 std::vector<xtd::byte> values;
479 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(enum_object<enum_t>(entry.first).to_byte());});
480 return values;
481 }
482
486 template<class enum_t>
487 static std::vector<int16> get_values_as_int16() noexcept {
488 std::vector<int16> values;
489 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(enum_object<enum_t>(entry.first).to_int16());});
490 return values;
491 }
492
496 template<class enum_t>
497 static std::vector<int32> get_values_as_int32() noexcept {
498 std::vector<int32> values;
499 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(enum_object<enum_t>(entry.first).to_int32());});
500 return values;
501 }
502
506 template<class enum_t>
507 static std::vector<int64> get_values_as_int64() noexcept {
508 std::vector<int64> values;
509 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(enum_object<enum_t>(entry.first).to_int64());});
510 return values;
511 }
512
516 template<class enum_t>
517 static std::vector<sbyte> get_values_as_sbyte() noexcept {
518 std::vector<sbyte> values;
519 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(enum_object<enum_t>(entry.first).to_sbyte());});
520 return values;
521 }
522
526 template<class enum_t>
527 static std::vector<uint16> get_values_as_uint16() noexcept {
528 std::vector<uint16> values;
529 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(enum_object<enum_t>(entry.first).to_uint16());});
530 return values;
531 }
532
536 template<class enum_t>
537 static std::vector<uint32> get_values_as_uint32() noexcept {
538 std::vector<uint32> values;
539 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(enum_object<enum_t>(entry.first).to_uint32());});
540 return values;
541 }
542
546 template<class enum_t>
547 static std::vector<uint64> get_values_as_uint64() noexcept {
548 std::vector<uint64> values;
549 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(enum_object<enum_t>(entry.first).to_uint64());});
550 return values;
551 }
552
557 template<class enum_t>
558 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();}
563 template<class enum_t>
564 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();}
565
570 template<class enum_t>
571 static enum_t parse(const xtd::string& value) {return parse<enum_t>(value, false);}
577 template<class enum_t>
578 static enum_t parse(const xtd::string& str, bool ignore_case) {
579 return enum_object<enum_t>::parse(str, ignore_case);
580 }
581
585 template<class enum_t>
586 static xtd::byte to_byte(enum_t value) noexcept {return enum_object<enum_t>(value).to_byte();}
587
591 template<class enum_t>
592 static int16 to_int16(enum_t value) noexcept {return enum_object<enum_t>(value).to_int16();}
593
597 template<class enum_t>
598 static int32 to_int32(enum_t value) noexcept {return enum_object<enum_t>(value).to_int32();}
599
603 template<class enum_t>
604 static int64 to_int64(enum_t value) noexcept {return enum_object<enum_t>(value).to_int64();}
605
609 template<class enum_t>
610 static sbyte to_sbyte(enum_t value) noexcept {return enum_object<enum_t>(value).to_sbyte();}
611
615 template<class enum_t>
616 static xtd::string to_string(enum_t value) noexcept {return enum_object<enum_t>(value).to_string();}
617
621 template<class enum_t>
622 static uint16 to_uint16(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint16();}
623
627 template<class enum_t>
628 static uint32 to_uint32(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint32();}
629
633 template<class enum_t>
634 static uint64 to_uint64(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint64();}
635
640 template<class enum_t>
641 static bool try_parse(const xtd::string& value, enum_t& result) noexcept {return try_parse<enum_t>(value, false, result);}
642
648 template<class enum_t>
649 static bool try_parse(const xtd::string& value, bool ignore_case, enum_t& result) noexcept {
650 try {
651 result = parse<enum_t>(value, ignore_case);
652 return true;
653 } catch (...) {
654 return false;
655 }
656 }
658 };
660
662 template<class enum_t>
663 xtd::string enum_object<enum_t>::to_string(const xtd::string& format, const std::locale& loc) const {
664 init();
665 auto fmt = format;
666 if (fmt.empty()) fmt = "G";
667
668 switch (fmt[0]) {
669 case 'b':
670 case 'B':
671 case 'd':
672 case 'D':
673 case 'o':
674 case 'O':
675 case 'x':
676 case 'X': return __numeric_formatter(fmt.chars(), static_cast<long long int>(value), std::locale());
677 case 'f':
678 case 'F':
679 case 'g':
680 case 'G': return xtd::enum_object<>::get_name(value);
681 }
683 }
685}
686
688template<class enum_t>
689inline std::string __enum_to_string__(enum_t value) noexcept {
690 return xtd::enum_object<>::get_name(value);
691}
692
693template<class value_t>
694value_t __parse_enum(const std::string& str) {
696}
Represents the base class for custom attributes.
Definition attribute.hpp:25
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:44
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< std::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:22
@ 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 std::vector< int64 > get_values_as_int64() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:507
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:571
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:413
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:377
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.hpp:527
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.hpp:497
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:445
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:649
static xtd::string to_string(enum_t value) noexcept
Converts this instance to string.
Definition enum_object.hpp:616
static int16 to_int16(enum_t value) noexcept
Converts this instance to int16.
Definition enum_object.hpp:592
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:439
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:386
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.hpp:487
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.hpp:517
static std::vector< xtd::string > get_names() noexcept
Retrieves an array of the names of the constants in a specified enumeration.
Definition enum_object.hpp:457
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:641
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.hpp:537
static std::vector< enum_t > get_values() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:467
static sbyte to_sbyte(enum_t value) noexcept
Converts this instance to signed byte.
Definition enum_object.hpp:610
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:451
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:352
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:558
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.hpp:547
static xtd::byte to_byte(enum_t value) noexcept
Converts this instance to byte.
Definition enum_object.hpp:586
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:404
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:359
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:564
static int32 to_int32(enum_t value) noexcept
Converts this instance to int32.
Definition enum_object.hpp:598
static uint32 to_uint32(enum_t value) noexcept
Converts this instance to unsigned int32.
Definition enum_object.hpp:628
static int64 to_int64(enum_t value) noexcept
Converts this instance to int64.
Definition enum_object.hpp:604
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:578
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.hpp:477
static uint16 to_uint16(enum_t value) noexcept
Converts this instance to unsigned int16.
Definition enum_object.hpp:622
static uint64 to_uint64(enum_t value) noexcept
Converts this instance to unsigned int64.
Definition enum_object.hpp:634
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:395
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:433
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:422
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:368
Provides the base class for enumerations.
Definition enum_object.hpp:48
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:90
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition enum_object.hpp:119
int64 to_int64() const noexcept
Converts this instance to int64.
Definition enum_object.hpp:152
uint32 to_uint32() const noexcept
Converts this instance to unsigned int32.
Definition enum_object.hpp:164
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:198
uint16 to_uint16() const noexcept
Converts this instance to unsigned int16.
Definition enum_object.hpp:160
sbyte to_sbyte() const noexcept
Converts this instance to signed byte.
Definition enum_object.hpp:156
enum_t value_type
Represents the enumeration type.
Definition enum_object.hpp:55
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
Definition enum_object.hpp:136
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition enum_object.hpp:172
bool equals(const enum_object &value) const noexcept override
Determines whether the specified object is equal to the current object.
Definition enum_object.hpp:123
static enum_type parse(const xtd::string &str)
Converts the string to its enum_type equivalent.
Definition enum_object.hpp:227
enum_t enum_type
Represents the enumeration type.
Definition enum_object.hpp:53
xtd::byte to_byte() const noexcept
Converts this instance to byte.
Definition enum_object.hpp:140
uint64 to_uint64() const noexcept
Converts this instance to unsigned int64.
Definition enum_object.hpp:168
bool equals(attribute_t value) const noexcept
Indicates whether the current object is equal to another object with defferent type.
Definition enum_object.hpp:132
int32 to_int32() const noexcept
Converts this instance to int32.
Definition enum_object.hpp:148
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:127
enum_type value
Gets or sets the value of the enum.
Definition enum_object.hpp:94
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:232
int16 to_int16() const noexcept
Converts this instance to int16.
Definition enum_object.hpp:144
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:110
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...