DART
6.10.1
|
Retrieve local resources specified by package:// URIs by: (1) resolving the package path and (2) passing the resolved URI to another ResourceRetriever. More...
#include <PackageResourceRetriever.hpp>
Public Member Functions | |
PackageResourceRetriever (const common::ResourceRetrieverPtr &_localRetriever=nullptr) | |
Construct a PackageResourceRetriever that uses the specified _localRetriever to load resolved URIs. More... | |
virtual | ~PackageResourceRetriever ()=default |
void | addPackageDirectory (const std::string &_packageName, const std::string &_packageDirectory) |
Specify the directory of a ROS package. 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 | |
const std::vector< std::string > & | getPackagePaths (const std::string &_packageName) const |
bool | resolvePackageUri (const common::Uri &_uri, std::string &_packageName, std::string &_relativePath) const |
Private Attributes | |
common::ResourceRetrieverPtr | mLocalRetriever |
std::unordered_map< std::string, std::vector< std::string > > | mPackageMap |
Retrieve local resources specified by package:// URIs by: (1) resolving the package path and (2) passing the resolved URI to another ResourceRetriever.
This class uses requires you to manually provide the base URI of every package that you wish to resolve using the addPackageDirectory method.
|
explicit |
Construct a PackageResourceRetriever that uses the specified _localRetriever to load resolved URIs.
|
virtualdefault |
void dart::utils::PackageResourceRetriever::addPackageDirectory | ( | const std::string & | _packageName, |
const std::string & | _packageDirectory | ||
) |
Specify the directory of a ROS package.
In your URDF files, you may see strings with a package URI pattern such as:
For us to successfully parse a URDF, we need to be told what the path to the package directory is, using addPackageDirectory(). In this case, suppose the path to the my_robot package is /path/to/my_robot. Then you should use addPackageDirectory("my_robot", "/path/to/my_robot"). Altogether, this implies that a file named "/path/to/my_robot/meshes/mesh_for_my_robot.stl" exists. Whatever you specify as the package directory will end up replacing the 'package keyword' and 'package name' components of the URI string.
You can call this method multiple times with the same _packageName to provide multiple candidates for resolution. This is necessarry if your resources are split between the Catkin devel and source spaces. Multiple candidates will be tested in the same order in which they were added.
This class supports arbitrary URIs for _packageDirectory, as long as they are supported by the _localRetriever passed to the constructor.
|
overridevirtual |
Returns whether the resource specified by a URI exists.
Implements dart::common::ResourceRetriever.
|
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.
|
private |
|
virtualinherited |
Reads all data from the resource of uri, and returns it as a string.
[in] | uri | URI to the resource to be retrieved. |
std::runtime_error | when failed to read sucessfully. |
|
private |
|
overridevirtual |
Returns the resource specified by a URI or nullptr on failure.
Implements dart::common::ResourceRetriever.
|
private |
|
private |