From 56d73b40979ef2f4b1908846ac649e07e692ad5b Mon Sep 17 00:00:00 2001 From: Gonzalo de Pedro Date: Fri, 10 Dec 2021 09:59:28 -0300 Subject: [PATCH] added copy constructor Signed-off-by: Gonzalo de Pedro --- .../cv_mat_sensor_msgs_image_type_adapter.hpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/image_tools/include/image_tools/cv_mat_sensor_msgs_image_type_adapter.hpp b/image_tools/include/image_tools/cv_mat_sensor_msgs_image_type_adapter.hpp index b6b225bb5..ea3a772d2 100644 --- a/image_tools/include/image_tools/cv_mat_sensor_msgs_image_type_adapter.hpp +++ b/image_tools/include/image_tools/cv_mat_sensor_msgs_image_type_adapter.hpp @@ -96,6 +96,34 @@ class ROSCvMatContainer IMAGE_TOOLS_PUBLIC ROSCvMatContainer() = default; + IMAGE_TOOLS_PUBLIC + explicit ROSCvMatContainer(const ROSCvMatContainer &other) : + header_(other.header_), frame_(other.frame_), is_bigendian_(other.is_bigendian_) + { + if(std::holds_alternative>(other.storage_)) { + storage_ = std::get>(other.storage_); + } + else if(std::holds_alternative>(other.storage_)) { + storage_ = std::make_unique( *std::get>(other.storage_) ); + } + + }; + + ROSCvMatContainer& operator=(const ROSCvMatContainer& other){ + if (this != &other) { + header_ = other.header_; + frame_ = other.frame_; + is_bigendian_ = other.is_bigendian_; + if(std::holds_alternative>(other.storage_)) { + storage_ = std::get>(other.storage_); + } + else if(std::holds_alternative>(other.storage_)) { + storage_ = std::make_unique( *std::get>(other.storage_) ); + } + } + return *this; + } + /// Store an owning pointer to a sensor_msg::msg::Image, and create a cv::Mat that references it. IMAGE_TOOLS_PUBLIC explicit ROSCvMatContainer(std::unique_ptr unique_sensor_msgs_image);