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 ()
 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.
 
int open (const char *path, int flags)
 Opens a file at the specified path.
 
int close ()
 Closes the file and invalidates the handle.
 
int read (void *buf, size_t count, size_t *bytes_read)
 Reads bytes from the file at the current position.
 
int write (const void *buf, size_t count, size_t *bytes_written)
 Writes bytes to the file at the current position.
 
int seek (long offset, int whence)
 Repositions the file offset.
 
long tell ()
 Returns the current file offset.
 
int size (size_t *out_size)
 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()

int ove::File::open ( const char *  path,
int  flags 
)
inline

Opens a file at the specified path.

Parameters
[in]pathAbsolute path to the file.
[in]flagsOpen flags (e.g., read-only, write, create).
Returns
OVE_OK on success, or a negative error code.

◆ close()

int ove::File::close ( )
inline

Closes the file and invalidates the handle.

Safe to call on an already-closed file (returns OVE_OK).

Returns
OVE_OK on success, or a negative error code.

◆ read()

int ove::File::read ( void *  buf,
size_t  count,
size_t *  bytes_read 
)
inline

Reads bytes from the file at the current position.

Parameters
[out]bufBuffer to receive the read data.
[in]countMaximum number of bytes to read.
[out]bytes_readReceives the actual number of bytes read.
Returns
OVE_OK on success, or a negative error code.

◆ write()

int ove::File::write ( const void *  buf,
size_t  count,
size_t *  bytes_written 
)
inline

Writes bytes to the file at the current position.

Parameters
[in]bufPointer to the data to write.
[in]countNumber of bytes to write.
[out]bytes_writtenReceives the actual number of bytes written.
Returns
OVE_OK on success, or a negative error code.

◆ seek()

int ove::File::seek ( long  offset,
int  whence 
)
inline

Repositions the file offset.

Parameters
[in]offsetByte offset relative to whence.
[in]whenceSeek origin (SEEK_SET, SEEK_CUR, or SEEK_END).
Returns
OVE_OK on success, or a negative error code.

◆ 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()

int ove::File::size ( size_t *  out_size)
inline

Returns the size of the file.

Parameters
[out]out_sizeReceives the file size in bytes.
Returns
OVE_OK on success, or a negative error code.

◆ 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: