NVIDIA Holoscan SDK v2.0.0
Holoscan v2.0.0 Download PDF

Program Listing for File resource.hpp

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

Copy
Copied!
            

/* * SPDX-FileCopyrightText: Copyright (c) 2022-2024 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_RESOURCE_HPP #define HOLOSCAN_CORE_RESOURCE_HPP #include <iostream> #include <memory> #include <string> #include <utility> #include "./component.hpp" #include "./gxf/gxf_component.hpp" #include "./gxf/gxf_utils.hpp" #define HOLOSCAN_RESOURCE_FORWARD_TEMPLATE() \ template <typename ArgT, \ typename... ArgsT, \ typename = std::enable_if_t<!std::is_base_of_v<Resource, std::decay_t<ArgT>> && \ (std::is_same_v<Arg, std::decay_t<ArgT>> || \ std::is_same_v<ArgList, std::decay_t<ArgT>>)>> #define HOLOSCAN_RESOURCE_FORWARD_ARGS(class_name) \ HOLOSCAN_RESOURCE_FORWARD_TEMPLATE() \ class_name(ArgT&& arg, ArgsT&&... args) \ : Resource(std::forward<ArgT>(arg), std::forward<ArgsT>(args)...) {} #define HOLOSCAN_RESOURCE_FORWARD_ARGS_SUPER(class_name, super_class_name) \ HOLOSCAN_RESOURCE_FORWARD_TEMPLATE() \ class_name(ArgT&& arg, ArgsT&&... args) \ : super_class_name(std::forward<ArgT>(arg), std::forward<ArgsT>(args)...) {} namespace holoscan { // Forward declarations class NetworkContext; class Scheduler; class Operator; class Resource : public Component { public: enum class ResourceType { kNative, kGXF, }; Resource() = default; Resource(Resource&&) = default; HOLOSCAN_RESOURCE_FORWARD_TEMPLATE() explicit Resource(ArgT&& arg, ArgsT&&... args) { add_arg(std::forward<ArgT>(arg)); (add_arg(std::forward<ArgsT>(args)), ...); } ~Resource() override = default; ResourceType resource_type() const { return resource_type_; } using Component::name; Resource& name(const std::string& name) & { name_ = name; return *this; } Resource&& name(const std::string& name) && { name_ = name; return std::move(*this); } using Component::fragment; Resource& fragment(Fragment* fragment) { fragment_ = fragment; return *this; } Resource& spec(const std::shared_ptr<ComponentSpec>& spec) { spec_ = spec; return *this; } ComponentSpec* spec() { return spec_.get(); } std::shared_ptr<ComponentSpec> spec_shared() { return spec_; } using Component::add_arg; virtual void setup(ComponentSpec& spec) { (void)spec; } void initialize() override; YAML::Node to_yaml_node() const override; protected: // Add friend classes that can call reset_graph_entites friend class holoscan::NetworkContext; friend class holoscan::Scheduler; friend class holoscan::Operator; using Component::reset_graph_entities; ResourceType resource_type_ = ResourceType::kNative; bool is_initialized_ = false; }; } // namespace holoscan #endif/* HOLOSCAN_CORE_RESOURCE_HPP */

© Copyright 2022-2024, NVIDIA. Last updated on Jun 4, 2024.