xtd 0.2.0
enum_object.h
Go to the documentation of this file.
1 #pragma once
5 #include "enum_attribute.h"
6 #include "enum_collection.h"
7 #include "enum_register.h"
8 #include "enum_set_attribute.h"
9 #include "format_exception.h"
10 #include "icomparable.h"
11 #include "iequatable.h"
12 #include "number_styles.h"
13 #include "optional.h"
14 #include "static.h"
15 #include "string_comparison.h"
16 #include "string_split_options.h"
17 
19 namespace xtd {
21 
37  template<typename enum_t = std::nullptr_t>
38  class enum_object : public xtd::object, public xtd::icomparable<enum_object<enum_t>>, public xtd::iequatable<enum_object<enum_t>> {
39  public:
41 
43  using enum_type = enum_t;
45 
47 
50  enum_object() noexcept = default;
53  explicit enum_object(enum_type value) : value_(value) {}
55 
57  explicit enum_object(xtd::byte value) : value_(to_enum(value)) {}
58  explicit enum_object(sbyte value) : value_(to_enum(value)) {}
59  explicit enum_object(int16 value) : value_(to_enum(value)) {}
60  explicit enum_object(int32 value) : value_(to_enum(value)) {}
61  explicit enum_object(int64 value) : value_(to_enum(value)) {}
62  explicit enum_object(uint16 value) : value_(to_enum(value)) {}
63  explicit enum_object(uint32 value) : value_(to_enum(value)) {}
64  explicit enum_object(uint64 value) : value_(to_enum(value)) {}
65  enum_object(enum_object&&) noexcept = default;
66  enum_object(const enum_object&) noexcept = default;
67  enum_object& operator =(const enum_object&) noexcept = default;
68  operator enum_type() const noexcept {return value_;}
70 
72 
78  bool has_flag(enum_type flag) const noexcept {return (to_int(value_) & to_int(flag)) == to_int(flag);}
79 
82  enum_type value() const noexcept {return value_;}
85  enum_object& value(enum_type value) {
86  value_ = value;
87  return *this;
88  }
90 
92 
94  int32 compare_to(const enum_object& value) const noexcept override {
95  if (to_int(value_) == to_int(value.value_)) return 0;
96  if (to_int(value_) < to_int(value.value_)) return -1;
97  return 1;
98  }
99 
102  xtd::byte to_byte() const noexcept {return static_cast<xtd::byte>(value_);}
103 
106  int16 to_int16() const noexcept {return static_cast<int16>(value_);}
107 
110  int32 to_int32() const noexcept {return static_cast<int32>(value_);}
111 
114  int64 to_int64() const noexcept {return static_cast<int64>(value_);}
115 
118  sbyte to_sbyte() const noexcept {return static_cast<sbyte>(value_);}
119 
122  uint16 to_uint16() const noexcept {return static_cast<uint16>(value_);}
123 
126  uint32 to_uint32() const noexcept {return static_cast<uint32>(value_);}
127 
130  uint64 to_uint64() const noexcept {return static_cast<uint64>(value_);}
131 
132  xtd::ustring to_string() const noexcept override {
133  init();
134  if (attribute() == xtd::enum_attribute::flags) return to_string_flags();
135 
136  auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == value_;});
137  if (iterator == entries().end()) return ustring::format("{}", to_int(value_));
138 
139  return iterator->second;
140  }
141 
158  xtd::ustring to_string(const xtd::ustring& format) const {
159  init();
160  auto fmt = format;
161  if (fmt.empty()) fmt = "G";
162 
163  switch (fmt[0]) {
164  case 'b':
165  case 'B':
166  case 'd':
167  case 'D':
168  case 'o':
169  case 'O':
170  case 'x':
171  case 'X': return __numeric_formatter(fmt, static_cast<long long int>(value_), std::locale());
172  case 'f':
173  case 'F':
174  case 'g':
175  case 'G': return __format_stringer<char>(value_);
176  }
177  throw format_exception("Invalid format"_t);
178  }
180 
182  bool equals(const enum_object& value) const noexcept override {return value_ == value.value_;}
183  bool equals(enum_type value) const noexcept {return value_ == value;}
184  template<typename attribute_t>
185  bool equals(attribute_t value) const noexcept {return false;}
186 
187  static enum_type parse(const xtd::ustring& str) {return parse(str, false);}
188  static enum_type parse(const xtd::ustring& str, bool ignore_case) {
189  enum_object<enum_type>().init();
190  if (enum_object<enum_type>().attribute() == xtd::enum_attribute::flags) return parse_flags(str, ignore_case);
191 
192  for (auto item : enum_object<enum_type>().entries()) {
193  if (xtd::ustring::compare(str, item.second, ignore_case) == 0)
194  return static_cast<enum_type>(item.first);
195  }
196 
197  return to_enum(xtd::parse<int64>(str));
198  }
199 
200  static enum_type parse_flags(const xtd::ustring& value, bool ignore_case) {
201  std::vector<xtd::ustring> values = value.split({','});
202  for (xtd::ustring& str : values)
203  str = str.trim(' ');
204 
205  if (values.size() == 1) {
206  for (auto item : enum_object<enum_type>().entries()) {
207  if (xtd::ustring::compare(value, item.second, ignore_case) == 0)
208  return to_enum(item.first);
209  }
210  return to_enum(xtd::parse<int64>(value));
211  }
212 
213  int64 result = 0;
214  for (xtd::ustring str : values) {
215  bool found = false;
216  for (auto item : enum_object<enum_type>().entries()) {
217  if (xtd::ustring::compare(str, item.second, ignore_case) == 0) {
218  found = true;
219  result |= to_int(item.first);
220  break;
221  }
222  }
223  if (found == false)
224  throw xtd::format_exception {csf_};
225  }
226 
227  return to_enum(result);
228  }
230 
231  private:
232  friend class enum_object<std::nullptr_t>;
233 
234  xtd::ustring get_name() const noexcept {
235  auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == value_;});
236  if (iterator == entries().end()) return xtd::ustring::format("{}", to_int(value_));
237  return iterator->second;
238  }
239 
240  xtd::ustring to_string_flags() const noexcept {
241  auto iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == value_;});
242  if (to_int(value_) == 0 && iterator == entries().end()) return "0";
243 
244  iterator = std::find_if(entries().begin(), entries().end(), [&](auto value)->bool {return value.first == to_enum(0);});
245  if (to_int(value_) == 0) return iterator == entries().end() ? "0" : iterator->second;
246 
247  xtd::ustring str;
248  int64 rest = to_int(value_);
249  enum_collection<enum_type> reversed_entries = entries();
250  std::reverse(reversed_entries.begin(), reversed_entries.end());
251 
252  for (auto item : reversed_entries) {
253  if (to_int(item.first) != 0 && (rest & to_int(item.first)) == to_int(item.first)) {
254  rest -= to_int(item.first);
255  if (!xtd::ustring::is_empty(str)) str = ", " + str;
256  str = item.second + str;
257  }
258  }
259 
260  if (str.empty() || rest > 0) return xtd::ustring::format("{}", to_int(value_));
261 
262  return str;
263  }
264 
265  template<typename attribute_t>
266  static enum_type to_enum(attribute_t value) noexcept {return static_cast<enum_type>(value);}
267  static int64 to_int(enum_type value) noexcept {return static_cast<int64>(value);}
268 
269  static xtd::enum_attribute attribute() noexcept {
270  if (attribute_.has_value()) return attribute_.value();
272  return attribute_.value();
273  }
274 
275  static enum_collection<enum_type>& entries() noexcept {
276  if (entries_.has_value()) return entries_.value();
278  return entries_.value();
279  };
280 
281  static void init() noexcept {
282  attribute();
283  entries();
284  }
285 
286  inline static std::optional<xtd::enum_attribute> attribute_;
287  inline static std::optional<enum_collection<enum_type>> entries_;
288  enum_type value_ {};
289  };
290 
299  template<>
300  class enum_object<std::nullptr_t> static_ {
301  public:
304  template<typename enum_t>
305  static const xtd::enum_collection<enum_t>& get_entries() noexcept {
306  return enum_object<enum_t>().entries();
307  }
308 
311  template<typename enum_t>
314  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);});
315  return entries;
316  }
317 
320  template<typename enum_t>
323  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);});
324  return entries;
325  }
326 
329  template<typename enum_t>
332  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);});
333  return entries;
334  }
335 
338  template<typename enum_t>
341  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);});
342  return entries;
343  }
344 
347  template<typename enum_t>
350  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);});
351  return entries;
352  }
353 
356  template<typename enum_t>
359  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);});
360  return entries;
361  }
362 
365  template<typename enum_t>
368  std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_uint32(), entry.second);});
369  return entries;
370  }
371 
374  template<typename enum_t>
377  std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {entries.emplace_back(enum_object<enum_t>(entry.first).to_uint64(), entry.second);});
378  return entries;
379  }
380 
385  template<typename enum_t>
386  static xtd::ustring get_name(enum_t value) noexcept {return enum_object<enum_t>(value).to_string();}
391  template<typename enum_t>
397  template<typename enum_t>
403  template<typename enum_t>
405 
409  template<typename enum_t>
410  static std::vector<xtd::ustring> get_names() noexcept {
411  std::vector<xtd::ustring> names;
412  std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {names.push_back(entry.second);});
413  return names;
414  }
415 
419  template<typename enum_t>
420  static std::vector<enum_t> get_values() noexcept {
421  std::vector<enum_t> values;
422  std::for_each(enum_object<enum_t>().entries().begin(), enum_object<enum_t>().entries().end(), [&](auto entry) {values.push_back(entry.first);});
423  return values;
424  }
425 
429  template<typename enum_t>
430  static std::vector<xtd::byte> get_values_as_byte() noexcept {
431  std::vector<xtd::byte> values;
432  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());});
433  return values;
434  }
435 
439  template<typename enum_t>
440  static std::vector<int16> get_values_as_int16() noexcept {
441  std::vector<int16> values;
442  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());});
443  return values;
444  }
445 
449  template<typename enum_t>
450  static std::vector<int32> get_values_as_int32() noexcept {
451  std::vector<int32> values;
452  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());});
453  return values;
454  }
455 
459  template<typename enum_t>
460  static std::vector<int64> get_values_as_int64() noexcept {
461  std::vector<int64> values;
462  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());});
463  return values;
464  }
465 
469  template<typename enum_t>
470  static std::vector<sbyte> get_values_as_sbyte() noexcept {
471  std::vector<sbyte> values;
472  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());});
473  return values;
474  }
475 
479  template<typename enum_t>
480  static std::vector<uint16> get_values_as_uint16() noexcept {
481  std::vector<uint16> values;
482  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());});
483  return values;
484  }
485 
489  template<typename enum_t>
490  static std::vector<uint32> get_values_as_uint32() noexcept {
491  std::vector<uint32> values;
492  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());});
493  return values;
494  }
495 
499  template<typename enum_t>
500  static std::vector<uint64> get_values_as_uint64() noexcept {
501  std::vector<uint64> values;
502  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());});
503  return values;
504  }
505 
510  template<typename enum_t>
511  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();}
516  template<typename enum_t>
517  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();}
518 
523  template<typename enum_t>
524  static enum_t parse(const xtd::ustring& value) {return parse<enum_t>(value, false);}
530  template<typename enum_t>
531  static enum_t parse(const xtd::ustring& str, bool ignore_case) {
532  return enum_object<enum_t>::parse(str, ignore_case);
533  }
534 
538  template<typename enum_t>
539  static xtd::byte to_byte(enum_t value) noexcept {return enum_object<enum_t>(value).to_byte();}
540 
544  template<typename enum_t>
545  static int16 to_int16(enum_t value) noexcept {return enum_object<enum_t>(value).to_int16();}
546 
550  template<typename enum_t>
551  static int32 to_int32(enum_t value) noexcept {return enum_object<enum_t>(value).to_int32();}
552 
556  template<typename enum_t>
557  static int64 to_int64(enum_t value) noexcept {return enum_object<enum_t>(value).to_int64();}
558 
562  template<typename enum_t>
563  static sbyte to_sbyte(enum_t value) noexcept {return enum_object<enum_t>(value).to_sbyte();}
564 
568  template<typename enum_t>
569  static xtd::ustring to_string(enum_t value) noexcept {return enum_object<enum_t>(value).to_string();}
570 
574  template<typename enum_t>
575  static uint16 to_uint16(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint16();}
576 
580  template<typename enum_t>
581  static uint32 to_uint32(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint32();}
582 
586  template<typename enum_t>
587  static uint64 to_uint64(enum_t value) noexcept {return enum_object<enum_t>(value).to_uint64();}
588 
593  template<typename enum_t>
594  static bool try_parse(const xtd::ustring& value, enum_t& result) noexcept {return try_parse<enum_t>(value, false, result);}
595 
601  template<typename enum_t>
602  static bool try_parse(const xtd::ustring& value, bool ignore_case, enum_t& result) noexcept {
603  try {
604  result = parse<enum_t>(value, ignore_case);
605  return true;
606  } catch (...) {
607  return false;
608  }
609  }
610  };
612 
614  template<typename type_t>
615  inline std::string to_string(const xtd::enum_object<type_t>& value, const std::string& fmt, const std::locale& loc) {
616  return value.to_string(fmt);
617  }
619 }
620 
622 template<typename enum_t>
623 inline std::string __enum_to_string(enum_t value) noexcept {
625 }
626 
627 template<typename value_t>
628 value_t __parse_enum(const std::string& str) {
629  return xtd::enum_object<>::parse<value_t>(str);
630 }
632 
int64 to_int64() const noexcept
Converts this instance to int64.
Definition: enum_object.h:114
static xtd::ustring get_name(int64 value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value...
Definition: enum_object.h:404
static xtd::ustring to_string(enum_t value) noexcept
Converts this instance to string.
Definition: enum_object.h:569
Contains xtd::static_object class.
static xtd::ustring get_name(enum_t value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value...
Definition: enum_object.h:386
Contains xtd::enum_set_attribute strcut.
static std::vector< sbyte > get_values_as_sbyte() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:470
int16 to_int16() const noexcept
Converts this instance to int16.
Definition: enum_object.h:106
static bool is_defined(enum_object< enum_t > value) noexcept
Returns an indication whether a constant with a specified value exists in a specified enumeration...
Definition: enum_object.h:517
xtd::ustring to_string(const xtd::ustring &format) const
Converts the value of this instance to its equivalent string representation using the specified forma...
Definition: enum_object.h:158
static std::vector< xtd::ustring > get_names() noexcept
Retrieves an array of the names of the constants in a specified enumeration.
Definition: enum_object.h:410
Contains std::optional type and std::bad_optional_access exception.
static xtd::enum_collection< uint32 > get_entries_as_uint32() noexcept
Retrieves an array of the std::pair<uint32, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:366
Contains xtd::iequatable interface.
int_least8_t sbyte
Represents a 8-bit signed integer.
Definition: types.h:173
value_t parse(const std::string &str)
Convert a string into a type.
Definition: parse.h:23
Contains xtd::format_exception exception.
static int16 to_int16(enum_t value) noexcept
Converts this instance to int16.
Definition: enum_object.h:545
enum_attribute
Specifies the enum attribute.
Definition: enum_attribute.h:20
Contains xtd::icomparable interface.
#define static_
This keyword is use to represent a static object. A static object can&#39;t be instantiated (constructors...
Definition: static.h:37
sbyte to_sbyte() const noexcept
Converts this instance to signed byte.
Definition: enum_object.h:118
static uint32 to_uint32(enum_t value) noexcept
Converts this instance to unsigned int32.
Definition: enum_object.h:581
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition: icomparable.h:17
static std::vector< int16 > get_values_as_int16() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:440
Represents the base class for custom attributes.
Definition: attribute.h:23
bool has_flag(enum_type flag) const noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:78
Enum flags attribute.
enum_object & value(enum_type value)
Sets the value of the enum.
Definition: enum_object.h:85
uint64 to_uint64() const noexcept
Converts this instance to unsigned int64.
Definition: enum_object.h:130
static std::vector< int32 > get_values_as_int32() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:450
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
static uint64 to_uint64(enum_t value) noexcept
Converts this instance to unsigned int64.
Definition: enum_object.h:587
static std::vector< uint16 > get_values_as_uint16() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:480
Contains xtd::enum_attribute enum class.
static xtd::enum_collection< uint16 > get_entries_as_uint16() noexcept
Retrieves an array of the std::pair<uint16, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:357
static int32 to_int32(enum_t value) noexcept
Converts this instance to int32.
Definition: enum_object.h:551
#define csf_
Provides information about the current stack frame.
Definition: current_stack_frame.h:30
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition: types.h:228
uint32 to_uint32() const noexcept
Converts this instance to unsigned int32.
Definition: enum_object.h:126
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
std::vector< std::pair< enum_t, xtd::ustring > > enum_collection
Represents a pair of an enum_t value and a string of an enum of type enum_t.
Definition: enum_collection.h:19
static int64 to_int64(enum_t value) noexcept
Converts this instance to int64.
Definition: enum_object.h:557
ustring trim() const noexcept
Removes all leading and trailing occurrences of white-space characters from the specified xtd::ustrin...
static uint16 to_uint16(enum_t value) noexcept
Converts this instance to unsigned int16.
Definition: enum_object.h:575
static int32 compare(const ustring &str_a, const ustring &str_b) noexcept
Compares two specified string objects and returns an integer that indicates their relative position i...
static bool is_defined(enum_t value) noexcept
Returns an indication whether a constant with a specified value exists in a specified enumeration...
Definition: enum_object.h:511
uint16 to_uint16() const noexcept
Converts this instance to unsigned int16.
Definition: enum_object.h:122
int32 to_int32() const noexcept
Converts this instance to int32.
Definition: enum_object.h:110
static xtd::enum_collection< sbyte > get_entries_as_sbyte() noexcept
Retrieves an array of the std::pair<sbyte, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:348
static bool try_parse(const xtd::ustring &value, bool ignore_case, enum_t &result) noexcept
Converts the xtd::ustring representation of the name or numeric value of one or more enumerated const...
Definition: enum_object.h:602
bool is_empty() const noexcept
Indicates whether this string is an empty string ("").
Definition: ustring.h:918
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
Provides the set attribute struct for enumerations.
Definition: enum_set_attribute.h:29
std::vector< ustring > split(const std::vector< value_type > &separators, size_t count, string_split_options options) const noexcept
Splits this string into a maximum number of substrings based on the characters in an array...
enum_type value() const noexcept
Gets the value of the enum.
Definition: enum_object.h:82
bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
Contains xtd::enum_register.
static xtd::ustring get_name(enum_object< enum_t > value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value...
Definition: enum_object.h:392
static std::vector< uint64 > get_values_as_uint64() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:500
enum_object(enum_type value)
Initializes a new instance of the xtd::enum_object class with specified value.
Definition: enum_object.h:53
static const xtd::enum_collection< enum_t > & get_entries() noexcept
Retrieves an array of the std::pair<enum_t, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:305
int_least16_t int16
Represents a 16-bit signed integer.
Definition: types.h:118
static enum_t parse(const xtd::ustring &value)
Converts the xtd::ustring representation of the name or numeric value of one or more enumerated const...
Definition: enum_object.h:524
The exception that is thrown when the format of an argument does not meet the parameter specification...
Definition: format_exception.h:18
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Provides the base class for enumerations.
Definition: enum_object.h:38
int32 compare_to(const enum_object &value) const noexcept override
Compares the current instance with another object of the same type.
Definition: enum_object.h:94
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains xtd::string_split_options enum class.
static xtd::ustring get_name(int32 value) noexcept
Retrieves the name of the constant in the specified enumeration that has the specified value...
Definition: enum_object.h:398
static enum_t parse(const xtd::ustring &str, bool ignore_case)
Converts the xtd::ustring representation of the name or numeric value of one or more enumerated const...
Definition: enum_object.h:531
static xtd::enum_collection< int64 > get_entries_as_int64() noexcept
Retrieves an array of the std::pair<int64, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:339
static sbyte to_sbyte(enum_t value) noexcept
Converts this instance to signed byte.
Definition: enum_object.h:563
enum_object() noexcept=default
Initializes a new instance of the xtd::enum_object class.
static std::vector< xtd::byte > get_values_as_byte() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:430
static xtd::enum_collection< xtd::byte > get_entries_as_byte() noexcept
Retrieves an array of the std::pair<xtd::byte, xtd::ustring> of the constants in a specified enumerat...
Definition: enum_object.h:312
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:744
xtd::byte to_byte() const noexcept
Converts this instance to byte.
Definition: enum_object.h:102
Contains xtd::enum_collection.
static std::vector< int64 > get_values_as_int64() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:460
static std::vector< enum_t > get_values() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:420
static xtd::enum_collection< int16 > get_entries_as_int16() noexcept
Retrieves an array of the std::pair<int16, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:321
static std::vector< uint32 > get_values_as_uint32() noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition: enum_object.h:490
xtd::ustring to_string() const noexcept override
Returns a sxd::ustring that represents the current object.
Definition: enum_object.h:132
uint_least64_t uint64
Represents a 64-bit unsigned integer.
Definition: types.h:250
int_least64_t int64
Represents a 64-bit signed integer.
Definition: types.h:140
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition: types.h:39
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:239
static xtd::enum_collection< int32 > get_entries_as_int32() noexcept
Retrieves an array of the std::pair<int32, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:330
Contains xtd::number_styles enum class.
Contains xtd::string_comparison enum class.
static xtd::enum_collection< uint64 > get_entries_as_uint64() noexcept
Retrieves an array of the std::pair<uint64, xtd::ustring> of the constants in a specified enumeration...
Definition: enum_object.h:375
Provides the registration struct for enumerations.
Definition: enum_register.h:36
static xtd::byte to_byte(enum_t value) noexcept
Converts this instance to byte.
Definition: enum_object.h:539
static bool try_parse(const xtd::ustring &value, enum_t &result) noexcept
Converts the xtd::ustring representation of the name or numeric value of one or more enumerated const...
Definition: enum_object.h:594