Public Types | Public Member Functions | Static Public Member Functions | List of all members
sdf::v11::ParserConfig Class Reference

This class contains configuration options for the libsdformat parser. More...

#include <ParserConfig.hh>

Public Types

using SchemeToPathMap = std::map< std::string, std::vector< std::string > >
 type alias for the map from URI scheme to search directories More...
 

Public Member Functions

 ParserConfig ()
 Default constructor. More...
 
void AddURIPath (const std::string &_uri, const std::string &_path)
 Associate paths to a URI. More...
 
const std::vector< CustomModelParser > & CustomModelParsers () const
 Get the registered custom model parsers. More...
 
EnforcementPolicy DeprecatedElementsPolicy () const
 Get the current deprecated elements policy. More...
 
const std::function< std::string(const std::string &)> & FindFileCallback () const
 Get the find file callback function. More...
 
void RegisterCustomModelParser (CustomModelParser _modelParser)
 Registers a custom model parser. More...
 
void ResetDeprecatedElementsPolicy ()
 Resets the policy for deprecated elements so that it follows WarningsPolicy. More...
 
void SetDeprecatedElementsPolicy (EnforcementPolicy _policy)
 Set the policy for deprecated elements. More...
 
void SetFindCallback (std::function< std::string(const std::string &)> _cb)
 Set the callback to use when libsdformat can't find a file. More...
 
void SetUnrecognizedElementsPolicy (EnforcementPolicy _policy)
 Set the policy for unrecogonized elements without an xmlns. More...
 
void SetWarningsPolicy (EnforcementPolicy _policy)
 Set the warning enforcment policy. More...
 
EnforcementPolicy UnrecognizedElementsPolicy () const
 Get the current unrecognized elements policy. More...
 
const SchemeToPathMapURIPathMap () const
 Get the URI scheme to search directories map. More...
 
EnforcementPolicy WarningsPolicy () const
 Get the current warning enforcement policy. More...
 

Static Public Member Functions

static ParserConfigGlobalConfig ()
 Mutable access to a singleton ParserConfig that serves as the global ParserConfig object for all parsing operations that do not specify their own ParserConfig. More...
 

Detailed Description

This class contains configuration options for the libsdformat parser.

The configuration options include:

For backward compatibility, the functions sdf::setFindCallback() and sdf::addURIPath() update a singleton ParserConfig object, which can be retrieved by ParserConfig::GlobalConfig().

The functions sdf::readFile(), sdf::readString(), and sdf::Root::Load() have overloads that take a ParserConfig object. If the ParserConfig object is omitted, these functions will use the singleton ParserConfig object.

Example: To set an additional URI scheme search directory without affecting the global config,

// Copy the global config
// Add the new scheme to the config
config.AddURIPath("newScheme://", "path/to/directory");
// Use the new config when loading a new SDFormat file
sdf::Root root;
root.Load("path/to/file.sdf", config);

Member Typedef Documentation

◆ SchemeToPathMap

using sdf::v11::ParserConfig::SchemeToPathMap = std::map<std::string, std::vector<std::string> >

type alias for the map from URI scheme to search directories

Constructor & Destructor Documentation

◆ ParserConfig()

sdf::v11::ParserConfig::ParserConfig ( )

Default constructor.

Member Function Documentation

◆ AddURIPath()

void sdf::v11::ParserConfig::AddURIPath ( const std::string &  _uri,
const std::string &  _path 
)

Associate paths to a URI.

Example paramters: "model://", "/usr/share/models:~/.gazebo/models"

Parameters
[in]_uriURI that will be mapped to _path
[in]_pathColon separated set of paths.
See also
sdf::findFile() for the order of search operations

◆ CustomModelParsers()

const std::vector<CustomModelParser>& sdf::v11::ParserConfig::CustomModelParsers ( ) const

Get the registered custom model parsers.

◆ DeprecatedElementsPolicy()

EnforcementPolicy sdf::v11::ParserConfig::DeprecatedElementsPolicy ( ) const

Get the current deprecated elements policy.

By default, the policy is the same as the overall WarningsPolicy, but it can be overriden by SetDeprecatedElementsPolicy. Once it is overriden, changing SetWarningsPolicy will not change the value of DeprecatedElementsPolicy unless ResetDeprecatedElementsPolicy is called.

Returns
The deperacted elements policy enum value

◆ FindFileCallback()

const std::function<std::string(const std::string &)>& sdf::v11::ParserConfig::FindFileCallback ( ) const

Get the find file callback function.

Returns
Immutable reference to the find file callback function

◆ GlobalConfig()

static ParserConfig& sdf::v11::ParserConfig::GlobalConfig ( )
static

Mutable access to a singleton ParserConfig that serves as the global ParserConfig object for all parsing operations that do not specify their own ParserConfig.

Returns
A mutable reference to the singleton ParserConfig object

◆ RegisterCustomModelParser()

void sdf::v11::ParserConfig::RegisterCustomModelParser ( CustomModelParser  _modelParser)

Registers a custom model parser.

Parameters
[in]_modelParserCallback as described in sdf/InterfaceElements.hh.

◆ ResetDeprecatedElementsPolicy()

void sdf::v11::ParserConfig::ResetDeprecatedElementsPolicy ( )

Resets the policy for deprecated elements so that it follows WarningsPolicy.

◆ SetDeprecatedElementsPolicy()

void sdf::v11::ParserConfig::SetDeprecatedElementsPolicy ( EnforcementPolicy  _policy)

Set the policy for deprecated elements.

Parameters
[in]_policyThe deprecated elements enforcement policy

◆ SetFindCallback()

void sdf::v11::ParserConfig::SetFindCallback ( std::function< std::string(const std::string &)>  _cb)

Set the callback to use when libsdformat can't find a file.

The callback should return a complete path to the requested file, or an empty string if the file was not found in the callback. Generally, the input argument is a URI or a file path (absolute or relative) obtained from a //include/uri element. For example, if the value custom://model_name is given in a //include/uri, sdf::findFile() may invoke the callback with the argument custom://model_name if it is unable to find a file using the steps listed in sdf::findfile().

Note, however, the input is not limited to URIs and file paths, and it is left up to the callback to interpret the contents of the input string.

Parameters
[in]_cbThe callback function.
See also
sdf::findFile() for the order of search operations

◆ SetUnrecognizedElementsPolicy()

void sdf::v11::ParserConfig::SetUnrecognizedElementsPolicy ( EnforcementPolicy  _policy)

Set the policy for unrecogonized elements without an xmlns.

Parameters
[in]_policyThe unrecognized elements enforcement policy

◆ SetWarningsPolicy()

void sdf::v11::ParserConfig::SetWarningsPolicy ( EnforcementPolicy  _policy)

Set the warning enforcment policy.

Parameters
[in]_policypolicy enum value to set

◆ UnrecognizedElementsPolicy()

EnforcementPolicy sdf::v11::ParserConfig::UnrecognizedElementsPolicy ( ) const

Get the current unrecognized elements policy.

Returns
The unrecognized elements policy enum value

◆ URIPathMap()

const SchemeToPathMap& sdf::v11::ParserConfig::URIPathMap ( ) const

Get the URI scheme to search directories map.

Returns
Immutable reference to the URI scheme to search directories map

◆ WarningsPolicy()

EnforcementPolicy sdf::v11::ParserConfig::WarningsPolicy ( ) const

Get the current warning enforcement policy.

Returns
The warning enforcement policy enum value

The documentation for this class was generated from the following file:
sdf::v11::ParserConfig::GlobalConfig
static ParserConfig & GlobalConfig()
Mutable access to a singleton ParserConfig that serves as the global ParserConfig object for all pars...
sdf::v11::ParserConfig
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:84
sdf::v11::Root::Load
Errors Load(const std::string &_filename)
Parse the given SDF file, and generate objects based on types specified in the SDF file.
sdf::v11::ParserConfig::AddURIPath
void AddURIPath(const std::string &_uri, const std::string &_path)
Associate paths to a URI.
sdf::v11::Root
Root class that acts as an entry point to the SDF document model.
Definition: Root.hh:54