oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ove::File Class Reference

RAII wrapper around an oveRTOS file handle. More...

#include <fs.hpp>

Public Member Functions

 File ()
 Constructs a File object with no open file (invalid state).
 
 ~File () noexcept
 Destroys the file object, closing the file if it is still open.
 
 File (const File &)=delete
 
Fileoperator= (const File &)=delete
 
 File (File &&other) noexcept
 Move constructor — transfers ownership of the file handle.
 
Fileoperator= (File &&other) noexcept
 Move-assignment operator — closes the current file and takes ownership.
 
Result< void > open (const char *path, int flags) noexcept
 Opens a file at the specified path.
 
void close () noexcept
 Closes the file and invalidates the handle.
 
Result< size_t > read (void *buf, size_t count) noexcept
 Reads bytes from the file at the current position.
 
Result< size_t > write (const void *buf, size_t count) noexcept
 Writes bytes to the file at the current position.
 
Result< void > seek (long offset, int whence) noexcept
 Repositions the file offset.
 
long tell ()
 Returns the current file offset.
 
Result< size_t > size () noexcept
 Returns the size of the file.
 
bool valid () const
 Returns true if the file handle is valid (file is open).
 
ove_file_t handle () const
 Returns the raw oveRTOS file handle.
 

Detailed Description

RAII wrapper around an oveRTOS file handle.

The file is opened explicitly via open() and closed either by calling close() or automatically by the destructor. If the object is destroyed with an open file, the destructor calls close().

Note
Non-copyable; movable.

Constructor & Destructor Documentation

◆ File()

ove::File::File ( File &&  other)
inlinenoexcept

Move constructor — transfers ownership of the file handle.

Parameters
otherThe source; its handle is set to null after the move.

Member Function Documentation

◆ operator=()

File & ove::File::operator= ( File &&  other)
inlinenoexcept

Move-assignment operator — closes the current file and takes ownership.

Parameters
otherThe source; its handle is set to null after the move.
Returns
Reference to this object.

◆ open()

Result< void > ove::File::open ( const char *  path,
int  flags 
)
inlinenoexcept

Opens a file at the specified path.

Parameters
[in]pathAbsolute path to the file.
[in]flagsOpen flags (e.g., read-only, write, create).
Returns
Empty Result<void> on success; unexpected Error on failure.

◆ close()

void ove::File::close ( )
inlinenoexcept

Closes the file and invalidates the handle.

Safe to call on an already-closed file (no-op). Errors from the backend (e.g. flush failures) are intentionally discarded here — call this on a known-good handle if you need to surface such failures. Matches the close-is-void shape used by TcpSocket and UdpSocket.

◆ read()

Result< size_t > ove::File::read ( void *  buf,
size_t  count 
)
inlinenoexcept

Reads bytes from the file at the current position.

Parameters
[out]bufBuffer to receive the read data.
[in]countMaximum number of bytes to read.
Returns
On success, the number of bytes actually read (may be less than count near end-of-file). On failure, an unexpected Error.

◆ write()

Result< size_t > ove::File::write ( const void *  buf,
size_t  count 
)
inlinenoexcept

Writes bytes to the file at the current position.

Parameters
[in]bufPointer to the data to write.
[in]countNumber of bytes to write.
Returns
On success, the number of bytes actually written. On failure, an unexpected Error.

◆ seek()

Result< void > ove::File::seek ( long  offset,
int  whence 
)
inlinenoexcept

Repositions the file offset.

Parameters
[in]offsetByte offset relative to whence.
[in]whenceSeek origin (SEEK_SET, SEEK_CUR, or SEEK_END).
Returns
Empty Result<void> on success; unexpected Error on failure.

◆ tell()

long ove::File::tell ( )
inline

Returns the current file offset.

Returns
The current byte offset from the start of the file, or -1 on error.

◆ size()

Result< size_t > ove::File::size ( )
inlinenoexcept

Returns the size of the file.

Returns
On success, the file size in bytes. On failure, an unexpected Error.

◆ valid()

bool ove::File::valid ( ) const
inline

Returns true if the file handle is valid (file is open).

Returns
true when a file has been successfully opened.

◆ handle()

ove_file_t ove::File::handle ( ) const
inline

Returns the raw oveRTOS file handle.

Returns
The opaque ove_file_t handle.

The documentation for this class was generated from the following file: