|
libcosmos
Linux C++ System Programming Library
|
Base class for File types with ownership of a FileDescriptor. More...
#include <FileBase.hxx>
Inheritance diagram for cosmos::FileBase:Public Member Functions | |
| FileBase (const FileBase &)=delete | |
| FileBase & | operator= (const FileBase &)=delete |
| virtual void | close () |
| Close the current file object. | |
| bool | isOpen () const |
| Returns whether currently a FileDescriptor is opened. | |
| FileDescriptor | fd () const |
| Allows access to the underlying fd with const semantics. | |
| void | truncate (const off_t length) |
Public Member Functions inherited from cosmos::StreamIO | |
| StreamIO (FileDescriptor &fd) | |
| StreamIO (const StreamIO &)=delete | |
| StreamIO & | operator= (const StreamIO &)=delete |
| StreamIO & | operator= (StreamIO &&) noexcept |
| size_t | read (void *buf, size_t length) |
Read up to length bytes from the file into buf. | |
| size_t | write (const void *buf, size_t length) |
Write up to length bytes from buf into the underlying file. | |
| size_t | write (const std::string_view data) |
| string_view wrapper around write(const void*, size_t). | |
| void | readAll (void *buf, size_t length) |
Read all length bytes from the underlying file. | |
| void | readAll (std::string &s, size_t length) |
| Like readAll(void*, size_t) using an STL string. | |
| void | writeAll (const void *buf, size_t length) |
Write all length bytes into the underlying file. | |
| void | writeAll (const std::string_view data) |
| string_view wrapper around writeAll(const void*, size_t). | |
| bool | read (ReadIOVector &iovec) |
| Read data from file into a vector of data regions. | |
| bool | write (WriteIOVector &iovec) |
| Write data to file from a vector of data regions. | |
| void | readAll (ReadIOVector &iovec) |
Read into all data regions specified in iovec. | |
| void | writeAll (WriteIOVector &iovec) |
Write all data regions specified in iovec. | |
| off_t | seek (const SeekType type, off_t off) |
Seek to the given offset based on the given offset type. | |
| off_t | seekFromStart (off_t off) |
| Seek to the given offset relative to the start of the file. | |
| off_t | seekFromCurrent (off_t off) |
| Seek to the given offset relative to the current file position. | |
| off_t | seekFromEnd (off_t off) |
| Seek to the given offset relative to the end of the file. | |
Protected Member Functions | |
| FileBase (const FileDescriptor fd=FileDescriptor{}) | |
| FileBase (FileBase &&other) noexcept | |
| FileBase & | operator= (FileBase &&other) noexcept |
Protected Attributes | |
| FileDescriptor | m_fd |
Protected Attributes inherited from cosmos::StreamIO | |
| FileDescriptor & | m_stream_fd |
Additional Inherited Members | |
Public Types inherited from cosmos::StreamIO | |
| enum class | SeekType : int { SET = SEEK_SET , CUR = SEEK_CUR , END = SEEK_END , DATA = SEEK_DATA , HOLE = SEEK_HOLE } |
| Different methods for changing the file read/write position. More... | |
Base class for File types with ownership of a FileDescriptor.
Implementations of FileBase carry ownership of a FileDescriptor. How this FileDescriptor is obtained is defined by specializations of this class.
This type implements the file close() logic and the moveable-only-semantics i.e. the type is non-copiable, but the ownership of the file descriptor can be transferred to other instances using std::move() and implicit move operations.
This type inherits the StreamIO interface for operating on the file content using streaming file I/O.
Definition at line 22 of file FileBase.hxx.
|
inlineprotected |
Definition at line 26 of file FileBase.hxx.
|
inlineprotectednoexcept |
Definition at line 35 of file FileBase.hxx.
|
virtual |
Definition at line 10 of file FileBase.cxx.
|
inlinevirtual |
Close the current file object.
If currently no file is open then this does nothing. If currently an external FileDescriptor is wrapped and auto-close is not set then only the object's state will be invalidated. Otherwise the referenced file descriptor will also be closed on OS-level.
Reimplemented in cosmos::EventFile, cosmos::FDFile, cosmos::TempFile, and cosmos::TimerFD< CLOCK >.
Definition at line 63 of file FileBase.hxx.
|
inline |
Allows access to the underlying fd with const semantics.
Definition at line 74 of file FileBase.hxx.
|
inline |
Returns whether currently a FileDescriptor is opened.
Definition at line 71 of file FileBase.hxx.
Definition at line 40 of file FileBase.hxx.
| void cosmos::FileBase::truncate | ( | const off_t | length | ) |
Definition at line 19 of file FileBase.cxx.
|
protected |
Definition at line 81 of file FileBase.hxx.