DART  6.7.3
dart::utils::CompositeResourceRetriever Class Reference

CompositeResourceRetriever allows multiple ResourceRetriever to be used interchangably by: (1) associating each ResourceRetriever with a particular URI schema and/or (2) providing a precedence order for trying multiple retrievers. More...

#include <CompositeResourceRetriever.hpp>

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

Public Member Functions

virtual ~CompositeResourceRetriever ()=default
 
void addDefaultRetriever (const common::ResourceRetrieverPtr &_resourceRetriever)
 Add a default ResourceRetriever for all URIs. More...
 
bool addSchemaRetriever (const std::string &_schema, const common::ResourceRetrieverPtr &_resourceRetriever)
 Add a default ResourceRetriever for _schema This ResourceRetriever will be called after URIs that match the specified schema. 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...
 

Private Member Functions

std::vector< common::ResourceRetrieverPtrgetRetrievers (const common::Uri &_uri) const
 

Private Attributes

std::unordered_map< std::string, std::vector< common::ResourceRetrieverPtr > > mResourceRetrievers
 
std::vector< common::ResourceRetrieverPtrmDefaultResourceRetrievers
 

Detailed Description

CompositeResourceRetriever allows multiple ResourceRetriever to be used interchangably by: (1) associating each ResourceRetriever with a particular URI schema and/or (2) providing a precedence order for trying multiple retrievers.

Constructor & Destructor Documentation

◆ ~CompositeResourceRetriever()

virtual dart::utils::CompositeResourceRetriever::~CompositeResourceRetriever ( )
virtualdefault

Member Function Documentation

◆ addDefaultRetriever()

void dart::utils::CompositeResourceRetriever::addDefaultRetriever ( const common::ResourceRetrieverPtr _resourceRetriever)

Add a default ResourceRetriever for all URIs.

This ResourceRetriever will be called after all schema-specific ResourceRetrievers, if any, have failed. This method may be called multiple times. In that case, the ResourceRetrievers will be queried in the same order in which they were added.

◆ addSchemaRetriever()

bool dart::utils::CompositeResourceRetriever::addSchemaRetriever ( const std::string &  _schema,
const common::ResourceRetrieverPtr _resourceRetriever 
)

Add a default ResourceRetriever for _schema This ResourceRetriever will be called after URIs that match the specified schema.

This method may be called multiple times. In that case, the ResourceRetrievers will be queried in the same order in which they were added.

◆ exists()

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

Returns whether the resource specified by a URI exists.

Implements dart::common::ResourceRetriever.

◆ getFilePath()

std::string dart::utils::CompositeResourceRetriever::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.

◆ getRetrievers()

std::vector< common::ResourceRetrieverPtr > dart::utils::CompositeResourceRetriever::getRetrievers ( const common::Uri _uri) const
private

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

◆ retrieve()

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

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

Implements dart::common::ResourceRetriever.

Member Data Documentation

◆ mDefaultResourceRetrievers

std::vector<common::ResourceRetrieverPtr> dart::utils::CompositeResourceRetriever::mDefaultResourceRetrievers
private

◆ mResourceRetrievers

std::unordered_map<std::string, std::vector<common::ResourceRetrieverPtr> > dart::utils::CompositeResourceRetriever::mResourceRetrievers
private