.. _program_listing_file_include_semantic_components_semantic_component_interface.hpp: Program Listing for File semantic_component_interface.hpp ========================================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/semantic_components/semantic_component_interface.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright (c) 2021, Stogl Robotics Consulting UG (haftungsbeschränkt) // // 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 SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_INTERFACE_HPP_ #define SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_INTERFACE_HPP_ #include #include #include "controller_interface/helpers.hpp" #include "hardware_interface/loaned_state_interface.hpp" namespace semantic_components { template class SemanticComponentInterface { public: explicit SemanticComponentInterface(const std::string & name, size_t size = 0) { name_ = name; interface_names_.reserve(size); state_interfaces_.reserve(size); } ~SemanticComponentInterface() = default; bool assign_loaned_state_interfaces( std::vector & state_interfaces) { return controller_interface::get_ordered_interfaces( state_interfaces, interface_names_, "", state_interfaces_); } void release_interfaces() { state_interfaces_.clear(); } virtual std::vector get_state_interface_names() { if (interface_names_.empty()) { for (auto i = 0u; i < interface_names_.capacity(); ++i) { interface_names_.emplace_back(name_ + "/" + std::to_string(i + 1)); } } return interface_names_; } bool get_values(std::vector & values) const { // check we have sufficient memory if (values.capacity() != state_interfaces_.size()) { return false; } // insert all the values for (size_t i = 0; i < state_interfaces_.size(); ++i) { values.emplace_back(state_interfaces_[i].get().get_value()); } return true; } bool get_values_as_message(MessageReturnType & /* message */) { return false; } protected: std::string name_; std::vector interface_names_; std::vector> state_interfaces_; }; } // namespace semantic_components #endif // SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_INTERFACE_HPP_