Public Member Functions | List of all members
sdf::v10::Element Class Reference

SDF Element class. More...

#include <sdf/sdf.hh>

Inheritance diagram for sdf::v10::Element:
Inheritance graph
[legend]

Public Member Functions

 Element ()
 Constructor. More...
 
virtual ~Element ()
 Destructor. More...
 
void AddAttribute (const std::string &_key, const std::string &_type, const std::string &_defaultvalue, bool _required, const std::string &_description="")
 Add an attribute value. More...
 
ElementPtr AddElement (const std::string &_name)
 Add a named element. More...
 
void AddElementDescription (ElementPtr _elem)
 Add a new element description. More...
 
void AddValue (const std::string &_type, const std::string &_defaultValue, bool _required, const std::string &_description="")
 Add a value to this Element. More...
 
void AddValue (const std::string &_type, const std::string &_defaultValue, bool _required, const std::string &_minValue, const std::string &_maxValue, const std::string &_description="")
 Add a value to this Element. More...
 
void Clear ()
 Remove all child elements and reset file path and original version. More...
 
void ClearElements ()
 Remove all child elements. More...
 
ElementPtr Clone () const
 Create a copy of this Element. More...
 
void Copy (const ElementPtr _elem)
 Copy values from an Element. More...
 
std::map< std::string, std::size_t > CountNamedElements (const std::string &_type="") const
 Count the number of child elements of the specified element type that have the same name attribute value. More...
 
const std::string & FilePath () const
 Get the path to the SDF document where this element came from. More...
 
template<typename T >
std::pair< T, bool > Get (const std::string &_key, const T &_defaultValue) const
 Get the value of a key. More...
 
template<typename T >
bool Get (const std::string &_key, T &_param, const T &_defaultValue) const
 Get the value of a key. More...
 
template<typename T >
Get (const std::string &_key="") const
 Get the value of a key. More...
 
std::any GetAny (const std::string &_key="") const
 Get the element value/attribute as a std::any. More...
 
ParamPtr GetAttribute (const std::string &_key) const
 Get the param of an attribute. More...
 
ParamPtr GetAttribute (unsigned int _index) const
 Get an attribute using an index. More...
 
size_t GetAttributeCount () const
 Get the number of attributes. More...
 
bool GetAttributeSet (const std::string &_key) const
 Return true if the attribute was set (i.e. More...
 
bool GetCopyChildren () const
 Return true if this Element's child elements should be copied during parsing. More...
 
std::string GetDescription () const
 Get a text description of the element. More...
 
ElementPtr GetElement (const std::string &_name)
 Return a pointer to the child element with the provided name. More...
 
ElementPtr GetElementDescription (const std::string &_key) const
 Get an element description using a key. More...
 
ElementPtr GetElementDescription (unsigned int _index) const
 Get an element description using an index. More...
 
size_t GetElementDescriptionCount () const
 Get the number of element descriptions. More...
 
ElementPtr GetElementImpl (const std::string &_name) const
 Get a pointer to the named element. More...
 
std::set< std::string > GetElementTypeNames () const
 Get set of child element type names. More...
 
ElementPtr GetFirstElement () const
 Get the first child element. More...
 
std::string GetInclude () const
 Get the include filename. More...
 
const std::string & GetName () const
 Get the Element's name. More...
 
ElementPtr GetNextElement (const std::string &_name="") const
 Get the next sibling of this element. More...
 
ElementPtr GetParent () const
 Get a pointer to this Element's parent. More...
 
const std::string & GetRequired () const
 Get the requirement string. More...
 
ParamPtr GetValue () const
 Get the param of the elements value return A Param pointer to the value of this element. More...
 
bool HasAttribute (const std::string &_key) const
 Return true if an attribute exists. More...
 
bool HasElement (const std::string &_name) const
 Return true if the named element exists. More...
 
bool HasElementDescription (const std::string &_name) const
 Return true if an element description exists. More...
 
bool HasUniqueChildNames (const std::string &_type="") const
 Checks whether any child elements of the specified element type have identical name attribute values and returns false if so. More...
 
void InsertElement (ElementPtr _elem)
 Add an element object. More...
 
const std::string & OriginalVersion () const
 Get the spec version that this was originally parsed from. More...
 
void PrintDescription (const std::string &_prefix) const
 Output Element's description to stdout. More...
 
void PrintDocLeftPane (std::string &_html, int _spacing, int &_index) const
 Helper function for SDF::PrintDoc. More...
 
void PrintDocRightPane (std::string &_html, int _spacing, int &_index) const
 Helper function for SDF::PrintDoc. More...
 
void PrintValues (std::string _prefix) const
 Output Element's values to stdout. More...
 
std::string ReferenceSDF () const
 Get the name of the reference SDF element. More...
 
void RemoveChild (ElementPtr _child)
 Remove a child element. More...
 
void RemoveFromParent ()
 Remove this element from its parent. More...
 
void Reset ()
 Call reset on each element and element description before deleting all of them. More...
 
template<typename T >
bool Set (const T &_value)
 Set the value of this element. More...
 
void SetCopyChildren (bool _value)
 Set whether this element should copy its child elements during parsing. More...
 
void SetDescription (const std::string &_desc)
 Set a text description for the element. More...
 
void SetFilePath (const std::string &_path)
 Set the path to the SDF document where this element came from. More...
 
void SetInclude (const std::string &_filename)
 Set the include filename to the passed in filename. More...
 
void SetName (const std::string &_name)
 Set the name of the Element. More...
 
void SetOriginalVersion (const std::string &_version)
 Set the spec version that this was originally parsed from. More...
 
void SetParent (const ElementPtr _parent)
 Set the parent of this Element. More...
 
void SetReferenceSDF (const std::string &_value)
 Set reference SDF element. More...
 
void SetRequired (const std::string &_req)
 Set the requirement type. More...
 
std::string ToString (const std::string &_prefix) const
 Convert the element values to a string representation. More...
 
void Update ()
 Call the Update() callback on each element, as well as the embedded Param. More...
 

Detailed Description

SDF Element class.

Constructor & Destructor Documentation

◆ Element()

sdf::v10::Element::Element ( )

Constructor.

◆ ~Element()

virtual sdf::v10::Element::~Element ( )
virtual

Destructor.

Member Function Documentation

◆ AddAttribute()

void sdf::v10::Element::AddAttribute ( const std::string &  _key,
const std::string &  _type,
const std::string &  _defaultvalue,
bool  _required,
const std::string &  _description = "" 
)

Add an attribute value.

Parameters
[in]_keyKey value.
[in]_typeType of data the attribute will hold.
[in]_defaultValueDefault value for the attribute.
[in]_requiredRequirement string. \as Element::SetRequired.
[in]_descriptionA text description of the attribute.
Exceptions
sdf::AssertionInternalErrorif an invalid type is given.

◆ AddElement()

ElementPtr sdf::v10::Element::AddElement ( const std::string &  _name)

Add a named element.

Parameters
[in]_namethe name of the element to add.
Returns
A pointer to the newly created Element object.

◆ AddElementDescription()

void sdf::v10::Element::AddElementDescription ( ElementPtr  _elem)

Add a new element description.

Parameters
[in]_elemthe Element object to add to the descriptions.

◆ AddValue() [1/2]

void sdf::v10::Element::AddValue ( const std::string &  _type,
const std::string &  _defaultValue,
bool  _required,
const std::string &  _description = "" 
)

Add a value to this Element.

Parameters
[in]_typeType of data the parameter will hold.
[in]_defaultValueDefault value for the parameter.
[in]_requiredRequirement string. \as Element::SetRequired.
[in]_descriptionA text description of the parameter.
Exceptions
sdf::AssertionInternalErrorif an invalid type is given.

◆ AddValue() [2/2]

void sdf::v10::Element::AddValue ( const std::string &  _type,
const std::string &  _defaultValue,
bool  _required,
const std::string &  _minValue,
const std::string &  _maxValue,
const std::string &  _description = "" 
)

Add a value to this Element.

This override allows passing min and max values of the parameter.

Parameters
[in]_typeType of data the parameter will hold.
[in]_defaultValueDefault value for the parameter.
[in]_requiredRequirement string. \as Element::SetRequired.
[in]_minValueMinimum allowed value for the parameter.
[in]_maxValueMaximum allowed value for the parameter.
[in]_descriptionA text description of the parameter.
Exceptions
sdf::AssertionInternalErrorif an invalid type is given.

◆ Clear()

void sdf::v10::Element::Clear ( )

Remove all child elements and reset file path and original version.

◆ ClearElements()

void sdf::v10::Element::ClearElements ( )

Remove all child elements.

◆ Clone()

ElementPtr sdf::v10::Element::Clone ( ) const

Create a copy of this Element.

Returns
A copy of this Element.

◆ Copy()

void sdf::v10::Element::Copy ( const ElementPtr  _elem)

Copy values from an Element.

Parameters
[in]_elemElement to copy value from.

◆ CountNamedElements()

std::map<std::string, std::size_t> sdf::v10::Element::CountNamedElements ( const std::string &  _type = "") const

Count the number of child elements of the specified element type that have the same name attribute value.

Parameters
[in]_typeThe type of Element to check. If empty, count names of all child elements.
Returns
Map from Element names to a count of how many times the name occurs. The count should never be 0. If all 2nd values are 1, then there are exclusively unique names.

◆ FilePath()

const std::string& sdf::v10::Element::FilePath ( ) const

Get the path to the SDF document where this element came from.

Returns
Full path to SDF document.

◆ GetAny()

std::any sdf::v10::Element::GetAny ( const std::string &  _key = "") const

Get the element value/attribute as a std::any.

Parameters
[in]_keyThe key of the attribute. If empty, get the value of the element. Defaults to empty.
Returns
The element as a std::any.

◆ GetAttribute() [1/2]

ParamPtr sdf::v10::Element::GetAttribute ( const std::string &  _key) const

Get the param of an attribute.

Parameters
[in]_keythe name of the attribute.
Returns
The parameter attribute value. NULL if the key is invalid.

◆ GetAttribute() [2/2]

ParamPtr sdf::v10::Element::GetAttribute ( unsigned int  _index) const

Get an attribute using an index.

Parameters
[in]_indexthe index of the attribute to get.
Returns
A Param pointer to the attribute.

◆ GetAttributeCount()

size_t sdf::v10::Element::GetAttributeCount ( ) const

Get the number of attributes.

Returns
The number of attributes.

◆ GetAttributeSet()

bool sdf::v10::Element::GetAttributeSet ( const std::string &  _key) const

Return true if the attribute was set (i.e.

not default value)

Parameters
[in]_keythe key to use to find the attribute.
Returns
True if the attribute is set, false otherwise.

◆ GetCopyChildren()

bool sdf::v10::Element::GetCopyChildren ( ) const

Return true if this Element's child elements should be copied during parsing.

Returns
True to copy child elements during parsing.

◆ GetDescription()

std::string sdf::v10::Element::GetDescription ( ) const

Get a text description of the element.

Returns
The text description of the element.

◆ GetElement()

ElementPtr sdf::v10::Element::GetElement ( const std::string &  _name)

Return a pointer to the child element with the provided name.

A new child element, with the provided name, is added to this element if there is no existing child element.

Remarks
If there are multiple elements with the given tag, it returns the first one.
Parameters
[in]_nameName of the child element to retreive.
Returns
Pointer to the existing child element, or a new child element if an existing child element did not exist.

◆ GetElementDescription() [1/2]

ElementPtr sdf::v10::Element::GetElementDescription ( const std::string &  _key) const

Get an element description using a key.

Parameters
[in]_keythe key to use to find the element.
Returns
An Element pointer to the found element.

◆ GetElementDescription() [2/2]

ElementPtr sdf::v10::Element::GetElementDescription ( unsigned int  _index) const

Get an element description using an index.

Parameters
[in]_indexthe index of the element description to get.
Returns
An Element pointer to the found element.

◆ GetElementDescriptionCount()

size_t sdf::v10::Element::GetElementDescriptionCount ( ) const

Get the number of element descriptions.

Returns
The number of element descriptions.

◆ GetElementImpl()

ElementPtr sdf::v10::Element::GetElementImpl ( const std::string &  _name) const

Get a pointer to the named element.

Parameters
[in]_namethe name of the element to look for.
Returns
A pointer to the named element if found, nullptr otherwise.

◆ GetElementTypeNames()

std::set<std::string> sdf::v10::Element::GetElementTypeNames ( ) const

Get set of child element type names.

Returns
A set of the names of the child elements.

◆ GetFirstElement()

ElementPtr sdf::v10::Element::GetFirstElement ( ) const

Get the first child element.

Returns
A smart pointer to the first child of this element, or sdf::ElementPtr(nullptr) if there are no children.

◆ GetInclude()

std::string sdf::v10::Element::GetInclude ( ) const

Get the include filename.

Returns
The include filename.

◆ GetName()

const std::string& sdf::v10::Element::GetName ( ) const

Get the Element's name.

Returns
The name of this Element.

◆ GetNextElement()

ElementPtr sdf::v10::Element::GetNextElement ( const std::string &  _name = "") const

Get the next sibling of this element.

Parameters
[in]_nameif given then filter siblings by their xml tag.
Remarks
This function does not alter or store any state Repeated calls to "GetNextElement()" with the same string will always return a pointer to the same element.
Returns
A pointer to the next element if it exists, sdf::ElementPtr(nullptr) otherwise.

This can be used in combination with GetFirstElement() to walk the SDF tree. First call parent->GetFirstElement() to get the first child. Call child = child->GetNextElement() to iterate through the children.

◆ GetParent()

ElementPtr sdf::v10::Element::GetParent ( ) const

Get a pointer to this Element's parent.

Returns
Pointer to this Element's parent, NULL if there is no parent.

◆ GetRequired()

const std::string& sdf::v10::Element::GetRequired ( ) const

Get the requirement string.

Returns
The requirement string.
See also
Element::SetRequired

◆ GetValue()

ParamPtr sdf::v10::Element::GetValue ( ) const

Get the param of the elements value return A Param pointer to the value of this element.

◆ HasAttribute()

bool sdf::v10::Element::HasAttribute ( const std::string &  _key) const

Return true if an attribute exists.

Parameters
[in]_keythe key to use to find the attribute.
Returns
True if the attribute exists, false otherwise.

◆ HasElement()

bool sdf::v10::Element::HasElement ( const std::string &  _name) const

Return true if the named element exists.

Parameters
[in]_namethe name of the element to look for.
Returns
True if the named element was found, false otherwise.

◆ HasElementDescription()

bool sdf::v10::Element::HasElementDescription ( const std::string &  _name) const

Return true if an element description exists.

Parameters
[in]_namethe name of the element to find.
Returns
True if the element description exists, false otherwise.

◆ HasUniqueChildNames()

bool sdf::v10::Element::HasUniqueChildNames ( const std::string &  _type = "") const

Checks whether any child elements of the specified element type have identical name attribute values and returns false if so.

Parameters
[in]_typeThe type of Element to check. If empty, check names of all child elements.
Returns
True if all child elements with name attributes of the specified type have unique names, return false if there are duplicated names. Also return true if no elements of the specified type are found.

◆ InsertElement()

void sdf::v10::Element::InsertElement ( ElementPtr  _elem)

Add an element object.

Parameters
[in]_elemthe element object to add.

◆ OriginalVersion()

const std::string& sdf::v10::Element::OriginalVersion ( ) const

Get the spec version that this was originally parsed from.

Returns
Spec version string.

◆ PrintDescription()

void sdf::v10::Element::PrintDescription ( const std::string &  _prefix) const

Output Element's description to stdout.

Parameters
[in]_prefixString value to prefix to the output.

◆ PrintDocLeftPane()

void sdf::v10::Element::PrintDocLeftPane ( std::string &  _html,
int  _spacing,
int &  _index 
) const

Helper function for SDF::PrintDoc.

This generates the SDF html documentation.

Parameters
[out]_htmlAccumulated HTML for output.
[in]_spacingAmount of spacing for this element.
[in]_indexUnique index for this element.

◆ PrintDocRightPane()

void sdf::v10::Element::PrintDocRightPane ( std::string &  _html,
int  _spacing,
int &  _index 
) const

Helper function for SDF::PrintDoc.

This generates the SDF html documentation.

Parameters
[out]_htmlAccumulated HTML for output.
[in]_spacingAmount of spacing for this element.

◆ PrintValues()

void sdf::v10::Element::PrintValues ( std::string  _prefix) const

Output Element's values to stdout.

Parameters
[in]_prefixString value to prefix to the output.

◆ ReferenceSDF()

std::string sdf::v10::Element::ReferenceSDF ( ) const

Get the name of the reference SDF element.

Returns
Name of the reference SDF element.

◆ RemoveChild()

void sdf::v10::Element::RemoveChild ( ElementPtr  _child)

Remove a child element.

Parameters
[in]_childPointer to the child to remove.

◆ RemoveFromParent()

void sdf::v10::Element::RemoveFromParent ( )

Remove this element from its parent.

◆ Reset()

void sdf::v10::Element::Reset ( )

Call reset on each element and element description before deleting all of them.

Also clear out the embedded Param.

◆ SetCopyChildren()

void sdf::v10::Element::SetCopyChildren ( bool  _value)

Set whether this element should copy its child elements during parsing.

Parameters
[in]_valueTrue to copy Element's children.

◆ SetDescription()

void sdf::v10::Element::SetDescription ( const std::string &  _desc)

Set a text description for the element.

Parameters
[in]_descthe text description to set for the element.

◆ SetFilePath()

void sdf::v10::Element::SetFilePath ( const std::string &  _path)

Set the path to the SDF document where this element came from.

Parameters
[in]_pathFull path to SDF document.

◆ SetInclude()

void sdf::v10::Element::SetInclude ( const std::string &  _filename)

Set the include filename to the passed in filename.

Parameters
[in]_filenamethe filename to set the include filename to.

◆ SetName()

void sdf::v10::Element::SetName ( const std::string &  _name)

Set the name of the Element.

Parameters
[in]_nameThe new name for this Element.

◆ SetOriginalVersion()

void sdf::v10::Element::SetOriginalVersion ( const std::string &  _version)

Set the spec version that this was originally parsed from.

Parameters
[in]_versionSpec version string.

◆ SetParent()

void sdf::v10::Element::SetParent ( const ElementPtr  _parent)

Set the parent of this Element.

Parameters
[in]_parentParen for this element.

◆ SetReferenceSDF()

void sdf::v10::Element::SetReferenceSDF ( const std::string &  _value)

Set reference SDF element.

Parameters
[in]_valueName of the reference sdf element.

◆ SetRequired()

void sdf::v10::Element::SetRequired ( const std::string &  _req)

Set the requirement type.

Parameters
[in]_reqRequirement type for this element: 0: Not required. 1: Exactly one element is required. +: One or more elements are required. *: Zero or more elements are required.

◆ ToString()

std::string sdf::v10::Element::ToString ( const std::string &  _prefix) const

Convert the element values to a string representation.

Parameters
[in]_prefixString value to prefix to the output.
Returns
The string representation.

◆ Update()

void sdf::v10::Element::Update ( )

Call the Update() callback on each element, as well as the embedded Param.


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