Add move operators to ScopedFD
This makes MediaDevice movable when we switch it over.
Change-Id: I673c47129a0342bb9a78bb01bc505dcb8b9b245c
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/scoped/scoped_fd.h b/aos/scoped/scoped_fd.h
index e098d2c..116985a 100644
--- a/aos/scoped/scoped_fd.h
+++ b/aos/scoped/scoped_fd.h
@@ -11,7 +11,18 @@
class ScopedFD {
public:
explicit ScopedFD(int fd = -1) : fd_(fd) {}
+ ScopedFD(ScopedFD &) = delete;
+ ScopedFD(ScopedFD &&other) : ScopedFD(other.release()) {}
+
+ void operator=(const ScopedFD &) = delete;
+ void operator=(ScopedFD &&other) {
+ int tmp = fd_;
+ fd_ = other.fd_;
+ other.fd_ = tmp;
+ }
+
~ScopedFD() { Close(); }
+
int get() const { return fd_; }
int release() {
const int r = fd_;
@@ -28,8 +39,8 @@
private:
int fd_;
+
void Close();
- DISALLOW_COPY_AND_ASSIGN(ScopedFD);
};
} // namespace aos