Class ComponentBase
Defined in File component.hpp
Derived Types
public holoscan::Component
(Class Component)public holoscan::Operator
(Class Operator)
-
class ComponentBase
Base class for all components.
This class is the base class for all components including
holoscan::Operator
,holoscan::Condition
, andholoscan::Resource
. It is used to define the common interface for all components.Subclassed by holoscan::Component, holoscan::Operator
Public Functions
-
ComponentBase() = default
-
template<typename ArgT, typename ...ArgsT, typename = std::enable_if_t<!std::is_base_of_v<::holoscan::ComponentBase, std::decay_t<ArgT>> && (std::is_same_v<::holoscan::Arg, std::decay_t<ArgT>> || std::is_same_v<::holoscan::ArgList, std::decay_t<ArgT>>)>>
inline explicit ComponentBase(ArgT &&arg, ArgsT&&... args) Construct a new Component object.
- Parameters
args – The arguments to be passed to the component.
-
virtual ~ComponentBase() = default
-
inline int64_t id() const
Get the identifier of the component.
By default, the identifier is set to -1. It is set to a valid value when the component is initialized.
With the default executor (GXFExecutor), the identifier is set to the GXF component ID.
- Returns
The identifier of the component.
-
inline const std::string &name() const
Get the name of the component.
- Returns
The name of the component.
-
inline Fragment *fragment()
Get a pointer to Fragment object.
- Returns
The Pointer to Fragment object.
-
inline void add_arg(const Arg &arg)
Add an argument to the component.
- Parameters
arg – The argument to add.
-
inline void add_arg(Arg &&arg)
Add an argument to the component.
- Parameters
arg – The argument to add.
-
inline void add_arg(const ArgList &arg)
Add a list of arguments to the component.
- Parameters
arg – The list of arguments to add.
-
inline void add_arg(ArgList &&arg)
Add a list of arguments to the component.
- Parameters
arg – The list of arguments to add.
-
inline std::vector<Arg> &args()
Get the list of arguments.
- Returns
The vector of arguments.
-
inline virtual void initialize()
Initialize the component.
This method is called only once when the component is created for the first time, and use of light-weight initialization.
-
virtual YAML::Node to_yaml_node() const
Get a YAML representation of the component.
- Returns
YAML node including the id, name, fragment name, and arguments of the component.
-
std::string description() const
Get a description of the component.
See also- Returns
YAML string.
Public Static Functions
-
template<typename typeT>
static inline void register_converter() Register the argument setter for the given type.
If an operator or resource has an argument with a custom type, the argument setter must be registered using this method.
The argument setter is used to set the value of the argument from the YAML configuration.
This method can be called in the initialization phase of the operator/resource (e.g.,
initialize()
). The example below shows how to register the argument setter for the custom type (Vec3
):void MyOp::initialize() { register_converter<Vec3>(); }
It is assumed that
YAML::convert<T>::encode
andYAML::convert<T>::decode
are implemented for the given type. You need to specialize theYAML::convert<>
template class.For example, suppose that you had a
Vec3
class with the following members:struct Vec3 { // make sure you have overloaded operator==() for the comparison double x, y, z; };
You can define the
YAML::convert<Vec3>
as follows in a ‘.cpp’ file:namespace YAML { template<> struct convert<Vec3> { static Node encode(const Vec3& rhs) { Node node; node.push_back(rhs.x); node.push_back(rhs.y); node.push_back(rhs.z); return node; } static bool decode(const Node& node, Vec3& rhs) { if(!node.IsSequence() || node.size() != 3) { return false; } rhs.x = node[0].as<double>(); rhs.y = node[1].as<double>(); rhs.z = node[2].as<double>(); return true; } }; }
Please refer to the yaml-cpp documentation for more details.
- Template Parameters
typeT – The type of the argument to register.
Protected Functions
-
void update_params_from_args(std::unordered_map<std::string, ParameterWrapper> ¶ms)
Update parameters based on the specified arguments.
-
virtual void reset_graph_entities()
Reset the GXF GraphEntity of any arguments that have one.
Protected Attributes
-
int64_t id_ = -1
The ID of the component.
-
std::string name_ = ""
Name of the component.
-
Fragment *fragment_ = nullptr
Pointer to the fragment that owns this component.
-
std::vector<Arg> args_
List of arguments.
Protected Static Functions
-
template<typename typeT>
static void register_argument_setter() Register the argument setter for the given type.
Please refer to the documentation of
register_converter()
for more details.- Template Parameters
typeT – The type of the argument to register.
Friends
- friend class holoscan::Executor
- friend class holoscan::gxf::GXFExecutor
- friend class holoscan::Fragment
-
ComponentBase() = default