xtd 0.2.0
Loading...
Searching...
No Matches
xtd::enum_object< enum_t > Struct Template Reference
Inheritance diagram for xtd::enum_object< enum_t >:
xtd::object xtd::icomparable< enum_object< std::nullptr_t > > xtd::iequatable< enum_object< std::nullptr_t > > xtd::iformatable xtd::interface xtd::extensions::comparison_operators< enum_object< std::nullptr_t >, icomparable< enum_object< std::nullptr_t > > > xtd::interface xtd::extensions::equality_operators< enum_object< std::nullptr_t >, iequatable< enum_object< std::nullptr_t > > > xtd::interface

Definition

template<class enum_t = std::nullptr_t>
struct xtd::enum_object< enum_t >

Provides the base class for enumerations.

template<class enum_t = std::nullptr_t>
struct enum_object : xtd::object, xtd::icomparable<enum_object<enum_t>>, xtd::iequatable<enum_object<enum_t>>, xtd::iformatable;
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
enum_object() noexcept=default
Initializes a new instance of the xtd::enum_object class.
Inheritance
xtd::objectxtd::enum_object <enum_t>
Header
#include <xtd/enum_object>
Namespace
xtd
Library
xtd.core
Remarks
For more information about enumeration, see enum class guide.
For more information about types, see Native types, boxing and unboxing. The following code show how to use xtd::enum_object class for an enum.
#include <xtd/xtd>
enum_class_(, enum_test,
value_one,
value_two,
value_three,
value_four
);
auto main() -> int {
console::write_line("name = {}", enum_test::value_four);
console::write_line("value = {}", enum_object(enum_test::value_four).to_int32());
console::write_line("as<int> = {}", as<int>(enum_test::value_four));
}
// This code produces the following output :
//
// name = value_four
// value = 3
// as<int> = 3
// values = [0, 1, 2, 3]
// names = [value_one, value_two, value_three, value_four]
// entries = [(0, value_one), (1, value_two), (2, value_three), (3, value_four)]
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
#define enum_class_(namespace_name, enum_class_t,...)
Provides the registration struct for enum class.
Definition enum_class.hpp:52
auto as(any_object &o) -> type_t
Casts a type into another type.
Definition __as_any_object.hpp:60
int32 to_int32() const noexcept
Converts this instance to int32.
Definition enum_object.hpp:148
The following code show how to use xtd::enum_object class for an enum flags.
#include <xtd/xtd>
enum_class_(, text_attribute,
normal = 0b0,
bold = 0b1,
italic = 0b10,
underline = 0b100,
strikeout = 0b1000
);
flags_attribute_(, text_attribute);
auto main() -> int {
console::write_line("name = {}", text_attribute::bold | text_attribute::italic);
console::write_line("value = {}", enum_object(text_attribute::bold | text_attribute::italic).to_int32());
console::write_line("as<int> = {}", as<int>(text_attribute::bold | text_attribute::italic));
}
// This code produces the following output :
//
// name = bold, italic
// value = 3
// as<int> = 3
// values = [0, 1, 2, 4, 8]
// names = [normal, bold, italic, underline, strikeout]
// entries = [(0, normal), (1, bold), (2, italic), (4, underline), (8, strikeout)]
#define flags_attribute_(namespace_name, enum_type)
Provides the set attribute struct for enumerations helper.
Definition flags_attribute.hpp:34
Examples
culture_info_culture_types.cpp, and sizeof.cpp.

Public Aliases

using enum_type
 Represents the enumeration type.
using value_type
 Represents the enumeration type.

Public Properties

enum_type value
 Gets or sets the value of the enum.
bool has_flag (enum_type flag) const noexcept
 Retrieves an array of the values of the constants in a specified enumeration.

Public Constructors

 enum_object () noexcept=default
 Initializes a new instance of the xtd::enum_object class.
 enum_object (enum_type value)
 Initializes a new instance of the xtd::enum_object class with specified value.

Public Methods

int32 compare_to (const enum_object &value) const noexcept override
 Compares the current instance with another object of the same type.
bool equals (const object &obj) const noexcept override
 Determines whether the specified object is equal to the current object.
bool equals (const enum_object &value) const noexcept override
 Determines whether the specified object is equal to the current object.
bool equals (enum_type value) const noexcept
 Indicates whether the current object is equal to another object of the same type.
template<class attribute_t>
bool equals (attribute_t value) const noexcept
 Indicates whether the current object is equal to another object with defferent type.
xtd::size get_hash_code () const noexcept override
 Serves as a hash function for a particular type.
xtd::byte to_byte () const noexcept
 Converts this instance to byte.
int16 to_int16 () const noexcept
 Converts this instance to int16.
int32 to_int32 () const noexcept
 Converts this instance to int32.
int64 to_int64 () const noexcept
 Converts this instance to int64.
sbyte to_sbyte () const noexcept
 Converts this instance to signed byte.
uint16 to_uint16 () const noexcept
 Converts this instance to unsigned int16.
uint32 to_uint32 () const noexcept
 Converts this instance to unsigned int32.
uint64 to_uint64 () const noexcept
 Converts this instance to unsigned int64.
xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
xtd::string to_string (const xtd::string &format) const
 Converts the value of this instance to its equivalent string representation using the specified format.
xtd::string to_string (const xtd::string &format, const globalization::culture_info &culture) const override
 Converts the value of this instance to its equivalent string representation using the specified format, and locale.

Public Static Methods

static enum_type parse (const xtd::string &str)
 Converts the string to its enum_type equivalent.

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
template<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
virtual int32 compare_to (const enum_object< std::nullptr_t > &obj) const noexcept=0
 Compares the current instance with another object of the same type.
virtual bool equals (const enum_object< std::nullptr_t > &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
template<class object_a_t, class object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
template<class object_a_t, class object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.

Member Typedef Documentation

◆ enum_type

template<class enum_t = std::nullptr_t>
using xtd::enum_object< enum_t >::enum_type

Represents the enumeration type.

◆ value_type

template<class enum_t = std::nullptr_t>
using xtd::enum_object< enum_t >::value_type

Represents the enumeration type.

Constructor & Destructor Documentation

◆ enum_object() [1/2]

template<class enum_t = std::nullptr_t>
xtd::enum_object< enum_t >::enum_object ( )
defaultnoexcept

Initializes a new instance of the xtd::enum_object class.

◆ enum_object() [2/2]

template<class enum_t = std::nullptr_t>
xtd::enum_object< enum_t >::enum_object ( enum_type value)
inlineexplicit

Initializes a new instance of the xtd::enum_object class with specified value.

Parameters
valueValue to set to this instance.

Member Function Documentation

◆ has_flag()

template<class enum_t = std::nullptr_t>
bool xtd::enum_object< enum_t >::has_flag ( enum_type flag) const
inlinenoexcept

Retrieves an array of the values of the constants in a specified enumeration.

Parameters
flagAn enumeration value.
Returns
true if the bit field or bit fields that are set in flag are also set in the current instance; otherwise, false.
Remarks
The has_flag method returns the result of the following bool expression : this_instance And flag = flag
Examples
culture_info_culture_types.cpp.

◆ compare_to()

template<class enum_t = std::nullptr_t>
int32 xtd::enum_object< enum_t >::compare_to ( const enum_object< enum_t > & value) const
inlineoverridenoexcept

Compares the current instance with another object of the same type.

Parameters
valueAn object to compare with this instance.
Returns
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Condition
Less than zero This instance is less than obj.
Zero This instance is equal to obj.
Greater than zero This instance is greater than obj.

◆ equals() [1/4]

template<class enum_t = std::nullptr_t>
bool xtd::enum_object< enum_t >::equals ( const object & obj) const
inlineoverridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.

Reimplemented from xtd::object.

◆ equals() [2/4]

template<class enum_t = std::nullptr_t>
bool xtd::enum_object< enum_t >::equals ( const enum_object< enum_t > & value) const
inlineoverridenoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.

◆ equals() [3/4]

template<class enum_t = std::nullptr_t>
bool xtd::enum_object< enum_t >::equals ( enum_type value) const
inlinenoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

◆ equals() [4/4]

template<class enum_t = std::nullptr_t>
template<class attribute_t>
bool xtd::enum_object< enum_t >::equals ( attribute_t value) const
inlinenoexcept

Indicates whether the current object is equal to another object with defferent type.

Parameters
objAn object to compare with this object.
Returns
Always return false.

◆ get_hash_code()

template<class enum_t = std::nullptr_t>
xtd::size xtd::enum_object< enum_t >::get_hash_code ( ) const
inlineoverridevirtualnoexcept

Serves as a hash function for a particular type.

Returns
size_t A hash code for the current object.

Reimplemented from xtd::object.

◆ to_byte()

template<class enum_t = std::nullptr_t>
xtd::byte xtd::enum_object< enum_t >::to_byte ( ) const
inlinenoexcept

Converts this instance to byte.

Returns
A new xtd::byte object converted from this instance.

◆ to_int16()

template<class enum_t = std::nullptr_t>
int16 xtd::enum_object< enum_t >::to_int16 ( ) const
inlinenoexcept

Converts this instance to int16.

Returns
A new to_int16 object converted from this instance.

◆ to_int32()

template<class enum_t = std::nullptr_t>
int32 xtd::enum_object< enum_t >::to_int32 ( ) const
inlinenoexcept

Converts this instance to int32.

Returns
A new to_int32 object converted from this instance.

◆ to_int64()

template<class enum_t = std::nullptr_t>
int64 xtd::enum_object< enum_t >::to_int64 ( ) const
inlinenoexcept

Converts this instance to int64.

Returns
A new to_int64 object converted from this instance.

◆ to_sbyte()

template<class enum_t = std::nullptr_t>
sbyte xtd::enum_object< enum_t >::to_sbyte ( ) const
inlinenoexcept

Converts this instance to signed byte.

Returns
A new sbyte object converted from this instance.

◆ to_uint16()

template<class enum_t = std::nullptr_t>
uint16 xtd::enum_object< enum_t >::to_uint16 ( ) const
inlinenoexcept

Converts this instance to unsigned int16.

Returns
A new to_uint16 object converted from this instance.

◆ to_uint32()

template<class enum_t = std::nullptr_t>
uint32 xtd::enum_object< enum_t >::to_uint32 ( ) const
inlinenoexcept

Converts this instance to unsigned int32.

Returns
A new to_uint32 object converted from this instance.

◆ to_uint64()

template<class enum_t = std::nullptr_t>
uint64 xtd::enum_object< enum_t >::to_uint64 ( ) const
inlinenoexcept

Converts this instance to unsigned int64.

Returns
A new to_uint64 object converted from this instance.

◆ to_string() [1/3]

template<class enum_t = std::nullptr_t>
xtd::string xtd::enum_object< enum_t >::to_string ( ) const
inlineoverridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

◆ to_string() [2/3]

template<class enum_t = std::nullptr_t>
xtd::string xtd::enum_object< enum_t >::to_string ( const xtd::string & format) const
inline

Converts the value of this instance to its equivalent string representation using the specified format.

Parameters
formatA format string.
Returns
The string representation of the value of this instance as specified by format.
Exceptions
xtd::format_exceptionformat contains an invalid specification.
Remarks
The format parameter can be one of the following format strings: "G" or "g", "D" or "d", "X" or "x", and "F" or "f" (the format string is not case-sensitive). If format is null or an empty string (""), the general format specifier ("G") is used. For more information about the enumeration format strings and formatting enumeration values, see Enumeration Format Strings. For more information about formatting in general, see Formatting Types.
Notes to caller
If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member's name based on its underlying value, your code should not make any assumptions about which name the method will return. For example, the following enumeration defines two members, shade::gray and shade::grey, that have the same underlying value.
enum shade {
white = 0, gray = 1, grey = 1, black = 2
};
@ black
The color black.
Definition console_color.hpp:24
@ gray
The color gray.
Definition console_color.hpp:38
@ white
The color white.
Definition console_color.hpp:54
The following method call attempts to retrieve the name of a member of the shade enumeration whose underlying value is 1. The method can return either "gray" or "grey", and your code should not make any assumptions about which string will be returned.
string shade_name = enum_object<shade>(as<shade>(1)).to_string("F");

◆ to_string() [3/3]

template<class enum_t = std::nullptr_t>
xtd::string xtd::enum_object< enum_t >::to_string ( const xtd::string & format,
const globalization::culture_info & culture ) const
overridevirtual

Converts the value of this instance to its equivalent string representation using the specified format, and locale.

Parameters
formatA format string.
cultureAn xtd::globalization::culture_info object that contains culture information.
Returns
The string representation of the value of this instance as specified by format.
Exceptions
xtd::format_exceptionformat contains an invalid specification.
Remarks
The format parameter can be one of the following format strings: "G" or "g", "D" or "d", "X" or "x", and "F" or "f" (the format string is not case-sensitive). If format is null or an empty string (""), the general format specifier ("G") is used. For more information about the enumeration format strings and formatting enumeration values, see Enumeration Format Strings. For more information about formatting in general, see Formatting Types.
Notes to caller
If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member's name based on its underlying value, your code should not make any assumptions about which name the method will return. For example, the following enumeration defines two members, shade::gray and shade::grey, that have the same underlying value.
enum shade {
white = 0, gray = 1, grey = 1, black = 2
};
The following method call attempts to retrieve the name of a member of the shade enumeration whose underlying value is 1. The method can return either "gray" or "grey", and your code should not make any assumptions about which string will be returned.
string shade_name = enum_object<shade>(as<shade>(1)).to_string("F");

Implements xtd::iformatable.

◆ parse()

template<class enum_t = std::nullptr_t>
enum_type xtd::enum_object< enum_t >::parse ( const xtd::string & str)
inlinestatic

Converts the string to its enum_type equivalent.

Parameters
valueA string containing a enum_type to convert.
Returns
A enum_type equivalent to the native value contained in value.

Member Data Documentation

◆ value

template<class enum_t = std::nullptr_t>
enum_type xtd::enum_object< enum_t >::value

Gets or sets the value of the enum.

Parameters
valueThe value of the enum.

The documentation for this struct was generated from the following file: