Clara Holoscan v0.3.0
1.0

Program Listing for File operator.hpp

Return to documentation for file (include/holoscan/core/operator.hpp)

Copy
Copied!
            

/* * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HOLOSCAN_CORE_OPERATOR_HPP #define HOLOSCAN_CORE_OPERATOR_HPP #include "./common.hpp" #include <stdio.h> #include <iostream> #include <memory> #include <type_traits> #include "./arg.hpp" #include "./component.hpp" #include "./condition.hpp" #include "./forward_def.hpp" #include "./operator_spec.hpp" #include "./resource.hpp" #define HOLOSCAN_OPERATOR_FORWARD_TEMPLATE() \ template <typename ArgT, \ typename... ArgsT, \ typename = std::enable_if_t< \ !std::is_base_of_v<Operator, std::decay_t<ArgT>> && \ (std::is_same_v<Arg, std::decay_t<ArgT>> || \ std::is_same_v<ArgList, std::decay_t<ArgT>> || \ std::is_base_of_v<holoscan::Condition, \ typename holoscan::type_info<ArgT>::element_type> || \ std::is_base_of_v<holoscan::Resource, \ typename holoscan::type_info<ArgT>::element_type>)>> #define HOLOSCAN_OPERATOR_FORWARD_ARGS(class_name) \ HOLOSCAN_OPERATOR_FORWARD_TEMPLATE() \ class_name(ArgT&& arg, ArgsT&&... args) \ : Operator(std::forward<ArgT>(arg), std::forward<ArgsT>(args)...) {} #define HOLOSCAN_OPERATOR_FORWARD_ARGS_SUPER(class_name, super_class_name) \ HOLOSCAN_OPERATOR_FORWARD_TEMPLATE() \ class_name(ArgT&& arg, ArgsT&&... args) \ : super_class_name(std::forward<ArgT>(arg), std::forward<ArgsT>(args)...) {} namespace holoscan { class Operator : public Component { public: HOLOSCAN_OPERATOR_FORWARD_TEMPLATE() Operator(ArgT&& arg, ArgsT&&... args) { add_arg(std::forward<ArgT>(arg)); (add_arg(std::forward<ArgsT>(args)), ...); } Operator() = default; ~Operator() override = default; using Component::name; Operator& name(const std::string& name) { name_ = name; return *this; } using Component::fragment; Operator& fragment(Fragment* fragment) { fragment_ = fragment; return *this; } Operator& spec(std::unique_ptr<OperatorSpec> spec) { spec_ = std::move(spec); return *this; } OperatorSpec* spec() { return spec_.get(); } std::unordered_map<std::string, std::shared_ptr<Condition>>& conditions() { return conditions_; } std::unordered_map<std::string, std::shared_ptr<Resource>>& resources() { return resources_; } using Component::add_arg; void add_arg(const std::shared_ptr<Condition>& arg) { conditions_[arg->name()] = arg; } void add_arg(std::shared_ptr<Condition>&& arg) { conditions_[arg->name()] = std::move(arg); } void add_arg(const std::shared_ptr<Resource>& arg) { resources_[arg->name()] = arg; } void add_arg(std::shared_ptr<Resource>&& arg) { resources_[arg->name()] = std::move(arg); } virtual void setup(OperatorSpec& spec) { (void)spec; } virtual void start(){ // Empty default implementation }; virtual void stop(){ // Empty default implementation }; virtual void compute(InputContext& op_input, OutputContext& op_output, ExecutionContext& context) { (void)op_input; (void)op_output; (void)context; }; protected: std::unique_ptr<OperatorSpec> spec_; std::unordered_map<std::string, std::shared_ptr<Condition>> conditions_; std::unordered_map<std::string, std::shared_ptr<Resource>> resources_; }; } // namespace holoscan #endif/* HOLOSCAN_CORE_OPERATOR_HPP */

© Copyright 2022, NVIDIA. Last updated on Jun 28, 2023.