DART  6.7.3
dart::utils::DartResourceRetriever Class Reference

Retrieve local resources from sample data files given file URI. More...

#include <DartResourceRetriever.hpp>

Inheritance diagram for dart::utils::DartResourceRetriever:
dart::common::ResourceRetriever

Public Member Functions

 DartResourceRetriever ()
 Constructor. More...
 
 ~DartResourceRetriever () override=default
 Destructor. More...
 
bool exists (const common::Uri &uri) override
 Returns whether the resource specified by a URI exists. More...
 
common::ResourcePtr retrieve (const common::Uri &uri) override
 Returns the resource specified by a URI or nullptr on failure. More...
 
std::string getFilePath (const common::Uri &uri) override
 Returns absolute file path to uri; an empty string if unavailable. More...
 
virtual std::string readAll (const Uri &uri)
 Reads all data from the resource of uri, and returns it as a string. More...
 

Static Public Member Functions

template<typename... Args>
static std::shared_ptr< DartResourceRetrievercreate (Args &&... args)
 

Private Member Functions

void addDataDirectory (const std::string &packageDirectory)
 
bool resolveDataUri (const common::Uri &uri, std::string &relativePath) const
 

Private Attributes

common::ResourceRetrieverPtr mLocalRetriever
 
std::vector< std::string > mDataDirectories
 

Detailed Description

Retrieve local resources from sample data files given file URI.

The scheme and authority should be "file" and "sample", respectively.

Example of a sample data URI:

"dart://sample/skel/shapes.skel"
\______________/
|
file path with respect to
the sample data directory

DartResourceRetriever searches files in the following order: 1) Preprocessor, DART_DATA_LOCAL_PATH: Path to the data directory in the source directory (e.g., [DART_SRC_ROOT]/data/). 2) Preprocessor, DART_DATA_GLOBAL_PATH: Path to the data directory installed in a system directory. The location can be varied depending on OS (e.g., Linux: /usr/local/share/doc/dart/data/). 3) environment variable, DART_DATA_PATH: Path to the data directory specified by the user.

Constructor & Destructor Documentation

◆ DartResourceRetriever()

dart::utils::DartResourceRetriever::DartResourceRetriever ( )

Constructor.

◆ ~DartResourceRetriever()

dart::utils::DartResourceRetriever::~DartResourceRetriever ( )
overridedefault

Destructor.

Member Function Documentation

◆ addDataDirectory()

void dart::utils::DartResourceRetriever::addDataDirectory ( const std::string &  packageDirectory)
private

◆ create()

template<typename... Args>
static std::shared_ptr<DartResourceRetriever> dart::utils::DartResourceRetriever::create ( Args &&...  args)
inlinestatic

◆ exists()

bool dart::utils::DartResourceRetriever::exists ( const common::Uri _uri)
overridevirtual

Returns whether the resource specified by a URI exists.

Implements dart::common::ResourceRetriever.

◆ getFilePath()

std::string dart::utils::DartResourceRetriever::getFilePath ( const common::Uri uri)
overridevirtual

Returns absolute file path to uri; an empty string if unavailable.

This base class returns an empty string by default.

Reimplemented from dart::common::ResourceRetriever.

◆ readAll()

std::string dart::common::ResourceRetriever::readAll ( const Uri uri)
virtualinherited

Reads all data from the resource of uri, and returns it as a string.

Parameters
[in]uriURI to the resource to be retrieved.
Returns
The string retrieved from the resource.
Exceptions
std::runtime_errorwhen failed to read sucessfully.

◆ resolveDataUri()

bool dart::utils::DartResourceRetriever::resolveDataUri ( const common::Uri uri,
std::string &  relativePath 
) const
private

◆ retrieve()

common::ResourcePtr dart::utils::DartResourceRetriever::retrieve ( const common::Uri _uri)
overridevirtual

Returns the resource specified by a URI or nullptr on failure.

Implements dart::common::ResourceRetriever.

Member Data Documentation

◆ mDataDirectories

std::vector<std::string> dart::utils::DartResourceRetriever::mDataDirectories
private

◆ mLocalRetriever

common::ResourceRetrieverPtr dart::utils::DartResourceRetriever::mLocalRetriever
private