Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
kcenon::logger::composite_strategy Class Reference

Combines multiple configuration strategies. More...

#include <composite_strategy.h>

Inheritance diagram for kcenon::logger::composite_strategy:
Inheritance graph
Collaboration diagram for kcenon::logger::composite_strategy:
Collaboration graph

Public Member Functions

std::string get_name () const override
 Get the strategy name.
 
void apply (logger_config &config) const override
 Apply this strategy to a logger configuration.
 
bool is_applicable () const override
 Check if this strategy is applicable in the current context.
 
composite_strategyadd (std::unique_ptr< config_strategy_interface > strategy)
 Add a strategy to the composite.
 
template<typename Strategy , typename... Args>
composite_strategyadd (Args &&... args)
 Add a strategy by constructing it in-place.
 
composite_strategyclear ()
 Clear all strategies.
 
std::size_t size () const
 Get the number of strategies.
 
bool empty () const
 Check if composite is empty.
 
- Public Member Functions inherited from kcenon::logger::config_strategy_interface
virtual ~config_strategy_interface ()=default
 
virtual int priority () const
 Get the strategy priority.
 

Private Attributes

std::vector< std::unique_ptr< config_strategy_interface > > strategies_
 

Detailed Description

Combines multiple configuration strategies.

Stores multiple strategies and applies them in priority order. Strategies with higher priority values are applied first.

Since
2.0.0

Definition at line 32 of file composite_strategy.h.

Member Function Documentation

◆ add() [1/2]

template<typename Strategy , typename... Args>
composite_strategy & kcenon::logger::composite_strategy::add ( Args &&... args)
inline

Add a strategy by constructing it in-place.

Template Parameters
StrategyThe strategy type to construct
ArgsConstructor argument types
Parameters
argsConstructor arguments
Returns
Reference to this for chaining

Definition at line 86 of file composite_strategy.h.

86 {
87 strategies_.push_back(
88 std::make_unique<Strategy>(std::forward<Args>(args)...)
89 );
90 return *this;
91 }
std::vector< std::unique_ptr< config_strategy_interface > > strategies_

References strategies_.

◆ add() [2/2]

composite_strategy & kcenon::logger::composite_strategy::add ( std::unique_ptr< config_strategy_interface > strategy)
inline

Add a strategy to the composite.

Parameters
strategyThe strategy to add
Returns
Reference to this for chaining

Definition at line 71 of file composite_strategy.h.

71 {
72 if (strategy) {
73 strategies_.push_back(std::move(strategy));
74 }
75 return *this;
76 }

References strategies_.

◆ apply()

void kcenon::logger::composite_strategy::apply ( logger_config & config) const
inlineoverridevirtual

Apply this strategy to a logger configuration.

Parameters
configThe configuration to modify

Modifies the provided configuration according to the strategy's rules. Changes are applied in-place.

Implements kcenon::logger::config_strategy_interface.

Definition at line 38 of file composite_strategy.h.

38 {
39 // Create sorted copy of strategies by priority (descending)
40 std::vector<const config_strategy_interface*> sorted;
41 sorted.reserve(strategies_.size());
42 for (const auto& strategy : strategies_) {
43 sorted.push_back(strategy.get());
44 }
45 std::sort(sorted.begin(), sorted.end(),
46 [](const auto* a, const auto* b) {
47 return a->priority() > b->priority();
48 });
49
50 // Apply each applicable strategy in order
51 for (const auto* strategy : sorted) {
52 if (strategy->is_applicable()) {
53 strategy->apply(config);
54 }
55 }
56 }

References strategies_.

◆ clear()

composite_strategy & kcenon::logger::composite_strategy::clear ( )
inline

Clear all strategies.

Returns
Reference to this for chaining

Definition at line 97 of file composite_strategy.h.

97 {
98 strategies_.clear();
99 return *this;
100 }

References clear(), and strategies_.

Referenced by clear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

bool kcenon::logger::composite_strategy::empty ( ) const
inline

Check if composite is empty.

Returns
true if no strategies are contained

Definition at line 114 of file composite_strategy.h.

114 {
115 return strategies_.empty();
116 }

References strategies_.

◆ get_name()

std::string kcenon::logger::composite_strategy::get_name ( ) const
inlineoverridevirtual

Get the strategy name.

Returns
Human-readable strategy name

Implements kcenon::logger::config_strategy_interface.

Definition at line 34 of file composite_strategy.h.

34 {
35 return "composite";
36 }

◆ is_applicable()

bool kcenon::logger::composite_strategy::is_applicable ( ) const
inlineoverridevirtual

Check if this strategy is applicable in the current context.

Returns
true if the strategy should be applied

Override to implement conditional strategy application (e.g., only apply in certain environments).

Reimplemented from kcenon::logger::config_strategy_interface.

Definition at line 58 of file composite_strategy.h.

58 {
59 // Applicable if any contained strategy is applicable
60 return std::any_of(strategies_.begin(), strategies_.end(),
61 [](const auto& strategy) {
62 return strategy->is_applicable();
63 });
64 }

References strategies_.

◆ size()

std::size_t kcenon::logger::composite_strategy::size ( ) const
inline

Get the number of strategies.

Returns
Number of contained strategies

Definition at line 106 of file composite_strategy.h.

106 {
107 return strategies_.size();
108 }

References strategies_.

Member Data Documentation

◆ strategies_

std::vector<std::unique_ptr<config_strategy_interface> > kcenon::logger::composite_strategy::strategies_
private

Definition at line 119 of file composite_strategy.h.

Referenced by add(), add(), apply(), clear(), empty(), is_applicable(), and size().


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