xtd 0.2.0
Loading...
Searching...
No Matches
xtd::diagnostics::switch_object Class Reference
Inheritance diagram for xtd::diagnostics::switch_object:
xtd::object xtd::iequatable< xtd::diagnostics::switch_object > xtd::interface xtd::extensions::equality_operators< xtd::diagnostics::switch_object, iequatable< xtd::diagnostics::switch_object > > xtd::diagnostics::boolean_switch xtd::diagnostics::source_switch xtd::diagnostics::trace_switch

Definition

Provides an abstract base class to create new debugging and tracing switches.

switch_object(const xtd::string &display_name, const xtd::string &description)
Initializes a new instance of the switch_object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::objectxtd::diagnostics::switch_object
Header
#include <xtd/diagnostics/switch_object>
Namespace
xtd::diagnostics
Library
xtd.core
Remarks
A switch provides an efficient mechanism for controlling tracing and debugging output at run time using external settings. The switch_object class implements default behavior for switches, allowing you to change the switch level at run time.
This class is the base class for the boolean_switch, source_switch and the trace_switch classes. These switches meet most debugging and tracing needs.
Notes to implementers
If you need trace levels, or mechanisms for setting switch levels different from those provided by boolean_switch, source_switch and trace_switch, you can inherit from switch_object. When inheriting from this class, you must implement the switch_setting method.

Public Aliases

using attribute_collection
 Represents the attributes collection.
 

Public Properties

auto attributes () const noexcept -> const attribute_collection &
 Gets the custom switch attributes.
 
auto attributes () noexcept -> attribute_collection &
 Gets the custom switch attributes.
 
auto attributes (const attribute_collection &attributes) noexcept -> void
 Sets the custom switch attributes.
 
auto description () const noexcept -> const xtd::string &
 Gets a description of the switch.
 
auto display_name () const noexcept -> const xtd::string &
 Gets a name used to identify the switch.
 
auto value () const noexcept -> const xtd::string &
 Gets the value of the switch.
 
auto value (const xtd::string &value) -> void
 Sets the value of the switch.
 

Public Methods

auto equals (const xtd::object &obj) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
 
auto equals (const switch_object &other) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
 

Protected constructors

 switch_object (const xtd::string &display_name, const xtd::string &description)
 Initializes a new instance of the switch_object class.
 

Protected Properties

auto switch_setting () const noexcept -> xtd::int32
 Gets the current setting for this switch.
 
auto switch_setting (xtd::int32 switch_setting) -> void
 Sets the current setting for this switch.
 

Protected Methods

virtual auto get_supported_attributes () const noexcept -> xtd::array< xtd::string >
 Gets the custom attributes supported by the switch.
 
virtual auto on_switch_setting_changed () -> void
 Invoked when the switch_setting property is changed.
 
virtual auto on_value_changed () -> void
 Invoked when the value property is changed.
 

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual xtd::size 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<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const
 Returns a xtd::string that represents the current 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

◆ attribute_collection

Represents the attributes collection.

Constructor & Destructor Documentation

◆ switch_object()

xtd::diagnostics::switch_object::switch_object ( const xtd::string & display_name,
const xtd::string & description )
protected

Initializes a new instance of the switch_object class.

Parameters
display_nameThe name of the switch.
descriptionThe description for the switch.
Remarks
When you create a new switch_object object, the value of the display_name parameter is used to find initial switch settings. The default value is an empty string ("").
Notes to inheritors
To set the value of the switch, set the switch_setting property in the constructor.

Member Function Documentation

◆ attributes() [1/3]

auto xtd::diagnostics::switch_object::attributes ( ) const -> const attribute_collection &
nodiscardnoexcept

Gets the custom switch attributes.

Returns
A xtd::collections::specialized::string_dictionary containing the case-insensitive custom attributes for the trace switch.

◆ attributes() [2/3]

auto xtd::diagnostics::switch_object::attributes ( ) -> attribute_collection &
nodiscardnoexcept

Gets the custom switch attributes.

Returns
A xtd::collections::specialized::string_dictionary containing the case-insensitive custom attributes for the trace switch.

◆ attributes() [3/3]

auto xtd::diagnostics::switch_object::attributes ( const attribute_collection & attributes) -> void
noexcept

Sets the custom switch attributes.

Parameters
attributesA xtd::collections::specialized::string_dictionary containing the case-insensitive custom attributes for the trace switch.

◆ description()

auto xtd::diagnostics::switch_object::description ( ) const -> const xtd::string &
nodiscardnoexcept

Gets a description of the switch.

Returns
The description of the switch. The default value is an empty string ("").
Remarks
This property should indicate the function of the switch; for example, "Enables tracing for a directory watcher component." The value is set by the descriptor parameter in the switch_object constructor.

◆ display_name()

auto xtd::diagnostics::switch_object::display_name ( ) const -> const xtd::string &
nodiscardnoexcept

Gets a name used to identify the switch.

Returns
The name used to identify the switch. The default value is an empty string ("").
Remarks
When you create a new switch_object object, the display_name finds initial switch settings. For more information, see the switch_object constructor.

◆ value() [1/2]

auto xtd::diagnostics::switch_object::value ( ) const -> const xtd::string &
nodiscardnoexcept

Gets the value of the switch.

Returns
A string representing the value of the switch.
Remarks
The on_value_changed method is called when the value of the value property is changed. The on_value_changed method parses the value of this property and converts it to an integer value, which is then used to set the switch_setting property.
Notes to inheritors
You should override the on_value_changed() method and provide a conversion operation that sets the appropriate switch_setting value for your switch.

◆ value() [2/2]

auto xtd::diagnostics::switch_object::value ( const xtd::string & value) -> void

Sets the value of the switch.

Parameters
valueA string representing the value of the switch.
Remarks
The on_value_changed method is called when the value of the value property is changed. The on_value_changed method parses the value of this property and converts it to an integer value, which is then used to set the switch_setting property.
Notes to inheritors
You should override the on_value_changed() method and provide a conversion operation that sets the appropriate switch_setting value for your switch.

◆ equals() [1/2]

auto xtd::diagnostics::switch_object::equals ( const xtd::object & obj) const -> bool
nodiscardoverridevirtualnoexcept

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/2]

auto xtd::diagnostics::switch_object::equals ( const switch_object & other) const -> bool
nodiscardoverridevirtualnoexcept

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

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

Implements xtd::iequatable< xtd::diagnostics::switch_object >.

◆ switch_setting() [1/2]

auto xtd::diagnostics::switch_object::switch_setting ( ) const -> xtd::int32
nodiscardprotectednoexcept

Gets the current setting for this switch.

Returns
The current setting for this switch. The default is zero.

◆ switch_setting() [2/2]

auto xtd::diagnostics::switch_object::switch_setting ( xtd::int32 switch_setting) -> void
protected

Sets the current setting for this switch.

Parameters
switch_settingThe current setting for this switch. The default is zero.

◆ get_supported_attributes()

virtual auto xtd::diagnostics::switch_object::get_supported_attributes ( ) const -> xtd::array< xtd::string >
nodiscardprotectedvirtualnoexcept

Gets the custom attributes supported by the switch.

Returns
A string array that contains the names of the custom attributes supported by the switch, or null if there no custom attributes are supported.
Remarks
The default implementation for the get_supported_attributes method returns {} (empty array). If a switch is added in a configuration file and custom attributes are specified that are not included in the string array returned by get_supported_attributes, a configuration_exception is thrown when the switch is loaded.
Notes to Inheritors
When inheriting from the switch_object class or a derived class, you can override the get_supported_attributes() method to provide custom attributes for your class.

◆ on_switch_setting_changed()

virtual auto xtd::diagnostics::switch_object::on_switch_setting_changed ( ) -> void
protectedvirtual

Invoked when the switch_setting property is changed.

Reimplemented in xtd::diagnostics::trace_switch.

◆ on_value_changed()

virtual auto xtd::diagnostics::switch_object::on_value_changed ( ) -> void
protectedvirtual

Invoked when the value property is changed.

Remarks
The default implementation parses the new value of the value property to an integer value which it uses to set the switch_setting property.
Not to Inheritors
You should override this method and use a conversion that sets the appropriate switch_setting value for your switch.

Reimplemented in xtd::diagnostics::boolean_switch, xtd::diagnostics::source_switch, and xtd::diagnostics::trace_switch.


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