Rune Caster 1.0.0
Modern C++ Text Processing Framework
Loading...
Searching...
No Matches
rune_caster::Spell Class Reference

Unified spell object for text transformation. More...

#include <spell_unified.hpp>

Public Types

using transform_function = std::function<RuneSequence(const RuneSequence&)>
using validation_function = std::function<bool(const RuneSequence&)>

Public Member Functions

 Spell () noexcept
 Default constructor (identity spell)
 Spell (transform_function transform, std::string name="CustomSpell", std::string description="User-defined transformation")
 Construct from transformation function.
template<typename Func>
requires std::invocable<Func, const RuneSequence&> && std::convertible_to<std::invoke_result_t<Func, const RuneSequence&>, RuneSequence>
 Spell (Func &&func, std::string name="LambdaSpell", std::string description="Lambda transformation")
 Construct from lambda or functor (template)
 Spell (const Spell &)=default
 Spell (Spell &&) noexcept=default
Spelloperator= (const Spell &)=default
Spelloperator= (Spell &&) noexcept=default
 ~Spell ()=default
RuneSequence operator() (const RuneSequence &input) const
 Apply the spell transformation.
std::string operator() (std::string_view utf8_input) const
 Apply the spell to a UTF-8 string.
Spell operator| (const Spell &next) const
 Compose with another spell (pipeline operator)
const std::string & name () const noexcept
 Get the spell name.
const std::string & description () const noexcept
 Get the spell description.
uint64_t id () const noexcept
 Get the spell unique ID.
bool is_identity () const noexcept
 Check if this spell is the identity transformation.
bool is_composition () const noexcept
 Check if this spell is a composition of multiple spells.
size_t composition_depth () const noexcept
 Get the number of composed spells (1 for simple spells)
std::string to_string () const
 Get a detailed string representation.
RuneSequence test (const RuneSequence &test_input) const
 Test the spell with sample input.

Static Public Member Functions

static Spell identity ()
 Create an identity spell (no transformation)
static Spell constant (RuneSequence constant_result)
 Create a spell that always returns the same result.
static Spell conditional (validation_function condition, const Spell &if_true, const Spell &if_false)
 Create a conditional spell.

Detailed Description

Unified spell object for text transformation.

Following the Rune design philosophy, this class provides a single, extensible interface for all text transformations. Users can create custom spells using lambdas, functions, or functors while maintaining full compatibility with the Caster pipeline system.

Design principles:

  • Single unified type (like Rune for characters)
  • Easy extensibility through function objects
  • Pipeline compatibility with operator|
  • Zero-overhead abstractions where possible
  • Full Caster integration

Definition at line 29 of file spell_unified.hpp.

Member Typedef Documentation

◆ transform_function

Definition at line 32 of file spell_unified.hpp.

◆ validation_function

using rune_caster::Spell::validation_function = std::function<bool(const RuneSequence&)>

Definition at line 33 of file spell_unified.hpp.

Constructor & Destructor Documentation

◆ Spell() [1/5]

rune_caster::Spell::Spell ( )
noexcept

Default constructor (identity spell)

Definition at line 17 of file unified_spell.cpp.

◆ Spell() [2/5]

rune_caster::Spell::Spell ( transform_function transform,
std::string name = "CustomSpell",
std::string description = "User-defined transformation" )
explicit

Construct from transformation function.

Parameters
transformThe transformation function
nameOptional name for the spell
descriptionOptional description

Definition at line 26 of file unified_spell.cpp.

◆ Spell() [3/5]

template<typename Func>
requires std::invocable<Func, const RuneSequence&> && std::convertible_to<std::invoke_result_t<Func, const RuneSequence&>, RuneSequence>
rune_caster::Spell::Spell ( Func && func,
std::string name = "LambdaSpell",
std::string description = "Lambda transformation" )
inlineexplicit

Construct from lambda or functor (template)

Parameters
funcLambda or functor that transforms RuneSequence
nameOptional name for the spell
descriptionOptional description

Definition at line 61 of file spell_unified.hpp.

◆ Spell() [4/5]

rune_caster::Spell::Spell ( const Spell & )
default

◆ Spell() [5/5]

rune_caster::Spell::Spell ( Spell && )
defaultnoexcept

◆ ~Spell()

rune_caster::Spell::~Spell ( )
default

Member Function Documentation

◆ composition_depth()

size_t rune_caster::Spell::composition_depth ( ) const
inlinenodiscardnoexcept

Get the number of composed spells (1 for simple spells)

Returns
The composition depth

Definition at line 141 of file spell_unified.hpp.

◆ conditional()

Spell rune_caster::Spell::conditional ( validation_function condition,
const Spell & if_true,
const Spell & if_false )
static

Create a conditional spell.

Parameters
conditionCondition function
if_trueSpell to apply if condition is true
if_falseSpell to apply if condition is false
Returns
Conditional spell

Definition at line 107 of file unified_spell.cpp.

◆ constant()

Spell rune_caster::Spell::constant ( RuneSequence constant_result)
static

Create a spell that always returns the same result.

Parameters
constant_resultThe constant result to return
Returns
Constant spell

Definition at line 98 of file unified_spell.cpp.

◆ description()

const std::string & rune_caster::Spell::description ( ) const
inlinenodiscardnoexcept

Get the spell description.

Returns
The spell description

Definition at line 115 of file spell_unified.hpp.

◆ id()

uint64_t rune_caster::Spell::id ( ) const
inlinenodiscardnoexcept

Get the spell unique ID.

Returns
The spell ID

Definition at line 121 of file spell_unified.hpp.

◆ identity()

Spell rune_caster::Spell::identity ( )
static

Create an identity spell (no transformation)

Returns
Identity spell

Definition at line 94 of file unified_spell.cpp.

◆ is_composition()

bool rune_caster::Spell::is_composition ( ) const
inlinenodiscardnoexcept

Check if this spell is a composition of multiple spells.

Returns
true if composition, false otherwise

Definition at line 135 of file spell_unified.hpp.

◆ is_identity()

bool rune_caster::Spell::is_identity ( ) const
nodiscardnoexcept

Check if this spell is the identity transformation.

Returns
true if identity, false otherwise

Definition at line 70 of file unified_spell.cpp.

◆ name()

const std::string & rune_caster::Spell::name ( ) const
inlinenodiscardnoexcept

Get the spell name.

Returns
The spell name

Definition at line 109 of file spell_unified.hpp.

◆ operator()() [1/2]

RuneSequence rune_caster::Spell::operator() ( const RuneSequence & input) const

Apply the spell transformation.

Parameters
inputThe input sequence to transform
Returns
The transformed sequence

Definition at line 39 of file unified_spell.cpp.

◆ operator()() [2/2]

std::string rune_caster::Spell::operator() ( std::string_view utf8_input) const

Apply the spell to a UTF-8 string.

Parameters
utf8_inputThe UTF-8 input string
Returns
The transformed UTF-8 string

Definition at line 43 of file unified_spell.cpp.

◆ operator=() [1/2]

Spell & rune_caster::Spell::operator= ( const Spell & )
default

◆ operator=() [2/2]

Spell & rune_caster::Spell::operator= ( Spell && )
defaultnoexcept

◆ operator|()

Spell rune_caster::Spell::operator| ( const Spell & next) const

Compose with another spell (pipeline operator)

Parameters
nextThe next spell in the pipeline
Returns
A new spell representing the composition

Definition at line 51 of file unified_spell.cpp.

◆ test()

RuneSequence rune_caster::Spell::test ( const RuneSequence & test_input) const

Test the spell with sample input.

Parameters
test_inputSample input for testing
Returns
The transformation result

Definition at line 88 of file unified_spell.cpp.

◆ to_string()

std::string rune_caster::Spell::to_string ( ) const
nodiscard

Get a detailed string representation.

Returns
String representation for debugging

Definition at line 76 of file unified_spell.cpp.


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