xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Public Member Functions | Protected Member Functions | List of all members
xtd::diagnostics::switch_base Class Reference

#include <switch_base.h>

Definition

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

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_base 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_base. When inheriting from this class, you must implement the switch_setting method.

Public Member Functions

const std::map< xtd::ustring, xtd::ustring > & attributes () const
 Gets the custom switch attributes nA StringDictionary containing the case-insensitive custom attributes for the trace switch. More...
 
std::map< xtd::ustring, xtd::ustring > & attributes ()
 Gets the custom switch attributes. More...
 
void attributes (const std::map< xtd::ustring, xtd::ustring > &attributes)
 Sets the custom switch attributes. More...
 
const xtd::ustringdescription () const
 Gets a description of the switch. More...
 
const xtd::ustringdisplay_name () const
 Gets a name used to identify the switch. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object. More...
 

Protected Member Functions

 switch_base (const xtd::ustring &display_name, const xtd::ustring &description)
 Initializes a new instance of the switch_base class. More...
 
 switch_base (const xtd::ustring &display_name, const xtd::ustring &description, const xtd::ustring &default_switch_value)
 Initializes a new instance of the switch_base class. More...
 
virtual std::vector< xtd::ustringget_supported_attributes () const
 Gets the custom attributes supported by the switch. More...
 
virtual void on_switch_setting_changed ()
 Invoked when the switch_setting property is changed. More...
 
virtual void on_value_changed ()
 Invoked when the value property is changed. More...
 
int32_t switch_setting () const
 Gets the current setting for this switch. More...
 
void switch_setting (int32_t switch_setting)
 Sets the current setting for this switch. More...
 
const xtd::ustringvalue () const
 Gets the value of the switch. More...
 
void value (const xtd::ustring &value)
 Sets the value of the switch. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ switch_base() [1/2]

xtd::diagnostics::switch_base::switch_base ( const xtd::ustring display_name,
const xtd::ustring description 
)
protected

Initializes a new instance of the switch_base class.

Parameters
display_nameThe name of the switch.
descriptionThe description for the switch.
Remarks
When you create a new switch_base 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.

◆ switch_base() [2/2]

xtd::diagnostics::switch_base::switch_base ( const xtd::ustring display_name,
const xtd::ustring description,
const xtd::ustring default_switch_value 
)
protected

Initializes a new instance of the switch_base class.

Parameters
display_nameThe name of the switch.
descriptionThe description for the switch.
default_switch_valueThe default value for the switch.
Remarks
The display_name parameter is used to set the value of the display_name property, and the description parameter is use to set the value of the description property. The default_switch_value parameter is the value for the switch if the value property is not set by code.

Member Function Documentation

◆ attributes() [1/3]

const std::map<xtd::ustring, xtd::ustring>& xtd::diagnostics::switch_base::attributes ( ) const

Gets the custom switch attributes nA StringDictionary containing the case-insensitive custom attributes for the trace switch.

◆ attributes() [2/3]

std::map<xtd::ustring, xtd::ustring>& xtd::diagnostics::switch_base::attributes ( )

Gets the custom switch attributes.

Returns
A StringDictionary containing the case-insensitive custom attributes for the trace switch.

◆ attributes() [3/3]

void xtd::diagnostics::switch_base::attributes ( const std::map< xtd::ustring, xtd::ustring > &  attributes)

Sets the custom switch attributes.

Parameters
attributesA StringDictionary containing the case-insensitive custom attributes for the trace switch.

◆ description()

const xtd::ustring& xtd::diagnostics::switch_base::description ( ) const

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_base constructor.

◆ display_name()

const xtd::ustring& xtd::diagnostics::switch_base::display_name ( ) const

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_base object, the display_name finds initial switch settings. For more information, see the switch_base constructor.

◆ get_supported_attributes()

virtual std::vector<xtd::ustring> xtd::diagnostics::switch_base::get_supported_attributes ( ) const
protectedvirtual

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 {} (mepty array)l. 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_base 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 void xtd::diagnostics::switch_base::on_switch_setting_changed ( )
protectedvirtual

Invoked when the switch_setting property is changed.

Reimplemented in xtd::diagnostics::trace_switch.

◆ on_value_changed()

virtual void xtd::diagnostics::switch_base::on_value_changed ( )
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::trace_switch, and xtd::diagnostics::source_switch.

◆ switch_setting() [1/2]

int32_t xtd::diagnostics::switch_base::switch_setting ( ) const
protected

Gets the current setting for this switch.

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

◆ switch_setting() [2/2]

void xtd::diagnostics::switch_base::switch_setting ( int32_t  switch_setting)
protected

Sets the current setting for this switch.

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

◆ value() [1/2]

const xtd::ustring& xtd::diagnostics::switch_base::value ( ) const
protected

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]

void xtd::diagnostics::switch_base::value ( const xtd::ustring value)
protected

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.

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