libcamera/include/libcamera/base/unique_fd.h
Mattijs Korpershoek 5d444bbd51 libcamera: base: Remove custom __nodiscard attribute
__nodiscard was introduced for compatibility with C++14.
In C++17, there is an official attribute: [[nodiscard]].
Moreover, some libc implementations (like bionic) already define the
__nodiscard macro [1].

Since:
- libcamera builds with cpp_std=c++17
- [[nodiscard]] is already used in the android HAL (exif)

We should replace all usage __nodiscard of by [[nodiscard]] for
consistency.

Do the replacement and remove the no longer used compiler.h.

[1] 3254860

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2025-01-08 15:26:30 +00:00

68 lines
861 B
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2021, Google Inc.
*
* File descriptor wrapper that owns a file descriptor.
*/
#pragma once
#include <utility>
#include <libcamera/base/class.h>
namespace libcamera {
class UniqueFD final
{
public:
UniqueFD()
: fd_(-1)
{
}
explicit UniqueFD(int fd)
: fd_(fd)
{
}
UniqueFD(UniqueFD &&other)
: fd_(other.release())
{
}
~UniqueFD()
{
reset();
}
UniqueFD &operator=(UniqueFD &&other)
{
reset(other.release());
return *this;
}
[[nodiscard]] int release()
{
int fd = fd_;
fd_ = -1;
return fd;
}
void reset(int fd = -1);
void swap(UniqueFD &other)
{
std::swap(fd_, other.fd_);
}
int get() const { return fd_; }
bool isValid() const { return fd_ >= 0; }
private:
LIBCAMERA_DISABLE_COPY(UniqueFD)
int fd_;
};
} /* namespace libcamera */