.. _program_listing_file_include_rclcpp_message_memory_strategy.hpp: Program Listing for File message_memory_strategy.hpp ==================================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/rclcpp/message_memory_strategy.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2015 Open Source Robotics Foundation, Inc. // // 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 RCLCPP__MESSAGE_MEMORY_STRATEGY_HPP_ #define RCLCPP__MESSAGE_MEMORY_STRATEGY_HPP_ #include #include #include "rcl/types.h" #include "rclcpp/allocator/allocator_common.hpp" #include "rclcpp/exceptions.hpp" #include "rclcpp/macros.hpp" #include "rclcpp/serialized_message.hpp" #include "rclcpp/visibility_control.hpp" #include "rcutils/logging_macros.h" #include "rmw/serialized_message.h" namespace rclcpp { namespace message_memory_strategy { template> class MessageMemoryStrategy { public: RCLCPP_SMART_PTR_DEFINITIONS(MessageMemoryStrategy) using MessageAllocTraits = allocator::AllocRebind; using MessageAlloc = typename MessageAllocTraits::allocator_type; using MessageDeleter = allocator::Deleter; using SerializedMessageAllocTraits = allocator::AllocRebind; using SerializedMessageAlloc = typename SerializedMessageAllocTraits::allocator_type; using SerializedMessageDeleter = allocator::Deleter; using BufferAllocTraits = allocator::AllocRebind; using BufferAlloc = typename BufferAllocTraits::allocator_type; using BufferDeleter = allocator::Deleter; MessageMemoryStrategy() { message_allocator_ = std::make_shared(); serialized_message_allocator_ = std::make_shared(); buffer_allocator_ = std::make_shared(); rcutils_allocator_ = allocator::get_rcl_allocator(*buffer_allocator_.get()); } explicit MessageMemoryStrategy(std::shared_ptr allocator) { message_allocator_ = std::make_shared(*allocator.get()); serialized_message_allocator_ = std::make_shared(*allocator.get()); buffer_allocator_ = std::make_shared(*allocator.get()); rcutils_allocator_ = allocator::get_rcl_allocator(*buffer_allocator_.get()); } virtual ~MessageMemoryStrategy() = default; static SharedPtr create_default() { return std::make_shared>(std::make_shared()); } virtual std::shared_ptr borrow_message() { return std::allocate_shared(*message_allocator_.get()); } virtual std::shared_ptr borrow_serialized_message(size_t capacity) { return std::make_shared(capacity); } virtual std::shared_ptr borrow_serialized_message() { return borrow_serialized_message(default_buffer_capacity_); } virtual void set_default_buffer_capacity(size_t capacity) { default_buffer_capacity_ = capacity; } virtual void return_message(std::shared_ptr & msg) { msg.reset(); } virtual void return_serialized_message( std::shared_ptr & serialized_msg) { serialized_msg.reset(); } std::shared_ptr message_allocator_; MessageDeleter message_deleter_; std::shared_ptr serialized_message_allocator_; SerializedMessageDeleter serialized_message_deleter_; std::shared_ptr buffer_allocator_; BufferDeleter buffer_deleter_; size_t default_buffer_capacity_ = 0; rcutils_allocator_t rcutils_allocator_; }; } // namespace message_memory_strategy } // namespace rclcpp #endif // RCLCPP__MESSAGE_MEMORY_STRATEGY_HPP_