xtd 1.0.0
Loading...
Searching...
No Matches
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 "icomparable.hpp"
11#include "iequatable.hpp"
12#include "iformatable.hpp"
13#include "number_styles.hpp"
14#include "optional.hpp"
15#include "static.hpp"
16#include "string_comparison.hpp"
18
20namespace xtd {
22
46 template<typename enum_t = std::nullptr_t>
47 struct enum_object : xtd::object, xtd::icomparable<enum_object<enum_t>>, xtd::iequatable<enum_object<enum_t >>, xtd::iformatable {
49
52 using enum_type = enum_t;
54 using value_type = enum_t;
56
58
61 enum_object() noexcept = default;
66
68 explicit enum_object(xtd::byte value) : value(to_enum(value)) {}
69 explicit enum_object(sbyte value) : value(to_enum(value)) {}
70 explicit enum_object(int16 value) : value(to_enum(value)) {}
71 explicit enum_object(int32 value) : value(to_enum(value)) {}
72 explicit enum_object(int64 value) : value(to_enum(value)) {}
73 explicit enum_object(uint16 value) : value(to_enum(value)) {}
74 explicit enum_object(uint32 value) : value(to_enum(value)) {}
75 explicit enum_object(uint64 value) : value(to_enum(value)) {}
76 enum_object(enum_object&&) noexcept = default;
77 enum_object(const enum_object&) noexcept = default;
78 enum_object& operator =(const enum_object&) noexcept = default;
79 operator enum_type() const noexcept {return value;}
81
83
89 [[nodiscard]] auto has_flag(enum_type flag) const noexcept -> bool {return (to_int(value) & to_int(flag)) == to_int(flag);}
90
95
97
109 [[nodiscard]] auto compare_to(const enum_object& value) const noexcept -> xtd::int32 override {
110 if (to_int(this->value) == to_int(value.value)) return 0;
111 if (to_int(this->value) < to_int(value.value)) return -1;
112 return 1;
113 }
114
118 [[nodiscard]] auto equals(const object& obj) const noexcept -> bool override {return dynamic_cast<const enum_object*>(&obj) && equals(static_cast<const enum_object&>(obj));}
122 [[nodiscard]] auto equals(const enum_object& value) const noexcept -> bool override {return this->value == value.value;}
126 [[nodiscard]] auto equals(enum_type value) const noexcept -> bool {return this->value == value;}
130 template<typename attribute_t>
131 [[nodiscard]] auto equals(attribute_t value) const noexcept -> bool {return false;}
132
135 [[nodiscard]] auto get_hash_code() const noexcept -> xtd::usize override {return hash_code::combine(value);}
136
139 [[nodiscard]] auto to_byte() const noexcept -> xtd::byte {return static_cast<xtd::byte>(value);}
140
143 [[nodiscard]] auto to_int16() const noexcept -> xtd::int16 {return static_cast<int16>(value);}
144
147 [[nodiscard]] auto to_int32() const noexcept -> xtd::int32 {return static_cast<int32>(value);}
148
151 [[nodiscard]] auto to_int64() const noexcept -> xtd::int64 {return static_cast<int64>(value);}
152
155 [[nodiscard]] auto to_sbyte() const noexcept -> xtd::sbyte {return static_cast<sbyte>(value);}
156
159 [[nodiscard]] auto to_uint16() const noexcept -> xtd::uint16 {return static_cast<uint16>(value);}
160
163 [[nodiscard]] auto to_uint32() const noexcept -> xtd::uint32 {return static_cast<uint32>(value);}
164
167 [[nodiscard]] auto to_uint64() const noexcept -> xtd::uint64 {return static_cast<uint64>(value);}
168
171 [[nodiscard]] auto to_string() const noexcept -> xtd::string override {
172 init();
173 if (attribute() == xtd::enum_attribute::flags) return to_string_flags();
174 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
175 if (iterator == entries().end()) return string::format("{}", to_int(value));
176 return iterator->second;
177 }
178
195 [[nodiscard]] auto to_string(const xtd::string& format) const -> xtd::string {return to_string(format, std::locale {});}
196
214 [[nodiscard]] auto to_string(const xtd::string& format, const globalization::culture_info& culture) const -> xtd::string override;
216
218
224 [[nodiscard]] static auto parse(const xtd::string& str) -> enum_type {return parse(str, false);}
229 [[nodiscard]] static auto parse(const xtd::string& str, bool ignore_case) -> enum_type {
230 enum_object<enum_type>().init();
231 if (enum_object<enum_type>().attribute() == xtd::enum_attribute::flags) return parse_flags(str, ignore_case);
232 for (auto item : enum_object<enum_type>().entries())
233 if (xtd::string::compare(str, item.second, ignore_case) == 0) return static_cast<enum_type>(item.first);
234 return to_enum(xtd::parse<int64>(str));
235 }
237
238
240 friend auto operator << (std::ostream& os, const enum_object& value) -> std::ostream& {return os << value.to_string();}
242
243 private:
244 friend struct enum_object<std::nullptr_t>;
245
246 [[nodiscard]] auto get_name() const noexcept -> xtd::string {
247 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
248 if (iterator == entries().end()) return xtd::string::format("{}", to_int(value));
249 return iterator->second;
250 }
251
252 [[nodiscard]] static auto parse_flags(const xtd::string& value, bool ignore_case) -> enum_type {
253 auto values = value.split(',');
254 for (auto& str : values)
255 str = str.trim(' ');
256
257 if (values.length() == 1) {
258 for (auto item : enum_object<enum_type>().entries())
259 if (xtd::string::compare(value, item.second, ignore_case) == 0) return to_enum(item.first);
260 return to_enum(xtd::parse<int64>(value));
261 }
262
263 auto result = xtd::int64 {0};
264 for (const auto& str : values) {
265 auto found = false;
266 for (auto item : enum_object<enum_type>().entries()) {
267 if (xtd::string::compare(str, item.second, ignore_case) == 0) {
268 found = true;
269 result |= to_int(item.first);
270 break;
271 }
272 }
274 }
275 return to_enum(result);
276 }
277
278 [[nodiscard]] auto to_string_flags() const noexcept -> xtd::string {
279 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
280 if (to_int(value) == 0 && iterator == entries().end()) return "0";
281
282 iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == to_enum(0);});
283 if (to_int(value) == 0) return iterator == entries().end() ? "0" : iterator->second;
284
285 auto str = xtd::string::empty_string;
286 auto rest = to_int(value);
287 auto reversed_entries = entries();
288 std::reverse(reversed_entries.begin(), reversed_entries.end());
289
290 for (auto item : reversed_entries) {
291 if (to_int(item.first) != 0 && (rest & to_int(item.first)) == to_int(item.first)) {
292 rest -= to_int(item.first);
293 if (!xtd::string::is_empty(str)) str = ", " + str;
294 str = item.second + str;
295 }
296 }
297
298 if (xtd::string::is_empty(str) || rest > 0) return xtd::string::format("{}", to_int(value));
299 return str;
300 }
301
302 template<typename attribute_t>
303 static auto to_enum(attribute_t value) noexcept -> enum_type {return static_cast<enum_type>(value);}
304
305 [[nodiscard]] static auto to_int(enum_type value) noexcept -> xtd::int64 {return static_cast<int64>(value);}
306
307 [[nodiscard]] static auto attribute() noexcept -> xtd::enum_attribute {
308 if (attribute_.has_value()) return attribute_.value();
310 return attribute_.value();
311 }
312
313 [[nodiscard]] static auto entries() noexcept -> enum_collection<enum_type>& {
314 if (entries_.has_value()) return entries_.value();
316 return entries_.value();
317 };
318
319 static auto init() noexcept -> void {
320 [[maybe_unused]] auto a = attribute();
321 [[maybe_unused]] auto e = entries();
322 }
323
324 inline static std::optional<xtd::enum_attribute> attribute_;
325 inline static std::optional<enum_collection<enum_type>> entries_;
326 };
327
338 template<>
339 struct enum_object<std::nullptr_t> static_ {
341
344
347
351 template<class enum_t>
352 [[nodiscard]] static auto get_entries() noexcept -> const xtd::enum_collection<enum_t>& {
353 return enum_object<enum_t>().entries();
354 }
355
358 template<class enum_t>
359 [[nodiscard]] static auto get_entries_as_byte() noexcept -> xtd::enum_collection<xtd::byte> {
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>
368 [[nodiscard]] static auto get_entries_as_int16() noexcept -> xtd::enum_collection<xtd::int16> {
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>
377 [[nodiscard]] static auto get_entries_as_int32() noexcept -> xtd::enum_collection<xtd::int32> {
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>
386 [[nodiscard]] static auto get_entries_as_int64() noexcept -> xtd::enum_collection<xtd::int64> {
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>
395 [[nodiscard]] static auto get_entries_as_sbyte() noexcept -> xtd::enum_collection<xtd::sbyte> {
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>
404 [[nodiscard]] static auto get_entries_as_uint16() noexcept -> xtd::enum_collection<xtd::uint16> {
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>
413 [[nodiscard]] static auto get_entries_as_uint32() noexcept -> xtd::enum_collection<xtd::uint32> {
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>
422 [[nodiscard]] static auto get_entries_as_uint64() noexcept -> xtd::enum_collection<xtd::uint64> {
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 [[nodiscard]] static auto get_name(enum_t value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
438 template<class enum_t>
439 [[nodiscard]] static auto get_name(enum_object<enum_t> value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
444 template<class enum_t>
445 [[nodiscard]] static auto get_name(int32 value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
450 template<class enum_t>
451 [[nodiscard]] static auto get_name(int64 value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
452
456 template<class enum_t>
457 [[nodiscard]] static auto get_names() noexcept -> xtd::array<xtd::string> {
458 auto names = xtd::array<xtd::string> {};
459 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {names.resize(names.length() + 1, entry.second);});
460 return names;
461 }
462
466 template<class enum_t>
467 [[nodiscard]] static auto get_values() noexcept -> xtd::array<enum_t> {
468 auto values = xtd::array<enum_t> {};
469 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, entry.first);});
470 return values;
471 }
472
476 template<class enum_t>
477 [[nodiscard]] static auto get_values_as_byte() noexcept -> xtd::array<xtd::byte> {
478 auto values = xtd::array<xtd::byte> {};
479 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, enum_object<enum_t>(entry.first).to_byte());});
480 return values;
481 }
482
486 template<class enum_t>
487 [[nodiscard]] static auto get_values_as_int16() noexcept -> xtd::array<xtd::int16> {
488 auto values = xtd::array<xtd::int16> {};
489 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, enum_object<enum_t>(entry.first).to_int16());});
490 return values;
491 }
492
496 template<class enum_t>
497 [[nodiscard]] static auto get_values_as_int32() noexcept -> xtd::array<xtd::int32> {
498 auto values = xtd::array<xtd::int32> {};
499 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, enum_object<enum_t>(entry.first).to_int32());});
500 return values;
501 }
502
506 template<class enum_t>
507 [[nodiscard]] static auto get_values_as_int64() noexcept -> xtd::array<xtd::int64> {
508 auto values = xtd::array<xtd::int64> {};
509 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, enum_object<enum_t>(entry.first).to_int64());});
510 return values;
511 }
512
516 template<class enum_t>
517 [[nodiscard]] static auto get_values_as_sbyte() noexcept -> xtd::array<xtd::sbyte> {
518 auto values = xtd::array<xtd::sbyte> {};
519 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, enum_object<enum_t>(entry.first).to_sbyte());});
520 return values;
521 }
522
526 template<class enum_t>
527 [[nodiscard]] static auto get_values_as_uint16() noexcept -> xtd::array<xtd::uint16> {
528 auto values = xtd::array<xtd::uint16> {};
529 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, enum_object<enum_t>(entry.first).to_uint16());});
530 return values;
531 }
532
536 template<class enum_t>
537 [[nodiscard]] static auto get_values_as_uint32() noexcept -> xtd::array<xtd::uint32> {
538 auto values = xtd::array<xtd::uint32> {};
539 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, enum_object<enum_t>(entry.first).to_uint32());});
540 return values;
541 }
542
546 template<class enum_t>
547 [[nodiscard]] static auto get_values_as_uint64() noexcept -> xtd::array<xtd::uint64> {
548 auto values = xtd::array<xtd::uint64> {};
549 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, enum_object<enum_t>(entry.first).to_uint64());});
550 return values;
551 }
552
557 template<class enum_t>
558 [[nodiscard]] static auto is_defined(enum_t value) noexcept -> bool {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 [[nodiscard]] static auto is_defined(enum_object<enum_t>value) noexcept -> bool {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 [[nodiscard]] static auto parse(const xtd::string & value) -> enum_t {return parse<enum_t>(value, false);}
577 template<class enum_t>
578 [[nodiscard]] static auto parse(const xtd::string & str, bool ignore_case) -> enum_t {
579 return enum_object<enum_t>::parse(str, ignore_case);
580 }
581
585 template<class enum_t>
586 [[nodiscard]] static auto to_byte(enum_t value) noexcept -> xtd::byte {return enum_object<enum_t>(value).to_byte();}
587
591 template<class enum_t>
592 [[nodiscard]] static auto to_int16(enum_t value) noexcept -> xtd::int16 {return enum_object<enum_t>(value).to_int16();}
593
597 template<class enum_t>
598 [[nodiscard]] static auto to_int32(enum_t value) noexcept -> xtd::int32 {return enum_object<enum_t>(value).to_int32();}
599
603 template<class enum_t>
604 [[nodiscard]] static auto to_int64(enum_t value) noexcept -> xtd::int64 {return enum_object<enum_t>(value).to_int64();}
605
609 template<class enum_t>
610 [[nodiscard]] static auto to_sbyte(enum_t value) noexcept -> xtd::sbyte {return enum_object<enum_t>(value).to_sbyte();}
611
615 template<class enum_t>
616 [[nodiscard]] static auto to_string(enum_t value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
617
621 template<class enum_t>
622 [[nodiscard]] static auto to_uint16(enum_t value) noexcept -> xtd::uint16 {return enum_object<enum_t>(value).to_uint16();}
623
627 template<class enum_t>
628 [[nodiscard]] static auto to_uint32(enum_t value) noexcept -> xtd::uint32 {return enum_object<enum_t>(value).to_uint32();}
629
633 template<class enum_t>
634 [[nodiscard]] static auto to_uint64(enum_t value) noexcept -> xtd::uint64 {return enum_object<enum_t>(value).to_uint64();}
635
640 template<class enum_t>
641 [[nodiscard]] static auto try_parse(const xtd::string & value, enum_t& result) noexcept -> bool {return try_parse<enum_t>(value, false, result);}
642
648 template<class enum_t>
649 [[nodiscard]] static auto try_parse(const xtd::string & value, bool ignore_case, enum_t& result) noexcept -> bool {
650 try {
651 result = parse<enum_t>(value, ignore_case);
652 return true;
653 } catch (...) {
654 return false;
655 }
656 }
657
658 };
659
660}
661
663template<class enum_t>
664[[nodiscard]] inline auto __enum_to_string__(enum_t value) noexcept -> std::string {
665 return xtd::enum_object<>::get_name(value);
666}
667
668template<class value_t>
669[[nodiscard]] inline auto __parse_enum(const std::string& str) -> value_t {
671}
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Represents the base class for custom attributes.
Definition attribute.hpp:25
static const basic_string empty_string
Definition basic_string.hpp:111
static auto compare(const basic_string &str_a, const basic_string &str_b) noexcept -> xtd::int32
Definition basic_string.hpp:1021
static auto is_empty(const xtd::basic_string< value_type, traits_type, allocator_type > &string) noexcept -> bool
Definition basic_string.hpp:1249
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition culture_info.hpp:42
static auto combine(args_t... values) noexcept -> xtd::usize
Combines values into a hash code.
Definition hash_code.hpp:70
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
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:22
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:42
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Contains xtd::enum_attribute enum class.
Contains xtd::enum_collection.
Contains xtd::enum_register.
Contains xtd::enum_set_attribute strcut.
static auto format(const basic_string< char > &fmt, args_t &&... args) -> basic_string
auto format(const xtd::string &fmt, args_t &&... args) -> xtd::string
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:21
@ format
The format is not valid.
Definition exception_case.hpp:51
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:38
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
std::uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
std::int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
std::uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
std::int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
std::uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
std::uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.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:24
auto try_parse(const std::basic_string< char > &str, value_t &value) noexcept -> bool
Convert a string into a type.
Definition parse.hpp:416
auto parse(const std::string &str) -> value_t
Convert a string into a type.
Definition parse.hpp:34
@ flags
Enum flags attribute.
Definition enum_attribute.hpp:26
@ a
The A key.
Definition console_key.hpp:88
@ e
The E key.
Definition console_key.hpp:96
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
Contains xtd::iformatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > iterator
Represents the iterator of read_only_span value type.
Definition read_only_span.hpp:71
auto begin() const -> const_iterator
Returns an iterator to the beginning.
Definition read_only_span.hpp:186
auto end() const -> const_iterator
Returns an iterator to the end.
Definition read_only_span.hpp:205
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 auto get_name(enum_t value) noexcept -> xtd::string
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition enum_object.hpp:433
static auto parse(const xtd::string &value) -> enum_t
Converts the xtd::string representation of the name or numeric value of one or more enumerated consta...
Definition enum_object.hpp:571
static auto get_values_as_int16() noexcept -> xtd::array< xtd::int16 >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:487
static auto parse(const xtd::string &str, bool ignore_case) -> enum_t
Converts the xtd::string representation of the name or numeric value of one or more enumerated consta...
Definition enum_object.hpp:578
static auto to_int16(enum_t value) noexcept -> xtd::int16
Converts this instance to int16.
Definition enum_object.hpp:592
static auto try_parse(const xtd::string &value, enum_t &result) noexcept -> bool
Converts the xtd::string representation of the name or numeric value of one or more enumerated consta...
Definition enum_object.hpp:641
static auto get_name(enum_object< enum_t > value) noexcept -> xtd::string
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition enum_object.hpp:439
static auto get_entries_as_uint16() noexcept -> xtd::enum_collection< xtd::uint16 >
Retrieves an array of the xtd::enum_collection<uint16> of the constants in a specified enumeration.
Definition enum_object.hpp:404
static auto get_entries_as_uint64() noexcept -> xtd::enum_collection< xtd::uint64 >
Retrieves an array of the xtd::enum_collection<uint64> of the constants in a specified enumeration.
Definition enum_object.hpp:422
static auto get_name(int64 value) noexcept -> xtd::string
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition enum_object.hpp:451
static auto get_values_as_byte() noexcept -> xtd::array< xtd::byte >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:477
static auto get_entries_as_int16() noexcept -> xtd::enum_collection< xtd::int16 >
Retrieves an array of the xtd::enum_collection<int16> of the constants in a specified enumeration.
Definition enum_object.hpp:368
static auto get_values_as_int64() noexcept -> xtd::array< xtd::int64 >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:507
static auto get_values() noexcept -> xtd::array< enum_t >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:467
static auto get_values_as_int32() noexcept -> xtd::array< xtd::int32 >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:497
static auto is_defined(enum_object< enum_t >value) noexcept -> bool
Returns an indication whether a constant with a specified value exists in a specified enumeration.
Definition enum_object.hpp:564
static auto get_entries_as_int64() noexcept -> xtd::enum_collection< xtd::int64 >
Retrieves an array of the xtd::enum_collection<int64> of the constants in a specified enumeration.
Definition enum_object.hpp:386
static auto get_entries_as_sbyte() noexcept -> xtd::enum_collection< xtd::sbyte >
Retrieves an array of the xtd::enum_collection<sbyte> of the constants in a specified enumeration.
Definition enum_object.hpp:395
static auto get_values_as_uint32() noexcept -> xtd::array< xtd::uint32 >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:537
static auto try_parse(const xtd::string &value, bool ignore_case, enum_t &result) noexcept -> bool
Converts the xtd::string representation of the name or numeric value of one or more enumerated consta...
Definition enum_object.hpp:649
static auto get_entries_as_int32() noexcept -> xtd::enum_collection< xtd::int32 >
Retrieves an array of the xtd::enum_collection<int32> of the constants in a specified enumeration.
Definition enum_object.hpp:377
static auto get_name(int32 value) noexcept -> xtd::string
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition enum_object.hpp:445
static auto get_entries() noexcept -> const xtd::enum_collection< enum_t > &
Retrieves an array of the xtd::enum_collection<enum_t> of the constants in a specified enumeration.
Definition enum_object.hpp:352
static auto get_values_as_uint64() noexcept -> xtd::array< xtd::uint64 >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:547
static auto to_uint32(enum_t value) noexcept -> xtd::uint32
Converts this instance to unsigned int32.
Definition enum_object.hpp:628
static auto get_names() noexcept -> xtd::array< xtd::string >
Retrieves an array of the names of the constants in a specified enumeration.
Definition enum_object.hpp:457
static auto to_string(enum_t value) noexcept -> xtd::string
Converts this instance to string.
Definition enum_object.hpp:616
static auto to_uint16(enum_t value) noexcept -> xtd::uint16
Converts this instance to unsigned int16.
Definition enum_object.hpp:622
static auto get_entries_as_byte() noexcept -> xtd::enum_collection< xtd::byte >
Retrieves an array of the xtd::enum_collection<xtd::byte> of the constants in a specified enumeration...
Definition enum_object.hpp:359
static auto to_sbyte(enum_t value) noexcept -> xtd::sbyte
Converts this instance to signed byte.
Definition enum_object.hpp:610
static auto get_entries_as_uint32() noexcept -> xtd::enum_collection< xtd::uint32 >
Retrieves an array of the xtd::enum_collection<uint32> of the constants in a specified enumeration.
Definition enum_object.hpp:413
static auto to_int32(enum_t value) noexcept -> xtd::int32
Converts this instance to int32.
Definition enum_object.hpp:598
static auto is_defined(enum_t value) noexcept -> bool
Returns an indication whether a constant with a specified value exists in a specified enumeration.
Definition enum_object.hpp:558
static auto get_values_as_uint16() noexcept -> xtd::array< xtd::uint16 >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:527
static auto get_values_as_sbyte() noexcept -> xtd::array< xtd::sbyte >
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:517
static auto to_byte(enum_t value) noexcept -> xtd::byte
Converts this instance to byte.
Definition enum_object.hpp:586
static auto to_uint64(enum_t value) noexcept -> xtd::uint64
Converts this instance to unsigned int64.
Definition enum_object.hpp:634
static auto to_int64(enum_t value) noexcept -> xtd::int64
Converts this instance to int64.
Definition enum_object.hpp:604
Provides the base class for enumerations.
Definition enum_object.hpp:47
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
Definition enum_object.hpp:118
auto to_int16() const noexcept -> xtd::int16
Converts this instance to int16.
Definition enum_object.hpp:143
auto to_sbyte() const noexcept -> xtd::sbyte
Converts this instance to signed byte.
Definition enum_object.hpp:155
auto to_byte() const noexcept -> xtd::byte
Converts this instance to byte.
Definition enum_object.hpp:139
auto equals(attribute_t value) const noexcept -> bool
Indicates whether the current object is equal to another object with defferent type.
Definition enum_object.hpp:131
auto equals(enum_type value) const noexcept -> bool
Indicates whether the current object is equal to another object of the same type.
Definition enum_object.hpp:126
auto to_uint16() const noexcept -> xtd::uint16
Converts this instance to unsigned int16.
Definition enum_object.hpp:159
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
Definition enum_object.hpp:135
auto to_int32() const noexcept -> xtd::int32
Converts this instance to int32.
Definition enum_object.hpp:147
auto to_uint64() const noexcept -> xtd::uint64
Converts this instance to unsigned int64.
Definition enum_object.hpp:167
enum_t value_type
Represents the enumeration type.
Definition enum_object.hpp:54
auto to_string(const xtd::string &format) const -> xtd::string
Converts the value of this instance to its equivalent string representation using the specified forma...
Definition enum_object.hpp:195
auto to_int64() const noexcept -> xtd::int64
Converts this instance to int64.
Definition enum_object.hpp:151
auto to_uint32() const noexcept -> xtd::uint32
Converts this instance to unsigned int32.
Definition enum_object.hpp:163
auto to_string(const xtd::string &format, const globalization::culture_info &culture) const -> xtd::string override
Converts the value of this instance to its equivalent string representation using the specified forma...
auto has_flag(enum_type flag) const noexcept -> bool
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:89
enum_t enum_type
Represents the enumeration type.
Definition enum_object.hpp:52
auto compare_to(const enum_object &value) const noexcept -> xtd::int32 override
Compares the current instance with another object of the same type.
Definition enum_object.hpp:109
auto equals(const enum_object &value) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
Definition enum_object.hpp:122
static auto parse(const xtd::string &str) -> enum_type
Converts the string to its enum_type equivalent.
Definition enum_object.hpp:224
enum_object() noexcept=default
Initializes a new instance of the xtd::enum_object class.
enum_type value
Gets or sets the value of the enum.
Definition enum_object.hpp:93
auto to_string() const noexcept -> xtd::string override
Returns a xtd::string that represents the current object.
Definition enum_object.hpp:171
static auto values() noexcept
Definition enum_register.hpp:55
static auto attribute() noexcept
Definition enum_set_attribute.hpp:55