Silicium
file_handle.hpp
Go to the documentation of this file.
1 #ifndef SILICIUM_FILE_HANDLE_HPP
2 #define SILICIUM_FILE_HANDLE_HPP
3 
5 #include <silicium/exchange.hpp>
6 #include <silicium/is_handle.hpp>
7 
8 namespace Si
9 {
10  struct file_handle
11  {
12  native_file_descriptor handle;
13 
14  file_handle() BOOST_NOEXCEPT
15  : handle(no_file_handle)
16  {
17  }
18 
19  file_handle(file_handle &&other) BOOST_NOEXCEPT
20  : handle(no_file_handle)
21  {
22  swap(other);
23  }
24 
25  explicit file_handle(native_file_descriptor handle) BOOST_NOEXCEPT
26  : handle(handle)
27  {
28  }
29 
30  file_handle &operator = (file_handle &&other) BOOST_NOEXCEPT
31  {
32  swap(other);
33  return *this;
34  }
35 
36  void swap(file_handle &other) BOOST_NOEXCEPT
37  {
38  using std::swap;
39  swap(handle, other.handle);
40  }
41 
42  void close() BOOST_NOEXCEPT
43  {
44  file_handle().swap(*this);
45  }
46 
47  native_file_descriptor release() BOOST_NOEXCEPT
48  {
49  return Si::exchange(handle, no_file_handle);
50  }
51 
52  ~file_handle() BOOST_NOEXCEPT
53  {
54  if (handle != no_file_handle)
55  {
56  terminating_close(handle);
57  }
58  }
59 
60  private:
61 
64  };
65 
67 }
68 
69 #endif
file_handle() BOOST_NOEXCEPT
Definition: file_handle.hpp:14
BOOST_STATIC_ASSERT(Si::is_handle< absolute_path >::value)
native_file_descriptor handle
Definition: file_handle.hpp:12
file_handle(native_file_descriptor handle) BOOST_NOEXCEPT
Definition: file_handle.hpp:25
Definition: absolute_path.hpp:19
native_file_descriptor release() BOOST_NOEXCEPT
Definition: file_handle.hpp:47
file_handle & operator=(file_handle &&other) BOOST_NOEXCEPT
Definition: file_handle.hpp:30
T exchange(T &dest, U &&source)
Definition: exchange.hpp:30
file_handle(file_handle &&other) BOOST_NOEXCEPT
Definition: file_handle.hpp:19
void close() BOOST_NOEXCEPT
Definition: file_handle.hpp:42
void swap(file_handle &other) BOOST_NOEXCEPT
Definition: file_handle.hpp:36
#define SILICIUM_DELETED_FUNCTION(f)
Definition: config.hpp:111
Definition: file_handle.hpp:10
Definition: is_handle.hpp:21
~file_handle() BOOST_NOEXCEPT
Definition: file_handle.hpp:52