From 7c3a5296ab7defe295d41f2233af2b9aa7b73db6 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Tue, 19 Dec 2023 13:45:20 -0800 Subject: [PATCH] Make DeletingFile movable. PiperOrigin-RevId: 592332785 --- mediapipe/framework/formats/deleting_file.cc | 15 +++++++++++++++ mediapipe/framework/formats/deleting_file.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/mediapipe/framework/formats/deleting_file.cc b/mediapipe/framework/formats/deleting_file.cc index b759a5f64..ce09d8746 100644 --- a/mediapipe/framework/formats/deleting_file.cc +++ b/mediapipe/framework/formats/deleting_file.cc @@ -17,10 +17,25 @@ #include +#include + #include "absl/log/absl_log.h" namespace mediapipe { +DeletingFile::DeletingFile(DeletingFile&& other) + : path_(std::move(other.path_)), + delete_on_destruction_(other.delete_on_destruction_) { + other.delete_on_destruction_ = false; +} + +DeletingFile& DeletingFile::operator=(DeletingFile&& other) { + path_ = std::move(other.path_); + delete_on_destruction_ = other.delete_on_destruction_; + other.delete_on_destruction_ = false; + return *this; +} + DeletingFile::DeletingFile(const std::string& path, bool delete_on_destruction) : path_(path), delete_on_destruction_(delete_on_destruction) {} diff --git a/mediapipe/framework/formats/deleting_file.h b/mediapipe/framework/formats/deleting_file.h index f38e3333b..695cba491 100644 --- a/mediapipe/framework/formats/deleting_file.h +++ b/mediapipe/framework/formats/deleting_file.h @@ -28,6 +28,11 @@ class DeletingFile { DeletingFile(const DeletingFile&) = delete; DeletingFile& operator=(const DeletingFile&) = delete; + // DeletingFile is movable. The moved-from object remains in valid but + // unspecified state and will not perform any operations on destruction. + DeletingFile(DeletingFile&& other); + DeletingFile& operator=(DeletingFile&& other); + // Provide the path to the file and whether the file should be deleted // when this object is destroyed. DeletingFile(const std::string& path, bool delete_on_destruction);