xtd 0.2.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 "format_exception.hpp"
11#include "icomparable.hpp"
12#include "iequatable.hpp"
13#include "iformatable.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<typename 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 [[nodiscard]] auto has_flag(enum_type flag) const noexcept -> bool {return (to_int(value) & to_int(flag)) == to_int(flag);}
91
96
98
110 [[nodiscard]] auto compare_to(const enum_object& value) const noexcept -> xtd::int32 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 [[nodiscard]] auto equals(const object& obj) const noexcept -> bool override {return dynamic_cast<const enum_object*>(&obj) && equals(static_cast<const enum_object&>(obj));}
123 [[nodiscard]] auto equals(const enum_object& value) const noexcept -> bool override {return this->value == value.value;}
127 [[nodiscard]] auto equals(enum_type value) const noexcept -> bool {return this->value == value;}
131 template<typename attribute_t>
132 [[nodiscard]] auto equals(attribute_t value) const noexcept -> bool {return false;}
133
136 [[nodiscard]] auto get_hash_code() const noexcept -> xtd::usize override {return hash_code::combine(value);}
137
140 [[nodiscard]] auto to_byte() const noexcept -> xtd::byte {return static_cast<xtd::byte>(value);}
141
144 [[nodiscard]] auto to_int16() const noexcept -> xtd::int16 {return static_cast<int16>(value);}
145
148 [[nodiscard]] auto to_int32() const noexcept -> xtd::int32 {return static_cast<int32>(value);}
149
152 [[nodiscard]] auto to_int64() const noexcept -> xtd::int64 {return static_cast<int64>(value);}
153
156 [[nodiscard]] auto to_sbyte() const noexcept -> xtd::sbyte {return static_cast<sbyte>(value);}
157
160 [[nodiscard]] auto to_uint16() const noexcept -> xtd::uint16 {return static_cast<uint16>(value);}
161
164 [[nodiscard]] auto to_uint32() const noexcept -> xtd::uint32 {return static_cast<uint32>(value);}
165
168 [[nodiscard]] auto to_uint64() const noexcept -> xtd::uint64 {return static_cast<uint64>(value);}
169
172 [[nodiscard]] auto to_string() const noexcept -> xtd::string override {
173 init();
174 if (attribute() == xtd::enum_attribute::flags) return to_string_flags();
175 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
176 if (iterator == entries().end()) return string::format("{}", to_int(value));
177 return iterator->second;
178 }
179
196 [[nodiscard]] auto to_string(const xtd::string& format) const -> xtd::string {return to_string(format, std::locale {});}
197
215 [[nodiscard]] auto to_string(const xtd::string& format, const globalization::culture_info& culture) const -> xtd::string override;
217
219
225 [[nodiscard]] static auto parse(const xtd::string& str) -> enum_type {return parse(str, false);}
230 [[nodiscard]] static auto parse(const xtd::string& str, bool ignore_case) -> enum_type {
231 enum_object<enum_type>().init();
232 if (enum_object<enum_type>().attribute() == xtd::enum_attribute::flags) return parse_flags(str, ignore_case);
233 for (auto item : enum_object<enum_type>().entries())
234 if (xtd::string::compare(str, item.second, ignore_case) == 0) return static_cast<enum_type>(item.first);
235 return to_enum(xtd::parse<int64>(str));
236 }
238
239
241 friend auto operator << (std::ostream& os, const enum_object& value) -> std::ostream& {return os << value.to_string();}
243
244 private:
245 friend struct enum_object<std::nullptr_t>;
246
247 [[nodiscard]] auto get_name() const noexcept -> xtd::string {
248 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
249 if (iterator == entries().end()) return xtd::string::format("{}", to_int(value));
250 return iterator->second;
251 }
252
253 [[nodiscard]] static auto parse_flags(const xtd::string& value, bool ignore_case) -> enum_type {
254 auto values = value.split(',');
255 for (auto& str : values)
256 str = str.trim(' ');
257
258 if (values.length() == 1) {
259 for (auto item : enum_object<enum_type>().entries())
260 if (xtd::string::compare(value, item.second, ignore_case) == 0) return to_enum(item.first);
261 return to_enum(xtd::parse<int64>(value));
262 }
263
264 auto result = xtd::int64 {0};
265 for (const auto& str : values) {
266 auto found = false;
267 for (auto item : enum_object<enum_type>().entries()) {
268 if (xtd::string::compare(str, item.second, ignore_case) == 0) {
269 found = true;
270 result |= to_int(item.first);
271 break;
272 }
273 }
275 }
276 return to_enum(result);
277 }
278
279 [[nodiscard]] auto to_string_flags() const noexcept -> xtd::string {
280 auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == this->value;});
281 if (to_int(value) == 0 && iterator == entries().end()) return "0";
282
283 iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == to_enum(0);});
284 if (to_int(value) == 0) return iterator == entries().end() ? "0" : iterator->second;
285
286 auto str = xtd::string::empty_string;
287 auto rest = to_int(value);
288 auto reversed_entries = entries();
289 std::reverse(reversed_entries.begin(), reversed_entries.end());
290
291 for (auto item : reversed_entries) {
292 if (to_int(item.first) != 0 && (rest & to_int(item.first)) == to_int(item.first)) {
293 rest -= to_int(item.first);
294 if (!xtd::string::is_empty(str)) str = ", " + str;
295 str = item.second + str;
296 }
297 }
298
299 if (xtd::string::is_empty(str) || rest > 0) return xtd::string::format("{}", to_int(value));
300 return str;
301 }
302
303 template<typename attribute_t>
304 static auto to_enum(attribute_t value) noexcept -> enum_type {return static_cast<enum_type>(value);}
305
306 [[nodiscard]] static auto to_int(enum_type value) noexcept -> xtd::int64 {return static_cast<int64>(value);}
307
308 [[nodiscard]] static auto attribute() noexcept -> xtd::enum_attribute {
309 if (attribute_.has_value()) return attribute_.value();
310 attribute_ = xtd::enum_attribute(enum_set_attribute<enum_type>());
311 return attribute_.value();
312 }
313
314 [[nodiscard]] static auto entries() noexcept -> enum_collection<enum_type>& {
315 if (entries_.has_value()) return entries_.value();
316 entries_ = enum_collection<enum_type>(enum_register<enum_type>());
317 return entries_.value();
318 };
319
320 static auto init() noexcept -> void {
321 [[maybe_unused]] auto a = attribute();
322 [[maybe_unused]] auto e = entries();
323 }
324
325 inline static std::optional<xtd::enum_attribute> attribute_;
326 inline static std::optional<enum_collection<enum_type>> entries_;
327 };
328
339 template<>
340 struct enum_object<std::nullptr_t> static_ {
342
345
348
352 template<class enum_t>
353 [[nodiscard]] static auto get_entries() noexcept -> const xtd::enum_collection<enum_t>& {
354 return enum_object<enum_t>().entries();
355 }
356
359 template<class enum_t>
360 [[nodiscard]] static auto get_entries_as_byte() noexcept -> xtd::enum_collection<xtd::byte> {
362 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);});
363 return entries;
364 }
365
368 template<class enum_t>
369 [[nodiscard]] static auto get_entries_as_int16() noexcept -> xtd::enum_collection<xtd::int16> {
371 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);});
372 return entries;
373 }
374
377 template<class enum_t>
378 [[nodiscard]] static auto get_entries_as_int32() noexcept -> xtd::enum_collection<xtd::int32> {
380 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);});
381 return entries;
382 }
383
386 template<class enum_t>
387 [[nodiscard]] static auto get_entries_as_int64() noexcept -> xtd::enum_collection<xtd::int64> {
389 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);});
390 return entries;
391 }
392
395 template<class enum_t>
396 [[nodiscard]] static auto get_entries_as_sbyte() noexcept -> xtd::enum_collection<xtd::sbyte> {
398 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);});
399 return entries;
400 }
401
404 template<class enum_t>
405 [[nodiscard]] static auto get_entries_as_uint16() noexcept -> xtd::enum_collection<xtd::uint16> {
407 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);});
408 return entries;
409 }
410
413 template<class enum_t>
414 [[nodiscard]] static auto get_entries_as_uint32() noexcept -> xtd::enum_collection<xtd::uint32> {
416 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);});
417 return entries;
418 }
419
422 template<class enum_t>
423 [[nodiscard]] static auto get_entries_as_uint64() noexcept -> xtd::enum_collection<xtd::uint64> {
425 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);});
426 return entries;
427 }
428
433 template<class enum_t>
434 [[nodiscard]] static auto get_name(enum_t value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
439 template<class enum_t>
440 [[nodiscard]] static auto get_name(enum_object<enum_t> value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
445 template<class enum_t>
446 [[nodiscard]] static auto get_name(int32 value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
451 template<class enum_t>
452 [[nodiscard]] static auto get_name(int64 value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
453
457 template<class enum_t>
458 [[nodiscard]] static auto get_names() noexcept -> xtd::array<xtd::string> {
459 auto names = xtd::array<xtd::string> {};
460 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {names.resize(names.length() + 1, entry.second);});
461 return names;
462 }
463
467 template<class enum_t>
468 [[nodiscard]] static auto get_values() noexcept -> xtd::array<enum_t> {
469 auto values = xtd::array<enum_t> {};
470 std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.resize(values.length() + 1, entry.first);});
471 return values;
472 }
473
477 template<class enum_t>
478 [[nodiscard]] static auto get_values_as_byte() noexcept -> xtd::array<xtd::byte> {
479 auto values = xtd::array<xtd::byte> {};
480 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());});
481 return values;
482 }
483
487 template<class enum_t>
488 [[nodiscard]] static auto get_values_as_int16() noexcept -> xtd::array<xtd::int16> {
489 auto values = xtd::array<xtd::int16> {};
490 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());});
491 return values;
492 }
493
497 template<class enum_t>
498 [[nodiscard]] static auto get_values_as_int32() noexcept -> xtd::array<xtd::int32> {
499 auto values = xtd::array<xtd::int32> {};
500 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());});
501 return values;
502 }
503
507 template<class enum_t>
508 [[nodiscard]] static auto get_values_as_int64() noexcept -> xtd::array<xtd::int64> {
509 auto values = xtd::array<xtd::int64> {};
510 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());});
511 return values;
512 }
513
517 template<class enum_t>
518 [[nodiscard]] static auto get_values_as_sbyte() noexcept -> xtd::array<xtd::sbyte> {
519 auto values = xtd::array<xtd::sbyte> {};
520 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());});
521 return values;
522 }
523
527 template<class enum_t>
528 [[nodiscard]] static auto get_values_as_uint16() noexcept -> xtd::array<xtd::uint16> {
529 auto values = xtd::array<xtd::uint16> {};
530 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());});
531 return values;
532 }
533
537 template<class enum_t>
538 [[nodiscard]] static auto get_values_as_uint32() noexcept -> xtd::array<xtd::uint32> {
539 auto values = xtd::array<xtd::uint32> {};
540 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());});
541 return values;
542 }
543
547 template<class enum_t>
548 [[nodiscard]] static auto get_values_as_uint64() noexcept -> xtd::array<xtd::uint64> {
549 auto values = xtd::array<xtd::uint64> {};
550 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());});
551 return values;
552 }
553
558 template<class enum_t>
559 [[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();}
564 template<class enum_t>
565 [[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();}
566
571 template<class enum_t>
572 [[nodiscard]] static auto parse(const xtd::string & value) -> enum_t {return parse<enum_t>(value, false);}
578 template<class enum_t>
579 [[nodiscard]] static auto parse(const xtd::string & str, bool ignore_case) -> enum_t {
580 return enum_object<enum_t>::parse(str, ignore_case);
581 }
582
586 template<class enum_t>
587 [[nodiscard]] static auto to_byte(enum_t value) noexcept -> xtd::byte {return enum_object<enum_t>(value).to_byte();}
588
592 template<class enum_t>
593 [[nodiscard]] static auto to_int16(enum_t value) noexcept -> xtd::int16 {return enum_object<enum_t>(value).to_int16();}
594
598 template<class enum_t>
599 [[nodiscard]] static auto to_int32(enum_t value) noexcept -> xtd::int32 {return enum_object<enum_t>(value).to_int32();}
600
604 template<class enum_t>
605 [[nodiscard]] static auto to_int64(enum_t value) noexcept -> xtd::int64 {return enum_object<enum_t>(value).to_int64();}
606
610 template<class enum_t>
611 [[nodiscard]] static auto to_sbyte(enum_t value) noexcept -> xtd::sbyte {return enum_object<enum_t>(value).to_sbyte();}
612
616 template<class enum_t>
617 [[nodiscard]] static auto to_string(enum_t value) noexcept -> xtd::string {return enum_object<enum_t>(value).to_string();}
618
622 template<class enum_t>
623 [[nodiscard]] static auto to_uint16(enum_t value) noexcept -> xtd::uint16 {return enum_object<enum_t>(value).to_uint16();}
624
628 template<class enum_t>
629 [[nodiscard]] static auto to_uint32(enum_t value) noexcept -> xtd::uint32 {return enum_object<enum_t>(value).to_uint32();}
630
634 template<class enum_t>
635 [[nodiscard]] static auto to_uint64(enum_t value) noexcept -> xtd::uint64 {return enum_object<enum_t>(value).to_uint64();}
636
641 template<class enum_t>
642 [[nodiscard]] static auto try_parse(const xtd::string & value, enum_t& result) noexcept -> bool {return try_parse<enum_t>(value, false, result);}
643
649 template<class enum_t>
650 [[nodiscard]] static auto try_parse(const xtd::string & value, bool ignore_case, enum_t& result) noexcept -> bool {
651 try {
652 result = parse<enum_t>(value, ignore_case);
653 return true;
654 } catch (...) {
655 return false;
656 }
657 }
658
659 };
660
661}
662
664template<class enum_t>
665[[nodiscard]] inline auto __enum_to_string__(enum_t value) noexcept -> std::string {
666 return xtd::enum_object<>::get_name(value);
667}
668
669template<class value_t>
670[[nodiscard]] inline auto __parse_enum(const std::string& str) -> value_t {
672}
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:1018
static auto is_empty(const xtd::basic_string< value_type, traits_type, allocator_type > &string) noexcept -> bool
Definition basic_string.hpp:1246
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition culture_info.hpp:43
static xtd::usize combine(args_t... values) noexcept
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.
Contains xtd::format_exception exception.
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:21
static auto format(const basic_string< char > &fmt, args_t &&... args) -> basic_string
@ 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
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.hpp:34
bool try_parse(const std::basic_string< char > &str, value_t &value) noexcept
Convert a string into a type.
Definition parse.hpp:416
@ 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:74
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
const_iterator end() const
Returns an iterator to the end.
Definition read_only_span.hpp:213
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:434
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:572
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:488
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:579
static auto to_int16(enum_t value) noexcept -> xtd::int16
Converts this instance to int16.
Definition enum_object.hpp:593
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:642
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:440
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:405
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:423
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:452
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:478
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:369
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:508
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:468
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:498
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:565
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:387
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:396
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:538
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:650
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:378
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:446
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:353
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:548
static auto to_uint32(enum_t value) noexcept -> xtd::uint32
Converts this instance to unsigned int32.
Definition enum_object.hpp:629
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:458
static auto to_string(enum_t value) noexcept -> xtd::string
Converts this instance to string.
Definition enum_object.hpp:617
static auto to_uint16(enum_t value) noexcept -> xtd::uint16
Converts this instance to unsigned int16.
Definition enum_object.hpp:623
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:360
static auto to_sbyte(enum_t value) noexcept -> xtd::sbyte
Converts this instance to signed byte.
Definition enum_object.hpp:611
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:414
static auto to_int32(enum_t value) noexcept -> xtd::int32
Converts this instance to int32.
Definition enum_object.hpp:599
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:559
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:528
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:518
static auto to_byte(enum_t value) noexcept -> xtd::byte
Converts this instance to byte.
Definition enum_object.hpp:587
static auto to_uint64(enum_t value) noexcept -> xtd::uint64
Converts this instance to unsigned int64.
Definition enum_object.hpp:635
static auto to_int64(enum_t value) noexcept -> xtd::int64
Converts this instance to int64.
Definition enum_object.hpp:605
Provides the base class for enumerations.
Definition enum_object.hpp:48
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
Definition enum_object.hpp:119
auto to_int16() const noexcept -> xtd::int16
Converts this instance to int16.
Definition enum_object.hpp:144
auto to_sbyte() const noexcept -> xtd::sbyte
Converts this instance to signed byte.
Definition enum_object.hpp:156
auto to_byte() const noexcept -> xtd::byte
Converts this instance to byte.
Definition enum_object.hpp:140
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:132
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:127
auto to_uint16() const noexcept -> xtd::uint16
Converts this instance to unsigned int16.
Definition enum_object.hpp:160
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
Definition enum_object.hpp:136
auto to_int32() const noexcept -> xtd::int32
Converts this instance to int32.
Definition enum_object.hpp:148
auto to_uint64() const noexcept -> xtd::uint64
Converts this instance to unsigned int64.
Definition enum_object.hpp:168
enum_t value_type
Represents the enumeration type.
Definition enum_object.hpp:55
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:196
auto to_int64() const noexcept -> xtd::int64
Converts this instance to int64.
Definition enum_object.hpp:152
auto to_uint32() const noexcept -> xtd::uint32
Converts this instance to unsigned int32.
Definition enum_object.hpp:164
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:90
enum_t enum_type
Represents the enumeration type.
Definition enum_object.hpp:53
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:110
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:123
static auto parse(const xtd::string &str) -> enum_type
Converts the string to its enum_type equivalent.
Definition enum_object.hpp:225
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:94
auto to_string() const noexcept -> xtd::string override
Returns a xtd::string that represents the current object.
Definition enum_object.hpp:172