ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
Strategy< Derived > Struct Template Referenceabstract

CRTP base class providing self-registration for strategy types. More...

#include <Strategy.hpp>

Public Types

using Factory = Ptr (*)(nlohmann::json const&)
 Factory function type for deserializing a strategy from JSON.
 
using Ptr = std::shared_ptr<Derived>
 

Public Member Functions

virtual ~Strategy ()=default
 
virtual std::string display_name () const =0
 Human-readable name for display in summaries.
 
virtual void to_json (nlohmann::json &j) const =0
 Serialize this strategy's configuration to JSON.
 

Static Public Member Functions

static Ptr from_json (nlohmann::json const &j)
 Construct a strategy from its JSON representation.
 
static bool register_strategy (std::string const &name, Factory factory)
 Register a concrete strategy for JSON deserialization.
 

Detailed Description

template<typename Derived>
struct Strategy< Derived >

CRTP base class providing self-registration for strategy types.

Each strategy family (PP, DR, SR) inherits from Strategy<Derived> to get a shared_ptr Ptr typedef, a static registry of named factory functions, and a from_json() dispatcher that looks up the "name" field and delegates to the registered factory.

Concrete strategies register themselves at static-init time via the PPFOREST2_REGISTER_STRATEGY macro.

Template Parameters
DerivedThe strategy base class (e.g. PPStrategy).

Member Typedef Documentation

◆ Factory

template<typename Derived>
using Strategy< Derived >::Factory = Ptr (*)(nlohmann::json const&)

Factory function type for deserializing a strategy from JSON.

◆ Ptr

template<typename Derived>
using Strategy< Derived >::Ptr = std::shared_ptr<Derived>

Constructor & Destructor Documentation

◆ ~Strategy()

template<typename Derived>
virtual Strategy< Derived >::~Strategy ( )
virtualdefault

Member Function Documentation

◆ display_name()

template<typename Derived>
virtual std::string Strategy< Derived >::display_name ( ) const
pure virtual

◆ from_json()

template<typename Derived>
static Ptr Strategy< Derived >::from_json ( nlohmann::json const & j)
inlinestatic

Construct a strategy from its JSON representation.

Dispatches on the "name" field to the registered factory.

Parameters
jJSON object (must contain "name").
Returns
Shared pointer to the constructed strategy.

◆ register_strategy()

template<typename Derived>
static bool Strategy< Derived >::register_strategy ( std::string const & name,
Factory factory )
inlinestatic

Register a concrete strategy for JSON deserialization.

Called automatically by concrete strategies via inline static initialization. Adding a new strategy only requires defining a static from_json and the PPFOREST2_REGISTER_STRATEGY macro.

Parameters
nameStrategy name (must match the "name" field in JSON).
factoryFactory function that constructs the strategy.
Returns
Always true (return value used for static init).

◆ to_json()

template<typename Derived>
virtual void Strategy< Derived >::to_json ( nlohmann::json & j) const
pure virtual

Serialize this strategy's configuration to JSON.

Must include a "name" field identifying the strategy type, plus any strategy-specific parameters.

Parameters
jJSON object to populate.

Implemented in ppforest2::dr::DRNoopStrategy, ppforest2::dr::DRUniformStrategy, ppforest2::pp::PPPDAStrategy, and ppforest2::sr::SRMeanOfMeansStrategy.


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