Public Member Functions | List of all members
sdf::v11::Root Class Reference

Root class that acts as an entry point to the SDF document model. More...

#include <Root.hh>

Public Member Functions

 Root ()
 Default constructor. More...
 
const sdf::ActorActor () const
 Get a pointer to the actor object if it exists. More...
 
const sdf::ActorActorByIndex (const uint64_t _index) const SDF_DEPRECATED(11.0)
 Get an actor based on an index. More...
 
uint64_t ActorCount () const SDF_DEPRECATED(11.0)
 Get the number of actors. More...
 
bool ActorNameExists (const std::string &_name) const SDF_DEPRECATED(11.0)
 Get whether an actor name exists. More...
 
sdf::ElementPtr Element () const
 Get a pointer to the SDF element that was generated during load. More...
 
const sdf::LightLight () const
 Get a pointer to the light object if it exists. More...
 
const sdf::LightLightByIndex (const uint64_t _index) const SDF_DEPRECATED(11.0)
 Get a light based on an index. More...
 
uint64_t LightCount () const SDF_DEPRECATED(11.0)
 Get the number of lights. More...
 
bool LightNameExists (const std::string &_name) const SDF_DEPRECATED(11.0)
 Get whether a light name exists. More...
 
Errors Load (const SDFPtr _sdf)
 Parse the given SDF pointer, and generate objects based on types specified in the SDF file. More...
 
Errors Load (const SDFPtr _sdf, const ParserConfig &_config)
 Parse the given SDF pointer, and generate objects based on types specified in the SDF file. More...
 
Errors Load (const std::string &_filename)
 Parse the given SDF file, and generate objects based on types specified in the SDF file. More...
 
Errors Load (const std::string &_filename, const ParserConfig &_config)
 Parse the given SDF file, and generate objects based on types specified in the SDF file. More...
 
Errors LoadSdfString (const std::string &_sdf)
 Parse the given SDF string, and generate objects based on types specified in the SDF file. More...
 
Errors LoadSdfString (const std::string &_sdf, const ParserConfig &_config)
 Parse the given SDF string, and generate objects based on types specified in the SDF file. More...
 
const sdf::ModelModel () const
 Get a pointer to the model object if it exists. More...
 
const sdf::ModelModelByIndex (const uint64_t _index) const SDF_DEPRECATED(11.0)
 Get a model based on an index. More...
 
uint64_t ModelCount () const SDF_DEPRECATED(11.0)
 Get the number of models that are immediate (not nested) children of this Root object. More...
 
bool ModelNameExists (const std::string &_name) const SDF_DEPRECATED(11.0)
 Get whether a model name exists. More...
 
void SetVersion (const std::string &_version)
 Set the SDF version string. More...
 
std::string Version () const
 Get the SDF version specified in the parsed file or SDF pointer. More...
 
const WorldWorldByIndex (const uint64_t _index) const
 Get a world based on an index. More...
 
uint64_t WorldCount () const
 Get the number of worlds. More...
 
bool WorldNameExists (const std::string &_name) const
 Get whether a world name exists. More...
 

Detailed Description

Root class that acts as an entry point to the SDF document model.

Multiple worlds can exist in a single SDF file. A user of multiple worlds could run parallel instances of simulation, or offer selection of a world at runtime.

Usage

In this example, a root object is loaded from a file specified in the first command line argument to a program.

sdf::Root root;
sdf::Errors errors = root.Load(argv[1]);
if (errors.empty())
{
std::cerr << "Valid SDF file.\n";
return 0;
}
else
{
std::cerr << "Errors encountered: \n";
for (auto const &e : errors)
{
std::cout << e << std::endl;
}
}

Constructor & Destructor Documentation

◆ Root()

sdf::v11::Root::Root ( )

Default constructor.

Member Function Documentation

◆ Actor()

const sdf::Actor* sdf::v11::Root::Actor ( ) const

Get a pointer to the actor object if it exists.

If there is more than one actor, this will return the first element. If there is already a model or light element, this will return null. This method is preferred to ActorByIndex, as its behavior is consistent with the planned future API. Having more than one Actor, or more than one of Model/Actor/Light is now considered deprecated and should not be relied upon going forward.

Returns
A pointer to the actor, nullptr if it doesn't exist

◆ ActorByIndex()

const sdf::Actor* sdf::v11::Root::ActorByIndex ( const uint64_t  _index) const

Get an actor based on an index.

Parameters
[in]_indexIndex of the actor. The actor should be in the range [0..ActorCount()).
Returns
Pointer to the actor. Nullptr if the index does not exist.
See also
uint64_t ActorCount() const

◆ ActorCount()

uint64_t sdf::v11::Root::ActorCount ( ) const

Get the number of actors.

Returns
Number of actors contained in this Root object.

◆ ActorNameExists()

bool sdf::v11::Root::ActorNameExists ( const std::string &  _name) const

Get whether an actor name exists.

Parameters
[in]_nameName of the actor to check.
Returns
True if there exists an actor with the given name.

◆ Element()

sdf::ElementPtr sdf::v11::Root::Element ( ) const

Get a pointer to the SDF element that was generated during load.

Returns
SDF element pointer. The value will be nullptr if Load has not been called.

◆ Light()

const sdf::Light* sdf::v11::Root::Light ( ) const

Get a pointer to the light object if it exists.

If there is more than one light, this will return the first element. If there is already a model element, this will return null. This method is preferred to LightByIndex, as its behavior is consistent with the planned future API. Having more than one Light, or more than one of Model/Actor/Light is now considered deprecated and should not be relied upon going forward.

Returns
A pointer to the light, nullptr if it doesn't exist

◆ LightByIndex()

const sdf::Light* sdf::v11::Root::LightByIndex ( const uint64_t  _index) const

Get a light based on an index.

Parameters
[in]_indexIndex of the light. The index should be in the range [0..LightCount()).
Returns
Pointer to the light. Nullptr if the index does not exist.
See also
uint64_t LightCount() const

◆ LightCount()

uint64_t sdf::v11::Root::LightCount ( ) const

Get the number of lights.

Returns
Number of lights contained in this Root object.

◆ LightNameExists()

bool sdf::v11::Root::LightNameExists ( const std::string &  _name) const

Get whether a light name exists.

Parameters
[in]_nameName of the light to check.
Returns
True if there exists a light with the given name.

◆ Load() [1/4]

Errors sdf::v11::Root::Load ( const SDFPtr  _sdf)

Parse the given SDF pointer, and generate objects based on types specified in the SDF file.

Parameters
[in]_sdfSDF pointer to parse.
Returns
Errors, which is a vector of Error objects. Each Error includes an error code and message. An empty vector indicates no error.

◆ Load() [2/4]

Errors sdf::v11::Root::Load ( const SDFPtr  _sdf,
const ParserConfig _config 
)

Parse the given SDF pointer, and generate objects based on types specified in the SDF file.

Parameters
[in]_sdfSDF pointer to parse.
[in]_configCustom parser configuration
Returns
Errors, which is a vector of Error objects. Each Error includes an error code and message. An empty vector indicates no error.

◆ Load() [3/4]

Errors sdf::v11::Root::Load ( const std::string &  _filename)

Parse the given SDF file, and generate objects based on types specified in the SDF file.

Parameters
[in]_filenameName of the SDF file to parse.
Returns
Errors, which is a vector of Error objects. Each Error includes an error code and message. An empty vector indicates no error.

◆ Load() [4/4]

Errors sdf::v11::Root::Load ( const std::string &  _filename,
const ParserConfig _config 
)

Parse the given SDF file, and generate objects based on types specified in the SDF file.

Parameters
[in]_filenameName of the SDF file to parse.
[in]_configCustom parser configuration
Returns
Errors, which is a vector of Error objects. Each Error includes an error code and message. An empty vector indicates no error.

◆ LoadSdfString() [1/2]

Errors sdf::v11::Root::LoadSdfString ( const std::string &  _sdf)

Parse the given SDF string, and generate objects based on types specified in the SDF file.

Parameters
[in]_sdfSDF string to parse.
Returns
Errors, which is a vector of Error objects. Each Error includes an error code and message. An empty vector indicates no error.

◆ LoadSdfString() [2/2]

Errors sdf::v11::Root::LoadSdfString ( const std::string &  _sdf,
const ParserConfig _config 
)

Parse the given SDF string, and generate objects based on types specified in the SDF file.

Parameters
[in]_sdfSDF string to parse.
[in]_configCustom parser configuration
Returns
Errors, which is a vector of Error objects. Each Error includes an error code and message. An empty vector indicates no error.

◆ Model()

const sdf::Model* sdf::v11::Root::Model ( ) const

Get a pointer to the model object if it exists.

If there is more than one model, this will return the first element. This method is preferred to ModelByIndex, as its behavior is consistent with the planned future API. Having more than one Model, or more than one of Model/Actor/Light is now considered deprecated and should not be relied upon going forward.

Returns
A pointer to the model, nullptr if it doesn't exist

◆ ModelByIndex()

const sdf::Model* sdf::v11::Root::ModelByIndex ( const uint64_t  _index) const

Get a model based on an index.

Parameters
[in]_indexIndex of the model. The index should be in the range [0..ModelCount()).
Returns
Pointer to the model. Nullptr if the index does not exist.
See also
uint64_t ModelCount() const

◆ ModelCount()

uint64_t sdf::v11::Root::ModelCount ( ) const

Get the number of models that are immediate (not nested) children of this Root object.

Returns
Number of models contained in this Root object.

◆ ModelNameExists()

bool sdf::v11::Root::ModelNameExists ( const std::string &  _name) const

Get whether a model name exists.

Parameters
[in]_nameName of the model to check.
Returns
True if there exists a model with the given name.

◆ SetVersion()

void sdf::v11::Root::SetVersion ( const std::string &  _version)

Set the SDF version string.

Parameters
[in]_versionThe new SDF version.
See also
std::string Version()

◆ Version()

std::string sdf::v11::Root::Version ( ) const

Get the SDF version specified in the parsed file or SDF pointer.

Returns
SDF version string.
See also
void SetVersion(const std::string &_version)

◆ WorldByIndex()

const World* sdf::v11::Root::WorldByIndex ( const uint64_t  _index) const

Get a world based on an index.

Parameters
[in]_indexIndex of the world. The index should be in the range [0..WorldCount()).
Returns
Pointer to the world. Nullptr if the index does not exist.
See also
uint64_t WorldCount() const

◆ WorldCount()

uint64_t sdf::v11::Root::WorldCount ( ) const

Get the number of worlds.

Returns
Number of worlds contained in this Root object.

◆ WorldNameExists()

bool sdf::v11::Root::WorldNameExists ( const std::string &  _name) const

Get whether a world name exists.

Parameters
[in]_nameName of the world to check.
Returns
True if there exists a world with the given name.

The documentation for this class was generated from the following file:
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::Root
Root class that acts as an entry point to the SDF document model.
Definition: Root.hh:54
sdf::v11::Errors
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:106