DART  6.7.3
dart::common::Resource Class Referenceabstract

Resource provides file-like access to a resource loaded from URI. More...

#include <Resource.hpp>

Inheritance diagram for dart::common::Resource:
dart::common::LocalResource

Public Types

enum  SeekType { SEEKTYPE_CUR , SEEKTYPE_END , SEEKTYPE_SET }
 Position to seek relative to. More...
 

Public Member Functions

virtual ~Resource ()=default
 
virtual std::size_t getSize ()=0
 Return the size of the resource, in bytes. More...
 
virtual std::size_t tell ()=0
 Return the current value of the position indicator. More...
 
virtual bool seek (ptrdiff_t _offset, SeekType _origin)=0
 Set the position indicator to a new position. More...
 
virtual std::size_t read (void *_buffer, std::size_t _size, std::size_t _count)=0
 Read _count element, each of size _size, into _buffer. More...
 
virtual std::string readAll ()
 Reads all data from this resource, and returns it as a string. More...
 

Detailed Description

Resource provides file-like access to a resource loaded from URI.

It is expected that each ResourceRetriever will provide a concrete / instantiation of the Resource class. This interface exposes an similar API to that of the the standard C file manipulation functions.

Member Enumeration Documentation

◆ SeekType

Position to seek relative to.

Enumerator
SEEKTYPE_CUR 

Current position.

SEEKTYPE_END 

End of file.

SEEKTYPE_SET 

Begining of file.

Constructor & Destructor Documentation

◆ ~Resource()

virtual dart::common::Resource::~Resource ( )
virtualdefault

Member Function Documentation

◆ getSize()

virtual std::size_t dart::common::Resource::getSize ( )
pure virtual

Return the size of the resource, in bytes.

Implemented in dart::common::LocalResource.

◆ read()

virtual std::size_t dart::common::Resource::read ( void *  _buffer,
std::size_t  _size,
std::size_t  _count 
)
pure virtual

Read _count element, each of size _size, into _buffer.

Parameters
[out]_bufferPointer to a block of memory with a size of at least (_size * _count) bytes.
[in]_sizeSize, in bytes, of each element.
[in]_countNumber of elements, each of _size bytes.
Note
This method has the same API as the standard fread function.

Implemented in dart::common::LocalResource.

◆ readAll()

std::string dart::common::Resource::readAll ( )
virtual

Reads all data from this resource, and returns it as a string.

Returns
The string retrieved from the resource.
Exceptions
std::runtime_errorwhen failed to read sucessfully.

◆ seek()

virtual bool dart::common::Resource::seek ( ptrdiff_t  _offset,
SeekType  _origin 
)
pure virtual

Set the position indicator to a new position.

Parameters
[in]_offsetOffset, in bytes, relative to _origin.
[in]_originPosition used as the reference of _offset.
Note
This method has the same API as the standard fseek function.

Implemented in dart::common::LocalResource.

◆ tell()

virtual std::size_t dart::common::Resource::tell ( )
pure virtual

Return the current value of the position indicator.

Note
This method has the same API as the standard ftell function.

Implemented in dart::common::LocalResource.