Drake
Drake C++ Documentation
ScopedName Class Referencefinal

Detailed Description

A delimited string name for a multibody element, e.g., "robot1::torso".

The name is composed of two semantically separate pieces – the element name is the local name for the element (e.g., a joint, body, frame, etc.) and the namespace name is the location of that element within the tree. For "robot1::torso" the namespace name is "robot1" and the element name is "torso".

The namespace name typically refers to the model instance name that contains the element. Some temporary scoped names do not use a namespace (e.g., temporary values created during input file parsing), in which case the namespace name can be empty. The namespace name will never start or end with "::".

The element name is never empty, unless the ScopedName was default-constructed or moved-from. The element name will never contain the delimiter string "::".

When there is no namespace, the scoped name does not contain a leading "::", e.g., for the element name "box" without any namespace, the scoped name is "box" not "::box".

The namespace name may contain the "::" delimiter in the middle of the name (possibly multiple times), e.g., for "robot1::left::arm::end_frame" the namespace name is "robot1::left::arm" and the element is name "end_frame".

This class does not treat a single colon (":") specially. Those can appear in either namespace names or element names.

#include <drake/multibody/tree/scoped_name.h>

Public Member Functions

 ScopedName ()=default
 Creates an empty name. More...
 
 ScopedName (std::string_view namespace_name, std::string_view element_name)
 Creates a ScopedName for the given namespace_name and element_name. More...
 
std::string_view get_namespace () const
 Returns the namespace portion of this scoped name, e.g., "robot1". More...
 
std::string_view get_element () const
 Returns the element portion of this scoped name, e.g., "torso". More...
 
std::string_view get_full () const
 Returns the full ScopedName as a string, e.g., "robot1::torso". More...
 
std::string to_string () const
 Returns get_full() as a string value instead of a string_view. More...
 
void set_namespace (std::string_view namespace_name)
 Replaces the namespace name of this object, leaving the element name unchanged. More...
 
void set_element (std::string_view element_name)
 Replaces the element name of this object, leaving the namespace name unchanged. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 ScopedName (const ScopedName &)=default
 
ScopedNameoperator= (const ScopedName &)=default
 
 ScopedName (ScopedName &&)=default
 
ScopedNameoperator= (ScopedName &&)=default
 

Static Public Member Functions

static std::optional< ScopedNameMake (std::string_view namespace_name, std::string_view element_name)
 Creates a ScopedName for the given namespace_name and element_name. More...
 
static ScopedName Join (std::string_view name1, std::string_view name2)
 Creates a ScopedName for the given name1::name2. More...
 
static ScopedName Parse (std::string scoped_name)
 Parses the given scoped_name string. More...
 

Constructor & Destructor Documentation

◆ ScopedName() [1/4]

ScopedName ( const ScopedName )
default

◆ ScopedName() [2/4]

ScopedName ( ScopedName &&  )
default

◆ ScopedName() [3/4]

ScopedName ( )
default

Creates an empty name.

◆ ScopedName() [4/4]

ScopedName ( std::string_view  namespace_name,
std::string_view  element_name 
)

Creates a ScopedName for the given namespace_name and element_name.

Exceptions
std::exceptionif namespace_name starts or ends with "::".
std::exceptionif element_name contains "::" or is empty.
See also
ScopedName::Make() to use a null return value instead of exceptions.
ScopedName::Join() for automatic cleanup of "::" tokens.

Member Function Documentation

◆ get_element()

std::string_view get_element ( ) const

Returns the element portion of this scoped name, e.g., "torso".

This is the local name of the joint, body, etc. within the model instance. It is never empty unless this ScopedName was default-constructed or moved-from.

◆ get_full()

std::string_view get_full ( ) const

Returns the full ScopedName as a string, e.g., "robot1::torso".

It is never empty unless this ScopedName was default-constructed or moved-from.

◆ get_namespace()

std::string_view get_namespace ( ) const

Returns the namespace portion of this scoped name, e.g., "robot1".

This is typically the model instance name. This is typically the model instance name but can be empty (see class overview for details).

◆ Join()

static ScopedName Join ( std::string_view  name1,
std::string_view  name2 
)
static

Creates a ScopedName for the given name1::name2.

Unlike the constructor or ScopedName::Make(), this function allows "::" in either name. Any leading or trailing "::" on the names are removed before joining. After joining, the final word after all "::"s is the element name, and everything prior is the namespace name.

◆ Make()

static std::optional<ScopedName> Make ( std::string_view  namespace_name,
std::string_view  element_name 
)
static

Creates a ScopedName for the given namespace_name and element_name.

Returns nullopt if namespace_name starts or ends with "::", or if element_name contains "::" or is empty.

See also
ScopedName::Join() for automatic coalescing of "::" tokens.

◆ operator=() [1/2]

ScopedName& operator= ( ScopedName &&  )
default

◆ operator=() [2/2]

ScopedName& operator= ( const ScopedName )
default

◆ Parse()

static ScopedName Parse ( std::string  scoped_name)
static

Parses the given scoped_name string.

Any leading or trailing "::"s on the name are removed (even multiple copies like "::::" are removed).

◆ set_element()

void set_element ( std::string_view  element_name)

Replaces the element name of this object, leaving the namespace name unchanged.

Exceptions
std::exceptionif element_name contains "::" or is empty.

◆ set_namespace()

void set_namespace ( std::string_view  namespace_name)

Replaces the namespace name of this object, leaving the element name unchanged.

The namespace name is allowed to be empty.

Exceptions
std::exceptionif namespace_name starts or ends with "::".

◆ to_string()

std::string to_string ( ) const

Returns get_full() as a string value instead of a string_view.


The documentation for this class was generated from the following file: