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.
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
xtd::diagnostics::source_switch Class Reference

#include <source_switch.h>

Definition

Provides a multilevel switch to control tracing and debug output without recompiling your code.

Namespace
xtd::diagnostics
Library
xtd.core
Remarks
The switch property of the trace_source class is a source_switch object. The source_switch class provides a level property to test the event level of the switch. The level property gets or sets the switch's trace_level value.
The switch is used to check whether a trace should be propagated or ignored. Each trace_source trace method calls the should_trace method before calling the listeners. If the should_trace method returns false, the trace is ignored and the trace method exits. If the should_trace method returns true, the trace is passed to the listeners.

Inherits xtd::diagnostics::switch_base.

Public Member Functions

 source_switch (const xtd::ustring &display_name, const xtd::ustring &default_switch_value)
 Initializes a new instance of the source_switch class, specifying the display name and the default value for the source switch.
 
 source_switch (const xtd::ustring &name)
 Initializes a new instance of the source_switch class, specifying the name of the source.
 
xtd::diagnostics::source_levels level () const
 Gets the level of the switch.
 
void level (xtd::diagnostics::source_levels level)
 Sets the level of the switch.
 
bool should_trace (xtd::diagnostics::trace_event_type event_type)
 Determines if trace listeners should be called, based on the trace event type.
 
- Public Member Functions inherited from xtd::diagnostics::switch_base
std::map< xtd::ustring, xtd::ustring > & attributes ()
 Gets the custom switch attributes.
 
const std::map< xtd::ustring, xtd::ustring > & attributes () const
 Gets the custom switch attributes @rettur nA StringDictionary containing the case-insensitive custom attributes for the trace switch.
 
void attributes (const std::map< xtd::ustring, xtd::ustring > &attributes)
 Sets the custom switch attributes.
 
const xtd::ustringdescription () const
 Gets a description of the switch.
 
const xtd::ustringdisplay_name () const
 Gets a name used to identify the switch.
 
- 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.
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance.
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object.
 

Protected Member Functions

void on_value_changed () override
 Invoked when the value of the value property changes.
 
- Protected Member Functions inherited from xtd::diagnostics::switch_base
 switch_base (const xtd::ustring &display_name, const xtd::ustring &description)
 Initializes a new instance of the switch_base class.
 
 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.
 
virtual std::vector< xtd::ustringget_supported_attributes () const
 Gets the custom attributes supported by the switch.
 
virtual void on_switch_setting_changed ()
 Invoked when the switch_setting property is changed.
 
virtual void on_value_changed ()
 Invoked when the value property is changed.
 
int32_t switch_setting () const
 Gets the current setting for this switch.
 
void switch_setting (int32_t switch_setting)
 Sets the current setting for this switch.
 
const xtd::ustringvalue () const
 Gets the value of the switch.
 
void value (const xtd::ustring &value)
 Sets the value of the switch.
 

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.
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ source_switch() [1/2]

xtd::diagnostics::source_switch::source_switch ( const xtd::ustring name)
explicit

Initializes a new instance of the source_switch class, specifying the name of the source.

Parameters
nameThe name of the source.
Remarks
The name parameter is used to set the value of the display_name property.

◆ source_switch() [2/2]

xtd::diagnostics::source_switch::source_switch ( const xtd::ustring display_name,
const xtd::ustring default_switch_value 
)

Initializes a new instance of the source_switch class, specifying the display name and the default value for the source switch.

Parameters
display_nameThe name of the source.
default_switch_valueThe default value for the switch.
Remarks
The display_name parameter is used to set the value of the display_name property; the default_switch_value parameter is saved as a field and used to initialize the value property on first reference.

Member Function Documentation

◆ level() [1/2]

xtd::diagnostics::source_levels xtd::diagnostics::source_switch::level ( ) const

Gets the level of the switch.

Returns
One of the SourceLevels values that represents the event level of the switch.
Remarks
This property gets its value from the switch_setting property. Setting this property also modifies the switch_setting property.

◆ level() [2/2]

void xtd::diagnostics::source_switch::level ( xtd::diagnostics::source_levels  level)

Sets the level of the switch.

Parameters
levelOne of the SourceLevels values that represents the event level of the switch.
Remarks
This property gets its value from the switch_setting property. Setting this property also modifies the switch_setting property.

◆ on_value_changed()

void xtd::diagnostics::source_switch::on_value_changed ( )
overrideprotectedvirtual

Invoked when the value of the value property changes.

Remarks
The on_value_changed method converts the new value of the value property to the integer representation of the matching field in the source_levels enumeration, and then uses this integer to set the switch_setting property.

Reimplemented from xtd::diagnostics::switch_base.

◆ should_trace()

bool xtd::diagnostics::source_switch::should_trace ( xtd::diagnostics::trace_event_type  event_type)

Determines if trace listeners should be called, based on the trace event type.

Parameters
event_typeOne of the trace_event_type values.
Returns
true if the trace listeners should be called; otherwise, false.
Remarks
This method is called by the trace methods in the trace_source class to determine whether listeners should be called to write a trace.
Note
Application code should not call this method; it is intended to be called only by methods in the trace_source class.

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