Operator Types and Factory#

class IService#

IService interface for Operator.

The IService object will be created before any operator initialize and passed to the operator to provide all required data or save data for init.

Public Functions

virtual bool context_exists() const = 0#

Check if previous context exists or not.

Returns:

true if previous context exists.

Returns:

false if previous context not exists.

virtual visionflow::Buffer load_context() const = 0#

Get Context saved after the previous execution, which will be empty if it’s the first execution or the previous execution has not saved any context. You can call context_exists() to check if context exists before get it.

Returns:

visionflow::Buffer The context buffer saved after the previous execution.

virtual void save_context(const Buffer &context) = 0#

Save current Operator context.

After the Operator process success, you can call this method to save current context which maybe useful for the next execution.

Parameters:

context – The current Operator context.

inline virtual std::shared_ptr<IScriptStdSink> get_script_sink()#

Get the script sink.

Returns:

std::shared_ptr<IScriptStdSink>

class IOperator#

IOperator Interface for Operator.

An Operator is a data processing unit which can be initialized with list of predefined parameters and can generate list of output properties with specific types for each list of input properties of specific types.

Public Types

using PropList = std::vector<std::shared_ptr<props::IProperty>>#

Vector of props::IProperty’s shared pointer.

using ParamList = std::vector<std::shared_ptr<param::IParameter>>#

Vector of param::IParameter’s shared pointer.

Public Functions

IOperator &set_ids(ToolNodeId self_id, std::vector<ToolNodeId> input_ids, std::vector<ToolNodeId> output_ids)#

Set the input and output properties ids.

Parameters:
  • self_id – The operator id.

  • input_ids – The input properties ids.

  • output_ids – The output properties ids.

const ToolNodeId &oper_id() const#

Get the operator id.

Returns:

ToolNodeId The id of the operator.

const std::vector<ToolNodeId> &input_prop_ids() const#

Get the input properties ids.

Returns:

NO_DISCARD input properties ids.

const std::vector<ToolNodeId> &output_prop_ids() const#

Get the output properties ids.

Returns:

NO_DISCARD output properties ids.

virtual void initialize(const ParamList &param)#

Interface to initialize the operator with the given parameters. The derived class should implement this method initialize(or initialize

(param, service)) to initialize the operator.

Parameters:

param – List of parameters, all should be derived from param::IParameter.

virtual void initialize(const ParamList &param, IService &service)#

Interface to initialize the operator with the given parameters and service. The derived class should implement this method(or

initialize(param)) to initialize the operator.

Parameters:
  • param – List of parameters, all should be derived from param::IParameter.

  • service – Help to save data or load data to accelerate initialize.

void initialize_with_service(const ParamList &param, IService *service = nullptr)#

Interface to initialize the operator with the given parameters and service. it recommend to using this function to init operator instead of initialize.

Parameters:
  • param – List of parameters, all should be derived from param::IParameter.

  • service – Help to save data or load data to accelerate initialize.

virtual void execute(ISample &sample) const#

Execute the operator with given sample. By default it dispatches properties to overloaded functions that use a list of properties as arguments.

Parameters:

sample[inout] The sample contains the input and output properties.

virtual void execute(const PropList &inputs, PropList outputs) const#

Initialize the operator with the given properties and generate the output properties. This function is called after the operator is initialized.

Parameters:
  • inputs[in] List of input properties. All properties in the input list is readonly.

  • outputs[out] List of output properties. All output properties are allocated by the caller in advance. The implementer of the Operator can no longer modify the address of the property object in the execute phase, nor can it delete or add a property object, but can only modify the value of each property object.

template<typename OperatorType>
inline const OperatorType &as() const#

Convert the operator into its derived type. Caller should make sure the type is correct. or std::bad_cast will be thrown.

Template Parameters:

OperatorType – The derived class of IOperator.

Returns:

const OperatorType& The derived type of the operator.

class Factory : public visionflow::detail::Factory<Meta, IOperator>, public visionflow::detail::CreatorMutableMixin<Meta, Creator>#
struct Meta#

Operator Meta info.

using visionflow::opers::Creator = std::function<std::shared_ptr<IOperator>()>#

Operator creator.