RADLib
RADical C++ application framework
RADCore::RADFile Class Reference

File-backed RADIODevice. More...

#include <RADCore.h>

+ Inheritance diagram for RADCore::RADFile:
+ Collaboration diagram for RADCore::RADFile:

Public Member Functions

 RADFile ()
 Creates a file with no path. More...
 
 RADFile (std::string fileName)
 Creates a file bound to fileName. More...
 
 ~RADFile () override
 Closes the file if needed. More...
 
void setFileName (std::string fileName)
 Sets the file path. More...
 
const std::string & fileName () const
 Returns the file path. More...
 
bool open (OpenMode mode) override
 Opens the file with mode. More...
 
void close () override
 Closes the file descriptor. More...
 
bool isOpen () const override
 Returns true when the file is open. More...
 
ssize_t readData (void *buffer, size_t maxBytes) override
 Reads raw bytes from the file. More...
 
ssize_t writeData (const void *data, size_t size) override
 Writes raw bytes to the file. More...
 
bool seek (size_t position)
 Seeks to an absolute byte position. More...
 
size_t position () const
 Returns current byte position. More...
 
size_t size () const
 Returns file size in bytes. More...
 
- Public Member Functions inherited from RADCore::RADIODevice
virtual ~RADIODevice ()=default
 Destroys the IO device. More...
 
std::vector< uint8_t > read (size_t maxBytes)
 Reads up to maxBytes into a byte vector. More...
 
std::vector< uint8_t > readAll (size_t chunkSize=8192)
 Reads all available data in chunks. More...
 
ssize_t write (const std::vector< uint8_t > &data)
 Writes a byte vector. More...
 
ssize_t write (const std::string &text)
 Writes string bytes. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Additional Inherited Members

- Public Attributes inherited from RADCore::RADIODevice
RADCore::Event< void() > readyRead
 Raised when data is available to read. More...
 
RADCore::Event< void(size_t) > bytesWritten
 Raised after bytes are written. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised when an IO error occurs. More...
 

Detailed Description

File-backed RADIODevice.

Constructor & Destructor Documentation

◆ RADFile() [1/2]

RADCore::RADFile::RADFile ( )

Creates a file with no path.

◆ RADFile() [2/2]

RADCore::RADFile::RADFile ( std::string  fileName)
explicit

Creates a file bound to fileName.

◆ ~RADFile()

RADCore::RADFile::~RADFile ( )
override

Closes the file if needed.

Member Function Documentation

◆ close()

void RADCore::RADFile::close ( )
overridevirtual

Closes the file descriptor.

Implements RADCore::RADIODevice.

◆ fileName()

const std::string& RADCore::RADFile::fileName ( ) const

Returns the file path.

◆ isOpen()

bool RADCore::RADFile::isOpen ( ) const
overridevirtual

Returns true when the file is open.

Implements RADCore::RADIODevice.

◆ open()

bool RADCore::RADFile::open ( OpenMode  mode)
overridevirtual

Opens the file with mode.

Implements RADCore::RADIODevice.

◆ position()

size_t RADCore::RADFile::position ( ) const

Returns current byte position.

◆ readData()

ssize_t RADCore::RADFile::readData ( void *  buffer,
size_t  maxBytes 
)
overridevirtual

Reads raw bytes from the file.

Implements RADCore::RADIODevice.

◆ seek()

bool RADCore::RADFile::seek ( size_t  position)

Seeks to an absolute byte position.

◆ setFileName()

void RADCore::RADFile::setFileName ( std::string  fileName)

Sets the file path.

◆ size()

size_t RADCore::RADFile::size ( ) const

Returns file size in bytes.

◆ writeData()

ssize_t RADCore::RADFile::writeData ( const void *  data,
size_t  size 
)
overridevirtual

Writes raw bytes to the file.

Implements RADCore::RADIODevice.


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