xtd 0.2.0
xtd::enum_object< enum_t > Struct Template Reference
Inheritance diagram for xtd::enum_object< enum_t >:
xtd::object xtd::icomparable< type_t > xtd::iequatable< type_t > xtd::iformatable xtd::interface xtd::extensions::comparison_operators< type_t, icomparable< type_t > > xtd::interface xtd::extensions::equality_operators< type_t, iequatable< type_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:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:35
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
Provides the base class for enumerations.
Definition enum_object.hpp:49
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/as>
#include <xtd/console>
#include <xtd/enum_class>
using namespace 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
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
int32 to_int32() const noexcept
Converts this instance to int32.
Definition enum_object.hpp:149
enum_object() noexcept=default
Initializes a new instance of the xtd::enum_object class.
The following code show how to use xtd::enum_object class for an enum flags.
#include <xtd/as>
#include <xtd/console>
#include <xtd/enum_class>
using namespace 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
@ normal
Represent the exit mode when the terminates normally (via xtd::environment::exit or returning from th...
Examples
colored_forms.cpp, enum.cpp, enum_class.cpp, enum_class_flags.cpp, enum_class_flags_introspection.cpp, enum_class_flags_without_helpers.cpp, enum_class_parse.cpp, enum_class_ut.cpp, enum_class_without_helper.cpp, enum_struct.cpp, enum_struct_ut.cpp, enum_ut.cpp, form_background_image2.cpp, parse_enum.cpp, parse_enum_class.cpp, parse_enum_struct.cpp, sprintf_enum.cpp, and sprintf_enum_class.cpp.

Public Aliases

using enum_type = enum_t
 Represents the enumeration type.
 
using value_type = enum_t
 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 std::locale &loc) 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.
 
static enum_type parse (const xtd::string &str, bool ignore_case)
 Converts the string to its enum_type equivalent with a specified boolean to ignore case.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 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::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::icomparable< type_t >
virtual int32 compare_to (const type_t &obj) const noexcept=0
 Compares the current instance with another object of the same type.
 
- Public Member Functions inherited from xtd::iequatable< type_t >
virtual bool equals (const type_t &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 
- Public Member Functions inherited from xtd::iformatable
- Static Public Member Functions inherited from xtd::object
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 = enum_t

Represents the enumeration type.

◆ value_type

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

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

◆ 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.

Examples
sprintf_enum.cpp, and sprintf_enum_class.cpp.

◆ 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.
@ gray
The color gray.
@ white
The color white.
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");
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition enum_object.hpp:173

◆ 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 std::locale &  loc 
) const
overridevirtual

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

Parameters
formatA format string.
locAn std::locale object that contains locale information (see std::locale).
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() [1/2]

template<class enum_t = std::nullptr_t>
static 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.

◆ parse() [2/2]

template<class enum_t = std::nullptr_t>
static enum_type xtd::enum_object< enum_t >::parse ( const xtd::string str,
bool  ignore_case 
)
inlinestatic

Converts the string to its enum_type equivalent with a specified boolean to ignore case.

Parameters
valueA string containing a enum_type to convert.
ignore_case'trueto ingore case; otherwisefalse. @return Aenum_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: