Skip to main content

src/TransformsV2/PipelineValueStore/PipelineValueStore.hpp

src/TransformsV2/PipelineValueStore/PipelineValueStore.hpp

Runtime key-value store for pipeline intermediate values. More…

Namespaces

Name
Neuralyzer
Neuralyzer::Transforms
Neuralyzer::Transforms::V2

Classes

Name
class Neuralyzer::Transforms::V2::PipelineValueStore
Runtime key-value store for pipeline intermediate values.

Detailed Description

Runtime key-value store for pipeline intermediate values.

The PipelineValueStore provides a generic mechanism for storing named scalar values that can be bound to transform parameters. This enables composable pipelines where reduction outputs can be wired into transform parameters via JSON configuration.

Design Principles

  1. Type-safe storage - Values are stored with their original type
  2. JSON interchange - All values can be serialized as JSON fragments for reflect-cpp binding
  3. Simple flat namespace - Keys are plain strings without hierarchy
  4. Immutable semantics - Values are set once and read many times

Typical Usage Flow

┌─────────────────────────────────────────────────────────────────┐
│                    PipelineValueStore                           │
│  ┌─────────────────────────────────────────────────────────┐   │
│  │  "mean" → 0.5f, "std" → 0.1f, "alignment_time" → 100   │   │
│  └─────────────────────────────────────────────────────────┘   │
│        ↑                              ↓                         │
│   Range Reductions               Param Bindings                 │
│   (compute scalars)          (inject into params)               │
└─────────────────────────────────────────────────────────────────┘

Example


PipelineValueStore store;

// Reductions populate the store
store.set("computed_mean", 0.5f);
store.set("computed_std", 0.1f);
store.set("alignment_time", int64_t{1000});

// Later, bindings read from the store
auto mean_json = store.getJson("computed_mean");  // "0.5"
auto mean_val = store.getFloat("computed_mean");  // 0.5f

ParameterBinding.hpp for applying store values to parameters

TransformPipeline for integration with pipeline execution

Source code

#ifndef NEURALYZER_V2_PIPELINE_VALUE_STORE_HPP
#define NEURALYZER_V2_PIPELINE_VALUE_STORE_HPP


#include "TimeFrame/ClockTicks.hpp"

#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <variant>
#include <vector>

namespace Neuralyzer::Transforms::V2 {

// ============================================================================
// Supported Value Types
// ============================================================================

using PipelineValue = std::variant<float, int64_t, std::string, ClockTicks>;

// ============================================================================
// PipelineValueStore Implementation
// ============================================================================

class PipelineValueStore {
public:
    PipelineValueStore() = default;

    // ========================================================================
    // Type-safe Setters
    // ========================================================================

    void set(std::string const & key, float value) {
        values_[key] = value;
    }

    void set(std::string const & key, int value) {
        values_[key] = static_cast<int64_t>(value);
    }

    void set(std::string const & key, int64_t value) {
        values_[key] = value;
    }

    void set(std::string const & key, ClockTicks value) {
        values_[key] = value;
    }

    void set(std::string const & key, std::string value) {
        values_[key] = std::move(value);
    }

    // ========================================================================
    // JSON Accessors (for parameter binding)
    // ========================================================================

    [[nodiscard]] std::optional<std::string> getJson(std::string const & key) const;

    // ========================================================================
    // Typed Getters (for direct access)
    // ========================================================================

    [[nodiscard]] std::optional<float> getFloat(std::string const & key) const;

    [[nodiscard]] std::optional<int64_t> getInt(std::string const & key) const;

    [[nodiscard]] std::optional<std::string> getString(std::string const & key) const;

    [[nodiscard]] std::optional<ClockTicks> getClockTicks(std::string const & key) const;
    [[nodiscard]] std::optional<PipelineValue> get(std::string const & key) const {
        auto it = values_.find(key);
        if (it == values_.end()) {
            return std::nullopt;
        }
        return it->second;
    }

    // ========================================================================
    // Query Methods
    // ========================================================================

    [[nodiscard]] bool contains(std::string const & key) const {
        return values_.find(key) != values_.end();
    }

    [[nodiscard]] size_t size() const noexcept {
        return values_.size();
    }

    [[nodiscard]] bool empty() const noexcept {
        return values_.empty();
    }

    [[nodiscard]] std::vector<std::string> keys() const {
        std::vector<std::string> result;
        result.reserve(values_.size());
        for (auto const & [key, _]: values_) {
            result.push_back(key);
        }
        return result;
    }

    // ========================================================================
    // Mutation Methods
    // ========================================================================

    void merge(PipelineValueStore const & other) {
        for (auto const & [key, value]: other.values_) {
            values_[key] = value;
        }
    }

    bool erase(std::string const & key) {
        return values_.erase(key) > 0;
    }

    void clear() noexcept {
        values_.clear();
    }

private:
    std::unordered_map<std::string, PipelineValue> values_;
};

}// namespace Neuralyzer::Transforms::V2

#endif// NEURALYZER_V2_PIPELINE_VALUE_STORE_HPP

Updated on 2026-11-13 at 20:25:44 +0000