#include <file_handle.hpp>
Public Member Functions | |
file_handle () | |
file_handle (handle_type h) | |
file_handle (const file_handle &fh) | |
~file_handle () | |
file_handle & | operator= (const file_handle &fh) |
bool | valid () const |
void | close () |
handle_type | release () |
handle_type | get () const |
The file_handle class is a simple RAII model for native system file handles. This class wraps one of such handles grabbing its ownership, and automaticaly closes it upon destruction. It is basically used inside the library to avoid leaking open file handles, shall an unexpected execution trace occur.
A file_handle object can be copied but doing so invalidates the source object. There can only be a single valid file_handle object for a given system file handle. This is similar to std::auto_ptr's semantics.
This class also provides some convenience methods to issue special file operations under their respective platforms.
boost::process::detail::file_handle::file_handle | ( | ) | [inline] |
Constructs an invalid file handle.
This constructor creates a new file_handle object that represents an invalid file handle. An invalid file handle can be copied but cannot be manipulated in any way (except checking for its validity).
boost::process::detail::file_handle::file_handle | ( | handle_type | h | ) | [inline] |
Constructs a new file handle from a native file handle.
This constructor creates a new file_handle object that takes ownership of the given h native file handle. The user must not close h on his own during the lifetime of the new object. Ownership can be reclaimed using release().
boost::process::detail::file_handle::file_handle | ( | const file_handle & | fh | ) | [inline] |
Copy constructor; invalidates the source handle.
This copy constructor creates a new file handle from a given one. Ownership of the native file handle is transferred to the new object, effectively invalidating the source file handle. This avoids having two live file_handle objects referring to the same native file handle. The source file handle needs not be valid in the name of simplicity.
The new file handle owns the source's native file handle.
boost::process::detail::file_handle::~file_handle | ( | ) | [inline] |
Releases resources if the handle is valid.
If the file handle is valid, the destructor closes it.
file_handle& boost::process::detail::file_handle::operator= | ( | const file_handle & | fh | ) | [inline] |
Assignment operator; invalidates the source handle.
This assignment operator transfers ownership of the RHS file handle to the LHS one, effectively invalidating the source file handle. This avoids having two live file_handle objects referring to the same native file handle. The source file handle needs not be valid in the name of simplicity.
The LHS file handle owns RHS' native file handle.
bool boost::process::detail::file_handle::valid | ( | ) | const [inline] |
Checks whether the file handle is valid or not.
Returns a boolean indicating whether the file handle is valid or not. If the file handle is invalid, no other methods can be executed other than the destructor.
void boost::process::detail::file_handle::close | ( | ) | [inline] |
Closes the file handle.
Explicitly closes the file handle, which must be valid. Upon exit, the handle is not valid any more.
The native file handle is closed.
handle_type boost::process::detail::file_handle::release | ( | ) | [inline] |
Reclaims ownership of the native file handle.
Explicitly reclaims ownership of the native file handle contained in the file_handle object, returning the native file handle. The caller is responsible of closing it later on.
handle_type boost::process::detail::file_handle::get | ( | ) | const [inline] |
Gets the native file handle.
Returns the native file handle for the file_handle object. The caller can issue any operation on it except closing it. If closing is required, release() shall be used.