Tesseract 0.28.4
Loading...
Searching...
No Matches
tesseract::common::GeneralResourceLocator Class Reference

A general resource loaders using environment variable. More...

#include <resource_locator.h>

Inheritance diagram for tesseract::common::GeneralResourceLocator:

Public Types

using Ptr = std::shared_ptr<GeneralResourceLocator>
using ConstPtr = std::shared_ptr<const GeneralResourceLocator>
Public Types inherited from tesseract::common::ResourceLocator
using Ptr = std::shared_ptr<ResourceLocator>
using ConstPtr = std::shared_ptr<const ResourceLocator>

Public Member Functions

 GeneralResourceLocator (const std::vector< std::string > &environment_variables={ "TESSERACT_RESOURCE_PATH", "ROS_PACKAGE_PATH", "AMENT_PREFIX_PATH" })
 Construct a new General Resource Locator object using the TESSERACT_RESOURCE_PATH environment variable.
 GeneralResourceLocator (const std::vector< std::filesystem::path > &paths, const std::vector< std::string > &environment_variables={ "TESSERACT_RESOURCE_PATH", "ROS_PACKAGE_PATH", "AMENT_PREFIX_PATH" })
 Construct a new General Resource Locator object using the provided paths and/or the TESSERACT_RESOURCE_PATH environment variable.
 GeneralResourceLocator (const GeneralResourceLocator &)=default
GeneralResourceLocator & operator= (const GeneralResourceLocator &)=default
 GeneralResourceLocator (GeneralResourceLocator &&)=default
GeneralResourceLocator & operator= (GeneralResourceLocator &&)=default
std::shared_ptr< Resource > locateResource (const std::string &url) const override
 Locate a resource based on a URL.
bool operator== (const GeneralResourceLocator &rhs) const
bool operator!= (const GeneralResourceLocator &rhs) const
bool addPath (const std::filesystem::path &path)
 Add path to the resource locator.
bool loadEnvironmentVariable (const std::string &environment_variable)
 Load paths from an environment variable.
Public Member Functions inherited from tesseract::common::ResourceLocator
bool operator== (const ResourceLocator &rhs) const
bool operator!= (const ResourceLocator &rhs) const

Friends

template<class Archive>
friend void::tesseract::common::serialize (Archive &ar, GeneralResourceLocator &obj)

Detailed Description

A general resource loaders using environment variable.

Also can set this environment variable TESSERACT_RESOURCE_PATH with ':' separated directories and then use the directires as package names

Constructor & Destructor Documentation

◆ GeneralResourceLocator() [1/2]

tesseract::common::GeneralResourceLocator::GeneralResourceLocator ( const std::vector< std::string > & environment_variables = { "TESSERACT_RESOURCE_PATH", "ROS_PACKAGE_PATH", "AMENT_PREFIX_PATH" })

Construct a new General Resource Locator object using the TESSERACT_RESOURCE_PATH environment variable.

Parameters
environment_variablesA vector of environment variables to search for paths

◆ GeneralResourceLocator() [2/2]

tesseract::common::GeneralResourceLocator::GeneralResourceLocator ( const std::vector< std::filesystem::path > & paths,
const std::vector< std::string > & environment_variables = { "TESSERACT_RESOURCE_PATH", "ROS_PACKAGE_PATH", "AMENT_PREFIX_PATH" } )

Construct a new General Resource Locator object using the provided paths and/or the TESSERACT_RESOURCE_PATH environment variable.

Parameters
pathsA vector of paths to search for resources
environment_variablesA vector of environment variables to search for paths

Member Function Documentation

◆ locateResource()

std::shared_ptr< Resource > tesseract::common::GeneralResourceLocator::locateResource ( const std::string & url) const
overridevirtual

Locate a resource based on a URL.

Parameters
urlThe URL of the resource
Returns
A shared pointer to a Resource instance, or nullptr if not found

Implements tesseract::common::ResourceLocator.

◆ addPath()

bool tesseract::common::GeneralResourceLocator::addPath ( const std::filesystem::path & path)

Add path to the resource locator.

Parameters
pathThe path to add. Must be a directory
Returns
true Success
false Directory does not exist

◆ loadEnvironmentVariable()

bool tesseract::common::GeneralResourceLocator::loadEnvironmentVariable ( const std::string & environment_variable)

Load paths from an environment variable.

Parameters
environment_variableThe environment variable to load paths from
Returns
true Success
false Environment variable does not exist