#include <sdf/sdf.hh>
Inherits enable_shared_from_this< Element >.
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 | 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 std::vector< std::string > &_ignoreElements) const |
Count the number of child elements of the specified element type that have the same name attribute value with the exception of elements listed in _ignoreElements . 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... | |
ElementPtr | FindElement (const std::string &_name) |
Return a pointer to the child element with the provided name. More... | |
ElementConstPtr | FindElement (const std::string &_name) const |
Return a pointer to the child element with the provided name. 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 > | |
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... | |
bool | GetExplicitlySetInFile () const |
Return if the element was been explicitly set in the file. 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 std::vector< std::string > &_ignoreElements) const |
Checks whether any child elements of the specified element type, except those listed in _ignoreElements , have identical name attribute values and returns false if so. 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 (const std::string &_prefix, bool _includeDefaultElements, bool _includeDefaultAttributes) const |
Output Element's values to stdout. 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 | RemoveAllAttributes () |
Removes all attributes. More... | |
void | RemoveAttribute (const std::string &_key) |
Remove an attribute. 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 | SetExplicitlySetInFile (const bool _value) |
Set if the element and children where set or default in the original file. 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... | |
std::string | ToString (const std::string &_prefix, bool _includeDefaultElements, bool _includeDefaultAttributes) 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... | |
Static Public Member Functions | |
static std::vector< std::string > | NameUniquenessExceptions () |
List of elements to which exceptions are made when checking for name uniqueness. More... | |
sdf::v9::Element::Element | ( | ) |
Constructor.
|
virtual |
Destructor.
void sdf::v9::Element::AddAttribute | ( | const std::string & | _key, |
const std::string & | _type, | ||
const std::string & | _defaultvalue, | ||
bool | _required, | ||
const std::string & | _description = "" |
||
) |
Add an attribute value.
[in] | _key | Key value. |
[in] | _type | Type of data the attribute will hold. |
[in] | _defaultValue | Default value for the attribute. |
[in] | _required | Requirement string. \as Element::SetRequired. |
[in] | _description | A text description of the attribute. |
sdf::AssertionInternalError | if an invalid type is given. |
ElementPtr sdf::v9::Element::AddElement | ( | const std::string & | _name | ) |
Add a named element.
[in] | _name | the name of the element to add. |
void sdf::v9::Element::AddElementDescription | ( | ElementPtr | _elem | ) |
Add a new element description.
[in] | _elem | the Element object to add to the descriptions. |
void sdf::v9::Element::AddValue | ( | const std::string & | _type, |
const std::string & | _defaultValue, | ||
bool | _required, | ||
const std::string & | _description = "" |
||
) |
Add a value to this Element.
[in] | _type | Type of data the attribute will hold. |
[in] | _defaultValue | Default value for the attribute. |
[in] | _required | Requirement string. \as Element::SetRequired. |
[in] | _description | A text description of the attribute. |
sdf::AssertionInternalError | if an invalid type is given. |
void sdf::v9::Element::Clear | ( | ) |
Remove all child elements and reset file path and original version.
void sdf::v9::Element::ClearElements | ( | ) |
Remove all child elements.
ElementPtr sdf::v9::Element::Clone | ( | ) | const |
void sdf::v9::Element::Copy | ( | const ElementPtr | _elem | ) |
std::map<std::string, std::size_t> sdf::v9::Element::CountNamedElements | ( | const std::string & | _type, |
const std::vector< std::string > & | _ignoreElements | ||
) | const |
Count the number of child elements of the specified element type that have the same name attribute value with the exception of elements listed in _ignoreElements
.
[in] | _type | The type of Element to check. If empty, count names of all child elements. |
[in] | _ignoreElements | A list of child element types to ignore when checking for uniqueness. |
std::map<std::string, std::size_t> sdf::v9::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.
[in] | _type | The type of Element to check. If empty, count names of all child elements. |
const std::string& sdf::v9::Element::FilePath | ( | ) | const |
ElementPtr sdf::v9::Element::FindElement | ( | const std::string & | _name | ) |
Return a pointer to the child element with the provided name.
Unlike GetElement, this does not create a new child element if it fails to find an existing element.
[in] | _name | Name of the child element to retreive. |
ElementConstPtr sdf::v9::Element::FindElement | ( | const std::string & | _name | ) | const |
Return a pointer to the child element with the provided name.
Unlike GetElement, this does not create a new child element if it fails to find an existing element.
[in] | _name | Name of the child element to retreive. |
std::any sdf::v9::Element::GetAny | ( | const std::string & | _key = "" | ) | const |
Get the element value/attribute as a std::any.
[in] | _key | The key of the attribute. If empty, get the value of the element. Defaults to empty. |
ParamPtr sdf::v9::Element::GetAttribute | ( | const std::string & | _key | ) | const |
Get the param of an attribute.
[in] | _key | the name of the attribute. |
ParamPtr sdf::v9::Element::GetAttribute | ( | unsigned int | _index | ) | const |
Get an attribute using an index.
[in] | _index | the index of the attribute to get. |
size_t sdf::v9::Element::GetAttributeCount | ( | ) | const |
Get the number of attributes.
bool sdf::v9::Element::GetAttributeSet | ( | const std::string & | _key | ) | const |
Return true if the attribute was set (i.e.
not default value)
[in] | _key | the key to use to find the attribute. |
bool sdf::v9::Element::GetCopyChildren | ( | ) | const |
Return true if this Element's child elements should be copied during parsing.
std::string sdf::v9::Element::GetDescription | ( | ) | const |
Get a text description of the element.
ElementPtr sdf::v9::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. If this is not desired see FindElement
[in] | _name | Name of the child element to retreive. |
ElementPtr sdf::v9::Element::GetElementDescription | ( | const std::string & | _key | ) | const |
Get an element description using a key.
[in] | _key | the key to use to find the element. |
ElementPtr sdf::v9::Element::GetElementDescription | ( | unsigned int | _index | ) | const |
Get an element description using an index.
[in] | _index | the index of the element description to get. |
size_t sdf::v9::Element::GetElementDescriptionCount | ( | ) | const |
Get the number of element descriptions.
ElementPtr sdf::v9::Element::GetElementImpl | ( | const std::string & | _name | ) | const |
Get a pointer to the named element.
[in] | _name | the name of the element to look for. |
std::set<std::string> sdf::v9::Element::GetElementTypeNames | ( | ) | const |
Get set of child element type names.
bool sdf::v9::Element::GetExplicitlySetInFile | ( | ) | const |
Return if the element was been explicitly set in the file.
ElementPtr sdf::v9::Element::GetFirstElement | ( | ) | const |
Get the first child element.
std::string sdf::v9::Element::GetInclude | ( | ) | const |
Get the include filename.
const std::string& sdf::v9::Element::GetName | ( | ) | const |
ElementPtr sdf::v9::Element::GetNextElement | ( | const std::string & | _name = "" | ) | const |
Get the next sibling of this element.
[in] | _name | if given then filter siblings by their xml tag. |
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.
ElementPtr sdf::v9::Element::GetParent | ( | ) | const |
const std::string& sdf::v9::Element::GetRequired | ( | ) | const |
ParamPtr sdf::v9::Element::GetValue | ( | ) | const |
Get the param of the elements value return A Param pointer to the value of this element.
bool sdf::v9::Element::HasAttribute | ( | const std::string & | _key | ) | const |
Return true if an attribute exists.
[in] | _key | the key to use to find the attribute. |
bool sdf::v9::Element::HasElement | ( | const std::string & | _name | ) | const |
Return true if the named element exists.
[in] | _name | the name of the element to look for. |
bool sdf::v9::Element::HasElementDescription | ( | const std::string & | _name | ) | const |
Return true if an element description exists.
[in] | _name | the name of the element to find. |
bool sdf::v9::Element::HasUniqueChildNames | ( | const std::string & | _type, |
const std::vector< std::string > & | _ignoreElements | ||
) | const |
Checks whether any child elements of the specified element type, except those listed in _ignoreElements
, have identical name attribute values and returns false if so.
[in] | _type | The type of Element to check. If empty, check names of all child elements. |
[in] | _ignoreElements | A list of child element types to ignore when checking for uniqueness. |
bool sdf::v9::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.
[in] | _type | The type of Element to check. If empty, check names of all child elements. |
void sdf::v9::Element::InsertElement | ( | ElementPtr | _elem | ) |
Add an element object.
[in] | _elem | the element object to add. |
|
static |
List of elements to which exceptions are made when checking for name uniqueness.
const std::string& sdf::v9::Element::OriginalVersion | ( | ) | const |
Get the spec version that this was originally parsed from.
void sdf::v9::Element::PrintDescription | ( | const std::string & | _prefix | ) | const |
Output Element's description to stdout.
[in] | _prefix | String value to prefix to the output. |
void sdf::v9::Element::PrintDocLeftPane | ( | std::string & | _html, |
int | _spacing, | ||
int & | _index | ||
) | const |
Helper function for SDF::PrintDoc.
This generates the SDF html documentation.
[out] | _html | Accumulated HTML for output. |
[in] | _spacing | Amount of spacing for this element. |
[in] | _index | Unique index for this element. |
void sdf::v9::Element::PrintDocRightPane | ( | std::string & | _html, |
int | _spacing, | ||
int & | _index | ||
) | const |
Helper function for SDF::PrintDoc.
This generates the SDF html documentation.
[out] | _html | Accumulated HTML for output. |
[in] | _spacing | Amount of spacing for this element. |
void sdf::v9::Element::PrintValues | ( | const std::string & | _prefix, |
bool | _includeDefaultElements, | ||
bool | _includeDefaultAttributes | ||
) | const |
Output Element's values to stdout.
[in] | _prefix | String value to prefix to the output. |
[in] | _includeDefaultElements | flag to print default elements. |
[in] | _includeDefaultAttributes | flag to print default attributes. |
void sdf::v9::Element::PrintValues | ( | std::string | _prefix | ) | const |
Output Element's values to stdout.
[in] | _prefix | String value to prefix to the output. |
std::string sdf::v9::Element::ReferenceSDF | ( | ) | const |
void sdf::v9::Element::RemoveAllAttributes | ( | ) |
Removes all attributes.
void sdf::v9::Element::RemoveAttribute | ( | const std::string & | _key | ) |
Remove an attribute.
[in] | _key | the key of the attribute. |
void sdf::v9::Element::RemoveChild | ( | ElementPtr | _child | ) |
Remove a child element.
[in] | _child | Pointer to the child to remove. |
void sdf::v9::Element::RemoveFromParent | ( | ) |
Remove this element from its parent.
void sdf::v9::Element::Reset | ( | ) |
Call reset on each element and element description before deleting all of them.
Also clear out the embedded Param.
void sdf::v9::Element::SetCopyChildren | ( | bool | _value | ) |
Set whether this element should copy its child elements during parsing.
[in] | _value | True to copy Element's children. |
void sdf::v9::Element::SetDescription | ( | const std::string & | _desc | ) |
Set a text description for the element.
[in] | _desc | the text description to set for the element. |
void sdf::v9::Element::SetExplicitlySetInFile | ( | const bool | _value | ) |
Set if the element and children where set or default in the original file.
This is meant to be used by the parser to indicate whether the element was set by the user in the original file or added by default during parsing.
[in] | _value | True if the element was set |
void sdf::v9::Element::SetFilePath | ( | const std::string & | _path | ) |
void sdf::v9::Element::SetInclude | ( | const std::string & | _filename | ) |
Set the include filename to the passed in filename.
[in] | _filename | the filename to set the include filename to. |
void sdf::v9::Element::SetName | ( | const std::string & | _name | ) |
void sdf::v9::Element::SetOriginalVersion | ( | const std::string & | _version | ) |
Set the spec version that this was originally parsed from.
[in] | _version | Spec version string. |
void sdf::v9::Element::SetParent | ( | const ElementPtr | _parent | ) |
Set the parent of this Element.
[in] | _parent | Paren for this element. |
void sdf::v9::Element::SetReferenceSDF | ( | const std::string & | _value | ) |
Set reference SDF element.
[in] | _value | Name of the reference sdf element. |
void sdf::v9::Element::SetRequired | ( | const std::string & | _req | ) |
Set the requirement type.
[in] | _req | Requirement 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. |
std::string sdf::v9::Element::ToString | ( | const std::string & | _prefix | ) | const |
Convert the element values to a string representation.
[in] | _prefix | String value to prefix to the output. |
std::string sdf::v9::Element::ToString | ( | const std::string & | _prefix, |
bool | _includeDefaultElements, | ||
bool | _includeDefaultAttributes | ||
) | const |
Convert the element values to a string representation.
Current behavior of ToString(const std::string &_prefix) can be achieved by calling this function with _includeDefaultElements=true and _includeDefaultAttributes=false
[in] | _prefix | String value to prefix to the output. |
[in] | _includeDefaultElements | flag to include default elements. |
[in] | _includeDefaultAttributes | flag to include default attributes. |
void sdf::v9::Element::Update | ( | ) |