Go to the documentation of this file.
26 #ifndef TESSERACT_COMMON_RESOURCE_LOCATOR_H
27 #define TESSERACT_COMMON_RESOURCE_LOCATOR_H
34 #include <unordered_map>
36 #include <boost/serialization/export.hpp>
56 using Ptr = std::shared_ptr<ResourceLocator>;
57 using ConstPtr = std::shared_ptr<const ResourceLocator>;
67 virtual std::shared_ptr<Resource>
locateResource(
const std::string& url)
const = 0;
75 template <
class Archive>
76 void serialize(Archive& ar,
const unsigned int version);
87 using Ptr = std::shared_ptr<GeneralResourceLocator>;
88 using ConstPtr = std::shared_ptr<const GeneralResourceLocator>;
94 GeneralResourceLocator(
const std::vector<std::string>& environment_variables = {
"TESSERACT_RESOURCE_PATH",
95 "ROS_PACKAGE_PATH" });
104 const std::vector<std::string>& environment_variables = {
"TESSERACT_RESOURCE_PATH",
105 "ROS_PACKAGE_PATH" });
112 std::shared_ptr<Resource>
locateResource(
const std::string& url)
const override;
124 bool addPath(
const std::filesystem::path& path);
138 template <
class Archive>
139 void serialize(Archive& ar,
const unsigned int version);
150 using Ptr = std::shared_ptr<Resource>;
158 virtual bool isFile()
const = 0;
165 virtual std::string
getUrl()
const = 0;
194 template <
class Archive>
195 void serialize(Archive& ar,
const unsigned int version);
204 using Ptr = std::shared_ptr<SimpleLocatedResource>;
205 using ConstPtr = std::shared_ptr<const SimpleLocatedResource>;
223 bool isFile() const override final;
225 std::
string getUrl() const override final;
243 friend class
boost::serialization::access;
245 template <class Archive>
246 void serialize(Archive& ar, const
unsigned int version);
263 bool isFile()
const override final;
264 std::string
getUrl()
const override final;
278 friend class boost::serialization::access;
280 template <
class Archive>
281 void serialize(Archive& ar,
const unsigned int version);
292 #endif // TESSERACT_COMMON_RESOURCE_LOCATOR_H
bool operator==(const SimpleLocatedResource &rhs) const
friend class boost::serialization::access
void serialize(Archive &ar, const unsigned int version)
bool operator!=(const Resource &rhs) const
virtual std::string getUrl() const =0
Get the original URL used to locate the file.
SimpleLocatedResource()=default
This is for boost serialization do not use directly.
GeneralResourceLocator & operator=(const GeneralResourceLocator &)=default
virtual std::shared_ptr< Resource > locateResource(const std::string &url) const =0
Locate a resource based on a URL.
std::function< std::string(const std::string &)> SimpleResourceLocatorFn
bool loadEnvironmentVariable(const std::string &environment_variable)
Load paths from an environment variable.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
SimpleLocatedResource & operator=(const SimpleLocatedResource &)=default
Resource implementation for a local file.
void processToken(const std::string &token)
virtual std::shared_ptr< std::istream > getResourceContentStream() const =0
Get the resource as a std::istream. This function and the returned stream may block.
~SimpleLocatedResource() override=default
virtual bool isFile() const =0
Returns true if the located resource is a local file.
friend class boost::serialization::access
friend class boost::serialization::access
GeneralResourceLocator(const std::vector< std::string > &environment_variables={ "TESSERACT_RESOURCE_PATH", "ROS_PACKAGE_PATH" })
Construct a new General Resource Locator object using the TESSERACT_RESOURCE_PATH environment variabl...
bool operator!=(const GeneralResourceLocator &rhs) const
std::shared_ptr< const ResourceLocator > ConstPtr
bool operator!=(const ResourceLocator &rhs) const
virtual std::vector< uint8_t > getResourceContents() const =0
Get the resource as bytes. This function may block.
Abstract class for resource loaders.
std::vector< uint8_t > getResourceContents() const override final
Get the resource as bytes. This function may block.
void serialize(Archive &ar, const unsigned int version)
Represents resource data available from a file or url.
bool operator==(const ResourceLocator &rhs) const
std::unordered_map< std::string, std::string > package_paths_
bool operator!=(const SimpleLocatedResource &rhs) const
std::string getFilePath() const override final
Get the file path of the resource. Only valid if isFile() is true.
void serialize(Archive &ar, const unsigned int version)
std::vector< uint8_t > bytes_
virtual std::string getFilePath() const =0
Get the file path of the resource. Only valid if isFile() is true.
std::shared_ptr< std::istream > getResourceContentStream() const override final
Get the resource as a std::istream. This function and the returned stream may block.
ResourceLocator::ConstPtr parent_
std::shared_ptr< Resource > locateResource(const std::string &url) const override
Locate a resource based on a URL.
~GeneralResourceLocator() override=default
bool operator==(const Resource &rhs) const
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
bool operator==(const GeneralResourceLocator &rhs) const
std::shared_ptr< Resource > Ptr
virtual ~ResourceLocator()=default
A general resource loaders using environment variable.
ResourceLocator::ConstPtr parent_
std::shared_ptr< ResourceLocator > Ptr
void serialize(Archive &ar, const unsigned int version)
bool isFile() const override final
Returns true if the located resource is a local file.
Resource::Ptr locateResource(const std::string &url) const override final
Locate a resource based on a URL.
std::string getUrl() const override final
Get the original URL used to locate the file.
bool addPath(const std::filesystem::path &path)
Add path to the resource locator.
tesseract_common
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:40