|
pstore2
|
Implements a portable file access API. More...
#include <file.hpp>


Classes | |
| struct | temporary |
| temporary is an empty class type used to disambiguate the overloads of creating a file. More... | |
| struct | unique |
| unique is an empty class type used to disambiguate the overloads of creating a file. More... | |
Public Types | |
| enum | create_mode { create_mode::create_new, create_mode::open_existing, create_mode::open_always } |
| enum | present_mode { present_mode::allow_not_found, present_mode::must_exist } |
| Controls the behavior of the file_handle constructor when passed a path which does not already exist. More... | |
| enum | writable_mode { read_only, read_write } |
| Controls whether the file_handle constructor produces a read-only or read/write object. More... | |
| using | memory_mapper = pstore::memory_mapper |
| The type which can be used to memory-map instances of physcial files. | |
| using | oshandle = int |
Public Types inherited from pstore::file::file_base | |
| enum | blocking_mode { blocking_mode::non_blocking, blocking_mode::blocking } |
| Indicates whether the lock() method should block until the lock has been obtained. More... | |
| enum | lock_kind { lock_kind::shared_read, lock_kind::exclusive_write } |
| Represents the type of file range lock to be obtained. More... | |
Public Member Functions | |
| file_handle (std::string path) noexcept | |
| file_handle (file_handle const &)=delete | |
| file_handle (file_handle &&other) noexcept | |
| file_handle & | operator= (file_handle &&rhs) noexcept |
| file_handle & | operator= (file_handle const &)=delete |
| void | open (create_mode create, writable_mode writable, present_mode present=present_mode::allow_not_found) |
| void | open (unique, std::string const &directory) |
| Create a new, uniquely named, file in the specified directory. | |
| void | open (temporary const t) |
| Creates a temporary file in the system temporary directory. | |
| void | open (temporary, std::string const &directory) |
| Creates a temporary file in the specified directory. | |
| bool | is_open () const noexcept override |
| bool | is_writable () const noexcept override |
| Return true if the object was created as writable. More... | |
| std::string | path () const override |
| Returns the name of the file originally associated with this file object. More... | |
| void | close () override |
| void | seek (std::uint64_t position) override |
| Sets the file position indicator for the file. More... | |
| std::uint64_t | tell () override |
| Obtains the current value of the position indicator for the file. | |
| std::uint64_t | size () override |
| void | truncate (std::uint64_t size) override |
| bool | rename (std::string const &new_name) |
| Renames a file from one UTF-8 encoded path to another. More... | |
| std::time_t | latest_time () const override |
| bool | lock (std::uint64_t offset, std::size_t size, lock_kind kind, blocking_mode block) override |
| Obtains a shared-read or exclusive-write lock on the file range specified by the 'offset' and size' parameters. More... | |
| void | unlock (std::uint64_t offset, std::size_t size) override |
| Unlocks the file bytes specified by 'offset' and 'size'. More... | |
| oshandle | raw_handle () noexcept |
Public Member Functions inherited from pstore::file::file_base | |
| file_base (file_base &&) noexcept=default | |
| file_base (file_base const &)=default | |
| file_base & | operator= (file_base &&) noexcept=default |
| file_base & | operator= (file_base const &)=default |
| template<typename SpanType , typename = typename std::enable_if<std::is_standard_layout< typename SpanType::element_type>::value>::type> | |
| std::size_t | read_span (SpanType const &s) |
| Reads instances of a standard-layout type from the file. More... | |
| template<typename T , typename = typename std::enable_if<std::is_standard_layout<T>::value>::type> | |
| void | read (T *const t) |
| Reads a series of raw bytes from the file as an instance of type T. | |
| template<typename SpanType , typename = typename std::enable_if<std::is_standard_layout< typename SpanType::element_type>::value>::type> | |
| void | write_span (SpanType const &s) |
| Writes instances of a standard-layout type to the file. | |
| template<typename T , typename = typename std::enable_if<std::is_standard_layout<T>::value>::type> | |
| void | write (T const &t) |
| Writes 't' as a series of raw bytes to the file. | |
Static Public Member Functions | |
| static std::string | get_temporary_directory () |
| Returns a UTF-8 encoded string representing the temporary directory. More... | |
Static Public Attributes | |
| static constexpr oshandle | invalid_oshandle = -1 |
Additional Inherited Members | |
Raw file I/O | |
The following methods are protected because they provide the raw read/write-bytes functions. Use of the read_span(), write_span(), and write() template convenience functions is preferred. |
Implements a portable file access API.
|
strong |
|
strong |
Controls the behavior of the file_handle constructor when passed a path which does not already exist.
| Enumerator | |
|---|---|
| allow_not_found | If opening a file that does not exist, an exception will not be raised. The condition can be detected by calling is_open() and testing for a true result. If the file was not found, then any attempt to operate on the file – such as reading, writing, seeking, and so on – will fail with an exception being raised. |
| must_exist | If attempting to open a file that does not exist, an exception is raised. This mode is meaningless if used in conjunction with create_mode::create_new.. |
|
strong |
Controls whether the file_handle constructor produces a read-only or read/write object.
|
static |
Returns a UTF-8 encoded string representing the temporary directory.
|
inlineoverridevirtualnoexcept |
Return true if the object was created as writable.
Implements pstore::file::file_base.
|
overridevirtual |
The time members of struct stat might be called st_Xtimespec (of type struct timespec) or st_Xtime (and be of type time_t). This macro is defined in the former situation.
Implements pstore::file::file_base.
|
overridevirtual |
Obtains a shared-read or exclusive-write lock on the file range specified by the 'offset' and size' parameters.
If the blocking-mode is 'blocking' and another process has an exclusive_write lock on the specified range, then the call will block execution until the lock is acquired.
| offset | The offset of the first byte of the file to be locked. |
| size | The number of bytes to be locked. |
| lt | Specifies the type of lock to be obtained |
| bl | Indicates whether the function should block until the lock has been obtained or return immediately. |
Implements pstore::file::file_base.
|
inlineoverridevirtual |
Returns the name of the file originally associated with this file object.
Implements pstore::file::file_base.
| bool pstore::file::file_handle::rename | ( | std::string const & | new_name | ) |
Renames a file from one UTF-8 encoded path to another.
|
overridevirtual |
Sets the file position indicator for the file.
The new position, measured in bytes, is given by the 'position' parameter.
| position | The file offset to be used as the file position indicator. |
Implements pstore::file::file_base.
|
overridevirtual |
Unlocks the file bytes specified by 'offset' and 'size'.
The same file range must be locked by the current process, otherwise, the behavior is undefined.
| offset | The offset of the first byte of the file to be locked. |
| size | The number of bytes to be locked. |
Implements pstore::file::file_base.
1.8.13