Rune Caster 1.0.0
Modern C++ Text Processing Framework
|
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 | |
Spell & | operator= (const Spell &)=default |
Spell & | operator= (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. |
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:
Definition at line 29 of file spell_unified.hpp.
using rune_caster::Spell::transform_function = std::function<RuneSequence(const RuneSequence&)> |
Definition at line 32 of file spell_unified.hpp.
using rune_caster::Spell::validation_function = std::function<bool(const RuneSequence&)> |
Definition at line 33 of file spell_unified.hpp.
|
noexcept |
Default constructor (identity spell)
Definition at line 17 of file unified_spell.cpp.
|
explicit |
Construct from transformation function.
transform | The transformation function |
name | Optional name for the spell |
description | Optional description |
Definition at line 26 of file unified_spell.cpp.
|
inlineexplicit |
Construct from lambda or functor (template)
func | Lambda or functor that transforms RuneSequence |
name | Optional name for the spell |
description | Optional description |
Definition at line 61 of file spell_unified.hpp.
|
default |
|
defaultnoexcept |
|
default |
|
inlinenodiscardnoexcept |
Get the number of composed spells (1 for simple spells)
Definition at line 141 of file spell_unified.hpp.
|
static |
Create a conditional spell.
condition | Condition function |
if_true | Spell to apply if condition is true |
if_false | Spell to apply if condition is false |
Definition at line 107 of file unified_spell.cpp.
|
static |
Create a spell that always returns the same result.
constant_result | The constant result to return |
Definition at line 98 of file unified_spell.cpp.
|
inlinenodiscardnoexcept |
Get the spell description.
Definition at line 115 of file spell_unified.hpp.
|
inlinenodiscardnoexcept |
|
static |
Create an identity spell (no transformation)
Definition at line 94 of file unified_spell.cpp.
|
inlinenodiscardnoexcept |
Check if this spell is a composition of multiple spells.
Definition at line 135 of file spell_unified.hpp.
|
nodiscardnoexcept |
Check if this spell is the identity transformation.
Definition at line 70 of file unified_spell.cpp.
|
inlinenodiscardnoexcept |
RuneSequence rune_caster::Spell::operator() | ( | const RuneSequence & | input | ) | const |
Apply the spell transformation.
input | The input sequence to transform |
Definition at line 39 of file unified_spell.cpp.
std::string rune_caster::Spell::operator() | ( | std::string_view | utf8_input | ) | const |
Apply the spell to a UTF-8 string.
utf8_input | The UTF-8 input string |
Definition at line 43 of file unified_spell.cpp.
Compose with another spell (pipeline operator)
next | The next spell in the pipeline |
Definition at line 51 of file unified_spell.cpp.
RuneSequence rune_caster::Spell::test | ( | const RuneSequence & | test_input | ) | const |
Test the spell with sample input.
test_input | Sample input for testing |
Definition at line 88 of file unified_spell.cpp.
|
nodiscard |
Get a detailed string representation.
Definition at line 76 of file unified_spell.cpp.