geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
UniqueFd.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef UNIQUEFD_HPP_INCLUDE
7 #define UNIQUEFD_HPP_INCLUDE
8 
9 namespace geopm
10 {
12  class UniqueFd
13  {
14  public:
15  UniqueFd() = delete;
16 
17  // Disable copies since we only want one wrapper to close the fd
18  UniqueFd(UniqueFd const&) = delete;
19  UniqueFd& operator=(UniqueFd const&) = delete;
20 
22  UniqueFd(int fd);
23 
25  UniqueFd(UniqueFd &&other);
26 
28  ~UniqueFd();
29 
31  int get();
32  private:
33  int m_fd;
34  };
35 }
36 
37 #endif
A wrapper to close a file descriptor when the descriptor goes out of scope.
Definition: UniqueFd.hpp:13
~UniqueFd()
Close the wrapped fd if it is valid.
Definition: UniqueFd.cpp:29
UniqueFd(UniqueFd const &)=delete
UniqueFd()=delete
int get()
Get the wrapped raw fd (e.g., to call IO functions on it)
Definition: UniqueFd.cpp:41
UniqueFd & operator=(UniqueFd const &)=delete
Definition: Agg.cpp:20