Lely core libraries 2.3.4
file.hpp
Go to the documentation of this file.
1
22#ifndef LELY_IO_FILE_HPP_
23#define LELY_IO_FILE_HPP_
24
25#ifndef __cplusplus
26#error "include <lely/io/file.h> for the C interface"
27#endif
28
29#include <lely/io/file.h>
30#include <lely/io/io.hpp>
31
32#include <utility>
33
34namespace lely {
35
37class IOFile : public IOHandle {
38 public:
39 IOFile(const char* path, int flags) : IOHandle(io_open_file(path, flags)) {
40 if (!operator bool()) throw_or_abort(bad_init());
41 }
42
43 IOFile(const IOFile& file) noexcept : IOHandle(file) {}
44
45 IOFile(IOFile&& file) noexcept : IOHandle(::std::forward<IOFile>(file)) {}
46
47 IOFile&
48 operator=(const IOFile& file) noexcept {
49 IOHandle::operator=(file);
50 return *this;
51 }
52
53 IOFile&
54 operator=(IOFile&& file) noexcept {
55 IOHandle::operator=(::std::forward<IOFile>(file));
56 return *this;
57 }
58
60 seek(io_off_t offset, int whence) noexcept {
61 return io_seek(*this, offset, whence);
62 }
63
64 ssize_t
65 pread(void* buf, size_t nbytes, io_off_t offset) noexcept {
66 return io_pread(*this, buf, nbytes, offset);
67 }
68
69 ssize_t
70 pwrite(const void* buf, size_t nbytes, io_off_t offset) noexcept {
71 return io_pwrite(*this, buf, nbytes, offset);
72 }
73};
74
75} // namespace lely
76
77#endif // !LELY_IO_FILE_HPP_
A regular file device handle.
Definition: file.hpp:37
An I/O device handle.
Definition: io.hpp:35
The type of objects thrown as exceptions to report a failure to initialize an instantiation of a C ty...
Definition: c_type.hpp:38
#define throw_or_abort(e)
If exceptions are disabled, aborts the process instead of throwing an exception.
Definition: exception.hpp:38
This header file is part of the I/O library; it contains the regular file declarations.
ssize_t io_pwrite(io_handle_t handle, const void *buf, size_t nbytes, io_off_t offset)
Performs a write operation at the specified offset, without updating the file pointer.
Definition: file.c:219
io_off_t io_seek(io_handle_t handle, io_off_t offset, int whence)
Moves the current read/write offset of an open file.
Definition: file.c:185
ssize_t io_pread(io_handle_t handle, void *buf, size_t nbytes, io_off_t offset)
Performs a read operation at the specified offset, without updating the file pointer.
Definition: file.c:202
io_handle_t io_open_file(const char *path, int flags)
Opens a regular file.
Definition: file.c:81
int64_t io_off_t
A file offset type.
Definition: io.h:37
This header file is part of the I/O library; it contains the C++ interface of the I/O device handle.
A regular file handle.
Definition: file.c:43