xtd 0.2.0
Loading...
Searching...
No Matches
xtd::enum_object< enum_t > Class 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::comparison_operators< type_t, icomparable< type_t > > xtd::interface xtd::equality_operators< type_t, iequatable< type_t > > xtd::interface

Definition

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

Provides the base class for enumerations.

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...
Provides the base class for enumerations.
Definition enum_object.h:41
int32 to_int32() const noexcept
Converts this instance to int32.
Definition enum_object.h:113
enum_object() noexcept=default
Initializes a new instance of the xtd::enum_object class.
#define enum_class_(namespace_name, enum_class_t,...)
Provides the registration struct for enum class.
Definition enum_class.h:52
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
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.h: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
 

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 Properties

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

Public Methods

int32 compare_to (const enum_object &value) const noexcept override
 
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.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename 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<typename object_a_t , typename 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<typename object_a_t , typename 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.
 

Constructor & Destructor Documentation

◆ enum_object() [1/2]

template<typename 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<typename 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<typename 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

◆ value() [1/2]

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

Gets the value of the enum.

Returns
The value of the enum.

◆ value() [2/2]

template<typename enum_t = std::nullptr_t>
enum_object & xtd::enum_object< enum_t >::value ( enum_type  value)
inline

Sets the value of the enum.

Parameters
valueThe value of the enum.

◆ to_byte()

template<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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.
Examples
The following code example demonstrates what to_string returns.
#include <xtd/xtd>
using namespace xtd;
namespace examples {
namespace object_test {
class object1 : public object {
};
}
}
auto main() -> int {
ptr<object> obj1 = new_ptr<examples::object_test::object1>();
console::write_line(obj1->to_string());
ptr<object> obj2 = new_ptr<date_time>(1971, 1, 5, 23, 5, 0);
console::write_line(obj2->to_string());
ptr<object> obj3 = new_ptr<boolean_object>();
console::write_line(obj3->to_string());
}
// This code produces the following output :
//
// examples::object_test::object1
// Tue Jan 5 23:05:00 1971
// false
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27

Reimplemented from xtd::object.

Examples
sprintf_enum.cpp, and sprintf_enum_class.cpp.

◆ to_string() [2/3]

template<typename 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.h:135

◆ to_string() [3/3]

template<typename 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.


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