Make DeletingFile movable.

PiperOrigin-RevId: 592332785
This commit is contained in:
MediaPipe Team 2023-12-19 13:45:20 -08:00 committed by Copybara-Service
parent 5ee24d1662
commit 7c3a5296ab
2 changed files with 20 additions and 0 deletions

View File

@ -17,10 +17,25 @@
#include <stdio.h>
#include <utility>
#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) {}

View File

@ -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);