Skip to main content

commands

commands

Classes

Name
struct commands::AdvanceFrameParams
class commands::AdvanceFrame
Advances (or rewinds) the current [TimePosition](/api_generated/Classes/structTimePosition.md) on [CommandContext::time_controller]().
struct commands::CopyByTimeRangeParams
class commands::CopyByTimeRange
struct commands::CommandContext
Runtime context provided to every command at execution time.
struct commands::CommandDescriptor
A single command invocation as it appears in a JSON file.
struct commands::CommandSequenceDescriptor
A sequence of commands, optionally with template variables.
struct commands::CommandInfo
Static metadata describing a registered command.
class commands::CommandRecorder
Records CommandDescriptors during sequence execution for replay, golden trace tests, and eventual integration into the Action Journal (Phase 4).
class commands::CommandRegistry
Singleton registry mapping command name strings to creator functions and metadata.
struct commands::CommandResult
Result of executing a command.
class commands::ICommand
Base class for all commands operating on DataManager.
struct commands::SequenceResult
Result of executing a command sequence.
struct commands::ValidationResult
Result of validating a command sequence before execution.
struct commands::AddIntervalParams
class commands::AddInterval
struct commands::FlipEventAtTimeParams
Parameters for [FlipEventAtTime]() (JSON field [data_key](), [time]()).
class commands::FlipEventAtTime
Toggles interval membership at time using hasIntervalAtTime then setEventAtTime with the negated value.
struct commands::SetEventAtTimeParams
Parameters for [SetEventAtTime]() (JSON field [data_key](), [time](), [event]()).
class commands::SetEventAtTime
Sets [DigitalIntervalSeries::setEventAtTime](/api_generated/Classes/classDigitalIntervalSeries.md#function-seteventattime) for one frame (event true adds a one-frame interval; false removes coverage at that time).
struct commands::ClearLineDataAtTimeParams
Parameters for [ClearLineDataAtTime]() (JSON fields [data_key](), [time]()).
class commands::ClearLineDataAtTime
Removes all [LineData](/api_generated/Classes/classLineData.md) entries at one frame via [LineData::clearAtTime](/api_generated/Classes/classRaggedTimeSeries.md#function-clearattime).
struct commands::ForEachKeyParams
class commands::ForEachKey
struct commands::LoadDataParams
class commands::LoadData
struct commands::SaveDataParams
class commands::SaveData
struct commands::SavePathResolution
Resolved save target for a data key.
struct commands::MultiFileSavePathResolution
Resolved multi-file save directory for a data key.
struct commands::MoveByTimeRangeParams
class commands::MoveByTimeRange
struct commands::UpsampleTimeFrameParams
Parameters for [UpsampleTimeFrame]().
class commands::UpsampleTimeFrame
Creates a new TimeFrame by upsampling an existing one.
class commands::CommandGuard
RAII guard that sets the inside-command flag for its lifetime.
struct commands::SynthesizeDataParams
class commands::SynthesizeData
struct commands::RunTransformsV2PipelineParams
Parameters for [RunTransformsV2Pipeline]().
class commands::RunTransformsV2Pipeline
Runs a saved TransformsV2 pipeline on an entire DataManager data object.
struct commands::RunTransformsV2PipelineAtTimeParams
Parameters for [RunTransformsV2PipelineAtTime]().
class commands::RunTransformsV2PipelineAtTime
Runs a saved TransformsV2 pipeline on one frame.

Types

Name
using std::function< std::unique_ptr< ICommand >(std::string const &)> CommandCreator
Type-erased command creator.

Functions

Name
bool isKnownCommandName(std::string const & name)
Check if a command name is recognized by the factory.
std::unique_ptr< ICommand > createCommand(std::string const & name, rfl::Generic const & params)
Create a command from a descriptor’s name and rfl::Generic parameters.
std::unique_ptr< ICommand > createCommandFromJson(std::string const & name, std::string const & params_json)
Create a command from a name and a pre-built JSON parameter string.
std::vector< CommandInfo > getAvailableCommands()
Return metadata for all registered commands.
std::optional< CommandInfo > getCommandInfo(std::string const & name)
Return metadata for a single command by name.
template <typename CommandT ,typename Params >
void
registerTypedCommand(CommandRegistry & reg, std::string name, CommandInfo info)
Convenience helper to register a command with automatic JSON deserialization and ParameterSchema extraction.
SequenceResult executeSequence(CommandSequenceDescriptor const & seq, CommandContext const & ctx, bool stop_on_error =true, CommandRecorder * recorder =[nullptr])
Execute a sequence of command descriptors.
CommandResult executeSingleCommand(std::string const & command_name, std::string const & params_json, CommandContext const & ctx)
Execute a single command through the sequence execution pipeline.
std::vector< std::string > findUnresolvedVariables(std::string const & input)
Find all unresolved ${variable} references in a string.
ValidationResult validateSequence(CommandSequenceDescriptor const & seq, CommandContext const & ctx)
Validate a command sequence without executing it.
std::string substituteVariables(std::string const & input, std::map< std::string, std::string > const & variables)
Replace all ${variable_name} patterns in a string with values from variables.
std::string normalizeJsonNumbers(std::string const & json)
Normalize whole-number floating-point values in a JSON string to integers.
std::unordered_set< EntityId > getEntityIdsInRange(DigitalEventSeries const & data, TimeFrameIndex start, TimeFrameIndex end)
Collect EntityIds in [start, end] from a DigitalEventSeries using view().
std::unordered_set< EntityId > getEntityIdsInRange(DigitalIntervalSeries const & data, TimeFrameIndex start, TimeFrameIndex end)
Collect EntityIds of intervals overlapping [start, end] from a DigitalIntervalSeries.
template <typename RaggedT >
std::unordered_set< EntityId >
getEntityIdsInRange(RaggedT const & data, TimeFrameIndex start, TimeFrameIndex end)
Collect EntityIds in [start, end] from a RaggedTimeSeries type (LineData, PointData, MaskData) using flattened_data().
SavePathResolution resolveDefaultSavePath(DataManager const & data_manager, std::string const & data_key, std::string const & requested_format, std::string const & fallback_filename)
Resolve the default single-file save path for a data key.
MultiFileSavePathResolution resolveDefaultMultiFileSaveDir(DataManager const & data_manager, std::string const & data_key, std::string const & requested_format, std::string const & fallback_parent_dir)
Resolve the default multi-file save directory for a data key.
void register_core_commands()
Register all built-in commands with the CommandRegistry singleton.
bool isInsideCommand()
Returns true when the current thread is inside a command’s execute() call.
void warnIfOutsideCommand(char const * method_name)
Check whether a DataManager mutation is happening outside a command scope.
std::optional< TimeKey > resolvePipelineOutputTimeKey(DataManager & dm, std::string const & input_key, std::string const & output_time_key, std::string_view command_prefix, std::string & error_message)
Resolve the TimeKey to use when storing pipeline output.
std::optional< std::string > storePipelineOutputMerged(DataManager & dm, std::string const & input_key, std::string const & output_key, DataTypeVariant const & output, std::string_view command_prefix)
Store pipeline output into output_key, merging when supported.
std::optional< std::string > storePipelineOutputReplace(DataManager & dm, std::string const & output_key, DataTypeVariant const & output, TimeKey const & time_key, std::string_view command_prefix)
Store pipeline output into output_key, replacing any existing object.

Types Documentation

using CommandCreator

using commands::CommandCreator =  std::function<std::unique_ptr<ICommand>(std::string const &)>;

Type-erased command creator.

Parameters:

  • params_json Normalized JSON parameter string for the command.

Return: A new command instance, or nullptr if deserialization fails.

Takes a normalized JSON parameter string and returns an owned command instance.

Functions Documentation

function isKnownCommandName

bool isKnownCommandName(
    std::string const & name
)

Check if a command name is recognized by the factory.

Parameters:

  • name Command name to query.

Return: True if name is registered in CommandRegistry.

Returns true for all command names that createCommand() can instantiate.

function createCommand

std::unique_ptr< ICommand > createCommand(
    std::string const & name,
    rfl::Generic const & params
)

Create a command from a descriptor’s name and rfl::Generic parameters.

Parameters:

  • name Registered command name.
  • params Command parameters as a generic JSON value.

Return: The constructed command, or nullptr if name is unknown or params fail to parse.

Delegates to createCommandFromJson() after serializing and normalizing the JSON.

function createCommandFromJson

std::unique_ptr< ICommand > createCommandFromJson(
    std::string const & name,
    std::string const & params_json
)

Create a command from a name and a pre-built JSON parameter string.

Parameters:

  • name Registered command name.
  • params_json JSON parameter string for the command.

Return: The constructed command, or nullptr if name is unknown or params_json fails to parse.

Applies integer normalization to handle the rfl::Generic round-trip issue (whole-number doubles like 10.0 are converted to 10 before deserialization). Prefer this overload when a JSON string is already available to avoid an unnecessary rfl::Generic round-trip.

function getAvailableCommands

std::vector< CommandInfo > getAvailableCommands()

Return metadata for all registered commands.

Return: Vector of CommandInfo for every registered command.

Each entry includes the command’s name, description, category, undo support flag, supported data types, and a ParameterSchema generated via extractParameterSchema().

function getCommandInfo

std::optional< CommandInfo > getCommandInfo(
    std::string const & name
)

Return metadata for a single command by name.

Parameters:

  • name Registered command name to look up.

Return: The CommandInfo for name, or std::nullopt if the name is not recognized.

function registerTypedCommand

template <typename CommandT ,
typename Params >
void registerTypedCommand(
    CommandRegistry & reg,
    std::string name,
    CommandInfo info
)

Convenience helper to register a command with automatic JSON deserialization and ParameterSchema extraction.

Parameters:

  • reg The registry to register into.
  • name Command name string (must match CommandT::commandName()).
  • info Metadata — parameter_schema will be overwritten.

Template Parameters:

  • CommandT Concrete ICommand subclass (must accept Params in its constructor).
  • Params reflect-cpp–annotated parameter struct.

The creator function deserializes the JSON string into Params via rfl::json::read<Params, rfl::DefaultIfMissing>, applying C++ default member initializers for omitted JSON fields (same pattern as TransformsV2 and DataSynthesizer). The parameter_schema field of info is automatically populated via extractParameterSchema().

function executeSequence

SequenceResult executeSequence(
    CommandSequenceDescriptor const & seq,
    CommandContext const & ctx,
    bool stop_on_error =true,
    CommandRecorder * recorder =nullptr
)

Execute a sequence of command descriptors.

Parameters:

  • seq The command sequence descriptor (JSON-deserialized).
  • ctx Runtime context with DataManager and runtime variables.
  • stop_on_error If true, stop on the first command failure (default: true).
  • recorder Optional CommandRecorder to record each successfully executed command’s descriptor. Pass nullptr (default) to disable recording. Falls back to ctx.recorder when nullptr.

Return: SequenceResult containing the overall result, executed commands, and failure index.

Applies two-pass variable substitution:

  1. Static pass from CommandSequenceDescriptor::variables
  2. Runtime pass from CommandContext::runtime_variables

Then creates and executes each command in order.

function executeSingleCommand

CommandResult executeSingleCommand(
    std::string const & command_name,
    std::string const & params_json,
    CommandContext const & ctx
)

Execute a single command through the sequence execution pipeline.

Parameters:

  • command_name The command factory name (e.g., “SaveData”, “SynthesizeData”).
  • params_json JSON-serialized command parameters.
  • ctx Runtime context with DataManager, runtime variables, and optional recorder.

Return: CommandResult indicating success or failure.

Convenience wrapper that routes a single command through executeSequence(), enabling recording (via ctx.recorder) and MutationGuard support.

function findUnresolvedVariables

std::vector< std::string > findUnresolvedVariables(
    std::string const & input
)

Find all unresolved ${variable} references in a string.

Parameters:

  • input String potentially containing ${variable} references.

Return: Variable names for each ${…} pattern found in input.

Returns the variable names (without the ${} delimiters) for each reference that remains in the string.

function validateSequence

ValidationResult validateSequence(
    CommandSequenceDescriptor const & seq,
    CommandContext const & ctx
)

Validate a command sequence without executing it.

Parameters:

  • seq The command sequence descriptor to validate.
  • ctx Runtime context (for variable resolution and optional DataManager).

Return: ValidationResult with any errors and warnings found.

Performs five checks in order of increasing specificity:

  1. Structural: all command_name values map to known commands in the factory
  2. Deserialization: parameters deserialize into expected param structs
  3. Variable resolution: all ${variable} references resolve
  4. Data key existence (optional, requires DataManager): referenced keys exist
  5. Type compatibility (optional, requires DataManager): move/copy source and destination resolve to the same DataTypeVariant alternative

Checks 1–3 run without a DataManager. Checks 4–5 only run when ctx.data_manager is non-null.

function substituteVariables

std::string substituteVariables(
    std::string const & input,
    std::map< std::string, std::string > const & variables
)

Replace all ${variable_name} patterns in a string with values from variables.

Parameters:

  • input The string potentially containing ${variable} references.
  • variables Map of variable names to their replacement values.

Return: The string with all resolved variables substituted.

Unresolved variables are left as-is. When a substitution appears inside a JSON string literal and the replacement value is a JSON number, boolean, or null, surrounding quotes are stripped so the substituted value preserves JSON typing.

function normalizeJsonNumbers

std::string normalizeJsonNumbers(
    std::string const & json
)

Normalize whole-number floating-point values in a JSON string to integers.

Parameters:

  • json JSON string to normalize.

Return: A copy of json with whole-number floats rewritten as integers.

Converts values like 10.0 to 10 while leaving 10.5 and strings untouched. This fixes an rfl::Generic round-trip issue where integers become doubles after rfl::json::write(Generic) → rfl::json::read<Generic>, producing values like 10.0 that fail to deserialize into int64_t fields.

function getEntityIdsInRange

std::unordered_set< EntityId > getEntityIdsInRange(
    DigitalEventSeries const & data,
    TimeFrameIndex start,
    TimeFrameIndex end
)

Collect EntityIds in [start, end] from a DigitalEventSeries using view().

function getEntityIdsInRange

std::unordered_set< EntityId > getEntityIdsInRange(
    DigitalIntervalSeries const & data,
    TimeFrameIndex start,
    TimeFrameIndex end
)

Collect EntityIds of intervals overlapping [start, end] from a DigitalIntervalSeries.

function getEntityIdsInRange

template <typename RaggedT >
std::unordered_set< EntityId > getEntityIdsInRange(
    RaggedT const & data,
    TimeFrameIndex start,
    TimeFrameIndex end
)

Collect EntityIds in [start, end] from a RaggedTimeSeries type (LineData, PointData, MaskData) using flattened_data().

function resolveDefaultSavePath

SavePathResolution resolveDefaultSavePath(
    DataManager const & data_manager,
    std::string const & data_key,
    std::string const & requested_format,
    std::string const & fallback_filename
)

Resolve the default single-file save path for a data key.

Parameters:

  • data_manager DataManager that owns data and lineage state.
  • data_key Key of the data object being saved.
  • requested_format Saver format requested by the UI/command.
  • fallback_filename Filename to use when no matching file origin exists.

Return: Resolved path components and whether provenance was used.

Postcondition: data_manager is not modified.

The resolver prefers a matching file-origin record, then falls back to the DataManager output directory plus fallback_filename.

function resolveDefaultMultiFileSaveDir

MultiFileSavePathResolution resolveDefaultMultiFileSaveDir(
    DataManager const & data_manager,
    std::string const & data_key,
    std::string const & requested_format,
    std::string const & fallback_parent_dir
)

Resolve the default multi-file save directory for a data key.

Parameters:

  • data_manager DataManager that owns data and lineage state.
  • data_key Key of the data object being saved.
  • requested_format Saver format requested by the UI/command.
  • fallback_parent_dir Directory name to use when no matching origin exists.

Return: Resolved parent directory and whether provenance was used.

Postcondition: data_manager is not modified.

The resolver prefers a matching file-origin record whose load config indicates multi-file mode or whose path is an existing directory, then falls back to the DataManager output directory joined with fallback_parent_dir.

function register_core_commands

void register_core_commands()

Register all built-in commands with the CommandRegistry singleton.

Must be called once at startup before any command creation or introspection. Safe to call multiple times (subsequent calls are no-ops).

function isInsideCommand

bool isInsideCommand()

Returns true when the current thread is inside a command’s execute() call.

function warnIfOutsideCommand

void warnIfOutsideCommand(
    char const * method_name
)

Check whether a DataManager mutation is happening outside a command scope.

Parameters:

  • method_name Name of the DataManager method being called (for the warning message)

Call this from DataManager mutating methods in debug builds. Prints a warning to stderr if the mutation is not inside a command.

function resolvePipelineOutputTimeKey

std::optional< TimeKey > resolvePipelineOutputTimeKey(
    DataManager & dm,
    std::string const & input_key,
    std::string const & output_time_key,
    std::string_view command_prefix,
    std::string & error_message
)

Resolve the TimeKey to use when storing pipeline output.

Parameters:

  • input_key DataManager key used as input to the pipeline
  • output_time_key When non-empty, must name an existing TimeFrame in dm
  • command_prefix Prefix for error messages (e.g. command name)
  • error_message Set on failure

Return: Resolved TimeKey on success, or empty on failure

Precondition: dm is non-null

function storePipelineOutputMerged

std::optional< std::string > storePipelineOutputMerged(
    DataManager & dm,
    std::string const & input_key,
    std::string const & output_key,
    DataTypeVariant const & output,
    std::string_view command_prefix
)

Store pipeline output into output_key, merging when supported.

Parameters:

  • command_prefix Prefix for error messages (e.g. command name)

Precondition: dm is non-null

Postcondition: On success, output_key exists with updated or merged data

Used by single-frame commands that accumulate results across repeated runs.

function storePipelineOutputReplace

std::optional< std::string > storePipelineOutputReplace(
    DataManager & dm,
    std::string const & output_key,
    DataTypeVariant const & output,
    TimeKey const & time_key,
    std::string_view command_prefix
)

Store pipeline output into output_key, replacing any existing object.

Parameters:

  • command_prefix Prefix for error messages (e.g. command name)

Precondition: dm is non-null

Postcondition: On success, output_key exists with replaced data bound to time_key

Used by full-dataset commands that mirror TransformsV2 widget semantics.


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