Jameo Core Library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
jm::Resource Class Reference

This class represents a resource, which comes with the app. More...

Inheritance diagram for jm::Resource:
jm::Stream jm::Object

Public Member Functions

 Resource (const jm::String &path)
 
 Resource (const Resource &other)
 
Resourceoperator= (const Resource &other)
 
 ~Resource () override
 
bool exists () const
 
size_t size () const override
 Returns the length of the stream.
 
jm::Status open (jm::FileMode mode) override
 Opens the stream for read or write operations.
 
bool isOpen () override
 Returns whether the file is open or not.
 
bool canRead () const override
 Checks if the file/stream can be read.
 
void close () override
 Closes the stream if it was previously opened and releases any system resources.
 
size_t read (uint8 *buffer, size_t length) override
 Reads a maximum of length bytes into the array.
 
size_t readFully (jm::ByteArray &buffer, size_t length) override
 Reads a maximum of length bytes into the array.
 
void seek (size_t position) override
 Moves the file cursor to the desired position, counted from the beginning of the file (0-based index).
 
void move (ssize_t offset) override
 Moves the file cursor to the desired position, counted from the current position.
 
size_t position () override
 Returns the current cursor position in the file.
 
size_t write (const uint8 *buffer, size_t length) override
 Writes a buffer to the output file.
 
- Public Member Functions inherited from jm::Stream
 Stream ()
 Constructor.
 
size_t readFully (ByteArray &buffer)
 Reads a maximum of length bytes into the array.
 
size_t write (const int8 *buffer, size_t length)
 Writes a buffer to the output file.
 
size_t write (const String &string)
 Writes a string to the output file. The encoding is the default encoding (UTF-8). NOT AS A C-STRING!
 
- Public Member Functions inherited from jm::Object
 Object () noexcept
 Constructor.
 
virtual ~Object () noexcept
 Destructor.
 
void release () noexcept
 Decreases the reference counter and releases the object immediately when the reference counter becomes 0.
 
Objectretain () noexcept
 Increases the reference counter of this object by 1.
 
Objectautorelease () noexcept
 Same function as release(), but releases the object with a delay if the reference counter is 0. AutoreleasePool::drain() must be called in the to release the object.
 
int32 referenceCount () const noexcept
 Returns the value of the reference counter.
 
virtual bool equals (const Object *other) const
 Comparison of objects.
 
virtual String displayName () const
 Returns the display name of the object intended to present to a user.
 
virtual void printDiffInfo (DiffOperation operation, Object *other) const
 Output method for outputting the diff results for the diff algorithm.
 
void setHighBit (bool status) noexcept
 
bool highBit () const noexcept
 

Detailed Description

This class represents a resource, which comes with the app.

Resources are files, that are packed with an application. Like images, fonts and other stuff to make the application work. On most systems, these are "plain" files in a defined resource directory. On Android for example, these are files packed into to apk of the app. So simple file access is not possible.

To handle all resources whether it is a file or a packed resource, we provide this unified interface.

Note
On Android, resource names must not contain a point (.), and must be lowercase. In Android resources are located without its ending. So in the same path do not have resources with same name, but different endings.

Constructor & Destructor Documentation

◆ Resource() [1/2]

jm::Resource::Resource ( const jm::String path)
explicit

◆ Resource() [2/2]

jm::Resource::Resource ( const Resource other)

◆ ~Resource()

jm::Resource::~Resource ( )
override

Member Function Documentation

◆ canRead()

bool jm::Resource::canRead ( ) const
overridevirtual

Checks if the file/stream can be read.

Implements jm::Stream.

◆ close()

void jm::Resource::close ( )
overridevirtual

Closes the stream if it was previously opened and releases any system resources.

This method closes the stream if it was previously opened and releases any system resources associated with it.

Implements jm::Stream.

◆ exists()

bool jm::Resource::exists ( ) const

◆ isOpen()

bool jm::Resource::isOpen ( )
overridevirtual

Returns whether the file is open or not.

This method returns a boolean value indicating whether the file is currently open or not.

Returns
true if the file is open, false otherwise.

Implements jm::Stream.

◆ move()

void jm::Resource::move ( ssize_t  offset)
overridevirtual

Moves the file cursor to the desired position, counted from the current position.

This method moves the file cursor to the specified position, counted from the current position.

Implements jm::Stream.

◆ open()

jm::Status jm::Resource::open ( jm::FileMode  mode)
overridevirtual

Opens the stream for read or write operations.

Parameters
modeThe mode to open the stream.

This method opens the stream for read or write operations based on the specified mode.

Returns
The status of the operation.

Implements jm::Stream.

◆ operator=()

Resource & jm::Resource::operator= ( const Resource other)

◆ position()

size_t jm::Resource::position ( )
overridevirtual

Returns the current cursor position in the file.

Note
Not every stream supports this method.

This method returns the current cursor position in the file.

Returns
The current cursor position.

Implements jm::Stream.

◆ read()

size_t jm::Resource::read ( uint8 *  buffer,
size_t  length 
)
overridevirtual

Reads a maximum of length bytes into the array.

For large blocks, it is possible that not all bytes are read because it is still waiting for data. In this case, only a portion may be returned. If you want to ensure that all data is read, you should call readFully().

Returns
The actual number of bytes read, or 0 if no bytes were read (EOF).

Implements jm::Stream.

◆ readFully()

size_t jm::Resource::readFully ( jm::ByteArray buffer,
size_t  length 
)
overridevirtual

Reads a maximum of length bytes into the array.

For large blocks, it is possible that not all bytes are read because it is still waiting for data. In this case, only a portion may be returned. If you want to ensure that all data is read, you should call readFully().

Parameters
bufferThe buffer to read the data from.
lengthThe maximum number of bytes to read.
Returns
The actual number of bytes read, or 0 if no bytes were read (EOF).

Implements jm::Stream.

◆ seek()

void jm::Resource::seek ( size_t  position)
overridevirtual

Moves the file cursor to the desired position, counted from the beginning of the file (0-based index).

Note
Not every stream supports this method.

This method moves the file cursor to the specified position, counted from the beginning of the file.

Implements jm::Stream.

◆ size()

size_t jm::Resource::size ( ) const
overridevirtual

Returns the length of the stream.

This method returns the length of the stream in bytes.

Returns
The length of the stream.

Implements jm::Stream.

◆ write()

size_t jm::Resource::write ( const uint8 *  buffer,
size_t  length 
)
overridevirtual

Writes a buffer to the output file.

This method writes the contents of the buffer to the output file.

Parameters
bufferThe buffer containing the data to be written.
lengthThe number of bytes to write from the buffer.
Returns
The actual number of bytes written.

Implements jm::Stream.