runtime 1.1.4
Checked CEL programs, owned values, and reusable execution stacks
Loading...
Searching...
No Matches
cel::value Class Reference

Holds any type representable by CEL, including client-defined types. More...

#include <cel/runtime/value.hpp>

Public Member Functions

 value () noexcept
 Creates the unit value () without allocating.
 ~value ()
 Destroys owned children and releases storage without allocating.
 value (const value &other)
 Copies the source under the class's aggregate and callable copy semantics.
 value (value &&other) noexcept
 Transfers ownership and leaves other as source unit.
value & operator= (const value &other)
 Replaces this value with a copy under the class's aggregate and callable copy semantics.
value & operator= (value &&other) noexcept
 Releases old ownership, transfers other, and leaves other as unit; self-move is unchanged.
const value_type & type () const
 Borrows the complete descriptor until this value is assigned or destroyed.
template<class T>
T as () const
 Returns a concrete copy of the exact requested adapter, leaf, vector, or tuple type.
std::size_t size () const
 Returns array length, fixed aggregate arity, or range endpoint count.
value at (std::size_t index) const
 Copies a source-order child under the class's aggregate and callable copy semantics.
void set (std::size_t index, const value &replacement)
 Replaces one child with a copy of the exact expected shape and ownership operations.
value field (std::string_view name) const
 Copies a named record field under the class's copy semantics.
void set_field (std::string_view name, const value &replacement)
 Replaces a named record field with a copy of the exact expected shape.

Static Public Member Functions

template<class T>
static value from (const T &source)
 Copies a concrete leaf, nominal record adapter, or nested owning vector/tuple value.
static value array (value_type element, std::span< const value > elements)
 Copies a sequence of elements with the specified complete shape and ownership operations.
static value tuple (std::span< const value > fields)
 Copies source-order fields into a canonical tuple; empty fields are source unit.
static value record (value_type type, std::span< const value > fields)
 Copies source-order fields into a record of the specified nominal type.
static value range (value_type type, std::span< const value > endpoints)
 Copies endpoints in source order for the given range descriptor.

Friends

struct detail::value_access
template<class T>
struct detail::concrete_adapter
template<class T>
struct detail::boundary_adapter

Detailed Description

Holds any type representable by CEL, including client-defined types.

Value area includes canonical bytes, logical elements even when zero-sized, and owned runtime objects. Released area also includes executable and type metadata: nodes, edges, and stored names. Owned result storage includes owner records, not just byte buffers. Held client types retain their own copy and destruction costs.

Checked operations additionally compare distinct expected/actual descriptor pairs. Across one operation, this costs expected O(P + E + S) time and O(P + E) auxiliary space for compared pairs P, their edges E, and compared identity/name bytes S. This need not be linear in the separate descriptor graph areas.

Copies share immutable ownership plans with metadata linear in descriptor edges. Canonical cloning and retirement use constant runtime auxiliary space and no traversal allocations beyond cloned result owners. Native adapters may use call space proportional to concrete nesting; held client operations retain their own space requirements.

Example: auto number = value::from(2.0); auto copy = number;.

Create a record and change a copied field without changing the original:

const auto fields =
std::array{cel::record_field{"enabled", cel::native_type<bool>()}};
const auto schema = cel::value_type::record("settings", fields);
auto original =
cel::value::record(schema, std::array{cel::value::from(false)});
auto copy = original;
copy.set_field("enabled", cel::value::from(true));
auto enabled = copy.field("enabled").as<bool>(); // true.
// original.field("enabled").as<bool>() remains false.
static value_type record(std::string_view identity, std::span< const record_field > fields)
Creates named fields with a nonempty nominal identity.
static value from(const T &source)
Copies a concrete leaf, nominal record adapter, or nested owning vector/tuple value.
Definition value.hpp:229
static value record(value_type type, std::span< const value > fields)
Copies source-order fields into a record of the specified nominal type.
void set_field(std::string_view name, const value &replacement)
Replaces a named record field with a copy of the exact expected shape.
value_type native_type()
Returns the runtime's complete descriptor for a trusted native value type.
Definition value.hpp:635
A source-order name/type pair validated by value_type::record.
Definition value_type.hpp:272

Constructor & Destructor Documentation

◆ value() [1/3]

cel::value::value ( )
noexcept

Creates the unit value () without allocating.

Example: value unit;.

◆ ~value()

cel::value::~value ( )

Destroys owned children and releases storage without allocating.

Runtime retirement uses no nesting-dependent call space; client capture destructors retain their own costs and behavior. Complexity: linear in released area; O(1) runtime auxiliary space.

See the class's shared copying example.

◆ value() [2/3]

cel::value::value ( const value & other)

Copies the source under the class's aggregate and callable copy semantics.

Leaves the source unchanged; failure releases every acquired owner. Complexity: linear in source area, with new owned result storage and O(1) runtime auxiliary space excluding opaque operations.

See the class's shared copying example.

◆ value() [3/3]

cel::value::value ( value && other)
noexcept

Transfers ownership and leaves other as source unit.

Example: auto owner = std::move(source); // source is unit.

Member Function Documentation

◆ array()

value cel::value::array ( value_type element,
std::span< const value > elements )
static

Copies a sequence of elements with the specified complete shape and ownership operations.

Retains element for an empty sequence; leaves all input values unchanged.

Throws std::invalid_argument for incompatible elements, releasing earlier copies. Throws std::overflow_error if count times canonical element extent overflows. Complexity: linear in combined element area and element count, plus the class's checked-comparison costs across the entire construction; owned result storage.

Example: auto empty = value::array(value_type::leaf<double>(), {});.

◆ as()

template<class T>
T cel::value::as ( ) const
inline

Returns a concrete copy of the exact requested adapter, leaf, vector, or tuple type.

Returned vectors and tuples own independent mutable payloads; leaf pointers remain pointers.

Throws std::invalid_argument if the complete concrete type does not match. Complexity: linear in result area, plus same_shape comparison and first-use native_type construction; owned result storage. Comparison auxiliary space and O(concrete nesting depth) adapter call space are additional.

Example: value::from(2.0).as<double>() == 2.0.

◆ at()

value cel::value::at ( std::size_t index) const

Copies a source-order child under the class's aggregate and callable copy semantics.

Leaves this value unchanged, including on failure.

Throws std::out_of_range for an invalid index, std::invalid_argument for non-composites. Complexity: linear in child area, with owned result storage and O(1) runtime auxiliary space excluding opaque operations.

Example: value::from(std::vector<double>{2.0}).at(0).as<double>() == 2.0.

◆ field()

value cel::value::field ( std::string_view name) const

Copies a named record field under the class's copy semantics.

Leaves this value unchanged, including on failure. Throws std::invalid_argument for a non-record or missing name. Complexity: linear field-name lookup, including compared name bytes, plus linear child-area copying time and child result storage; O(1) runtime auxiliary space excluding opaque operations.

See the class example for a complete record and field lookup.

◆ from()

template<class T>
value cel::value::from ( const T & source)
inlinestatic

Copies a concrete leaf, nominal record adapter, or nested owning vector/tuple value.

Leaves source unchanged; pointer members in opaque leaves do not confer pointee ownership. Complexity: linear in source area, plus first-use native_type construction; owned result storage; O(concrete nesting depth) adapter call space.

Example: auto numbers = value::from(std::vector<double>{1.0, 2.0});.

Examples
getting_started.cpp.

◆ operator=() [1/2]

value & cel::value::operator= ( const value & other)

Replaces this value with a copy under the class's aggregate and callable copy semantics.

Leaves other unchanged; self-assignment leaves this value unchanged. Failure leaves this unchanged without copying its prior payload. Complexity: linear in source and released area, with new source-sized result storage; runtime auxiliary space is O(1), excluding opaque operations.

Example: auto target = value{}; target = source;.

◆ operator=() [2/2]

value & cel::value::operator= ( value && other)
noexcept

Releases old ownership, transfers other, and leaves other as unit; self-move is unchanged.

Complexity: linear in released area; O(1) runtime auxiliary space.

Example: auto target = value{}; target = std::move(source); // source is unit.

◆ range()

value cel::value::range ( value_type type,
std::span< const value > endpoints )
static

Copies endpoints in source order for the given range descriptor.

Leaves inputs unchanged.

Throws std::invalid_argument for a non-range, wrong arity, or incompatible endpoint type. Complexity: O(endpoint byte size) time and result storage.

Example: auto full = value::range(value_type::range( range_kind::range_full, value_type::leaf<double>()), {});.

◆ record()

value cel::value::record ( value_type type,
std::span< const value > fields )
static

Copies source-order fields into a record of the specified nominal type.

Leaves inputs unchanged, with the class's copy semantics for every component.

Throws std::invalid_argument for a non-record, wrong arity, or incompatible fields. Field compatibility includes complete shape and ownership operations. Failure releases earlier children without leaking resources. Complexity: linear in combined field area and field count, plus the class's checked-comparison costs across all fields; owned result storage.

Example: auto empty = value::record(value_type::record("sample", {}), {});.

◆ set()

void cel::value::set ( std::size_t index,
const value & replacement )

Replaces one child with a copy of the exact expected shape and ownership operations.

Leaves replacement unchanged; callable children retain reference-semantic code.

Throws std::out_of_range for invalid index, std::invalid_argument for shape mismatch or non-composites. Failure leaves the value unchanged; no rollback copy is needed. Complexity: linear in replaced and replacement child area, plus the class's checked-comparison costs; new child result storage.

Example: auto a = value::from(std::vector<double>{1.0}); a.set(0, value::from(2.0));.

◆ set_field()

void cel::value::set_field ( std::string_view name,
const value & replacement )

Replaces a named record field with a copy of the exact expected shape.

Throws std::invalid_argument for non-record/missing name or shape mismatch. Follows set's ownership compatibility, copy semantics, and unchanged-on-failure guarantee. Complexity: linear field-name lookup, including compared name bytes, plus replacement work in old/new child area and the class's checked-comparison costs; new child result storage.

See the class example for a complete record and field replacement.

◆ size()

std::size_t cel::value::size ( ) const

Returns array length, fixed aggregate arity, or range endpoint count.

Throws std::invalid_argument for leaves or callables.

Example: value::tuple({}).size() == 0.

◆ tuple()

value cel::value::tuple ( std::span< const value > fields)
static

Copies source-order fields into a canonical tuple; empty fields are source unit.

Leaves input fields unchanged, with the class's copy semantics for every component.

Throws std::overflow_error for layout overflow. Complexity: linear in combined field area and field count; owned result storage and O(field count) temporary descriptor space, in addition to opaque operation costs.

Example: auto unit = value::tuple({});.

◆ type()

const value_type & cel::value::type ( ) const

Borrows the complete descriptor until this value is assigned or destroyed.

The first descriptor query on a default/moved-from value may allocate unit metadata.

Example: value::from(true).type().kind() == type_kind::leaf.


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