17 #ifndef SDF_ELEMENT_HH_
18 #define SDF_ELEMENT_HH_
29 #include "sdf/sdf_config.h"
37 #pragma warning(disable: 4251)
45 inline namespace SDF_VERSION_NAMESPACE {
69 public std::enable_shared_from_this<Element>
96 public:
void SetName(
const std::string &_name);
148 int _spacing,
int &_index)
const;
156 int _spacing,
int &_index)
const;
161 public: std::string
ToString(
const std::string &_prefix)
const;
171 const std::string &_type,
172 const std::string &_defaultvalue,
174 const std::string &_description=
"");
183 const std::string &_defaultValue,
bool _required,
184 const std::string &_description=
"");
237 public: std::any
GetAny(
const std::string &_key =
"")
const;
245 public:
template<
typename T>
246 T Get(
const std::string &_key =
"")
const;
254 public:
template<
typename T>
255 std::pair<T, bool> Get(
const std::string &_key,
256 const T &_defaultValue)
const;
264 public:
template<
typename T>
265 bool Get(
const std::string &_key,
267 const T &_defaultValue)
const;
272 public:
template<
typename T>
273 bool Set(
const T &_value);
318 public: std::map<std::string, std::size_t>
408 private:
void ToString(
const std::string &_prefix,
409 std::ostringstream &_out)
const;
414 private:
void PrintValuesImpl(
const std::string &_prefix,
415 std::ostringstream &_out)
const;
425 private:
ParamPtr CreateParam(
const std::string &_key,
426 const std::string &_type,
427 const std::string &_defaultValue,
429 const std::string &_description=
"");
433 private: std::unique_ptr<ElementPrivate> dataPtr;
482 T Element::Get(
const std::string &_key)
const
486 std::pair<T, bool> ret = this->Get<T>(_key, result);
493 bool Element::Get(
const std::string &_key,
495 const T &_defaultValue)
const
497 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
504 std::pair<T, bool> Element::Get(
const std::string &_key,
505 const T &_defaultValue)
const
507 std::pair<T, bool> result(_defaultValue,
true);
509 if (_key.empty() && this->dataPtr->value)
511 this->dataPtr->value->Get<T>(result.first);
513 else if (!_key.empty())
515 ParamPtr param = this->GetAttribute(_key);
518 param->Get(result.first);
520 else if (this->HasElement(_key))
522 result.first = this->GetElementImpl(_key)->Get<T>();
524 else if (this->HasElementDescription(_key))
526 result.first = this->GetElementDescription(_key)->Get<T>();
530 result.second =
false;
535 result.second =
false;
543 bool Element::Set(
const T &_value)
545 if (this->dataPtr->value)
547 this->dataPtr->value->Set(_value);
Definition: Element.hh:439
std::string required
True if element is required.
Definition: Element.hh:444
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:453
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:450
Param_V attributes
Definition: Element.hh:456
ElementPtr_V elements
Definition: Element.hh:462
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:471
ElementPtr_V elementDescriptions
Definition: Element.hh:465
std::string description
Element description.
Definition: Element.hh:447
std::string name
Element name.
Definition: Element.hh:441
std::string originalVersion
Spec version that this was originally parsed from.
Definition: Element.hh:477
ParamPtr value
Definition: Element.hh:459
std::string path
Path to file where this element came from.
Definition: Element.hh:474
std::string includeFilename
name of the include file that was used to create this element
Definition: Element.hh:468
SDF Element class.
Definition: Element.hh:70
void AddAttribute(const std::string &_key, const std::string &_type, const std::string &_defaultvalue, bool _required, const std::string &_description="")
Add an attribute value.
void PrintValues(std::string _prefix) const
Output Element's values to stdout.
void Update()
Call the Update() callback on each element, as well as the embedded Param.
ParamPtr GetAttribute(unsigned int _index) const
Get an attribute using an index.
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 va...
ElementPtr GetElement(const std::string &_name)
Return a pointer to the child element with the provided name.
ElementPtr GetNextElement(const std::string &_name="") const
Get the next sibling of this element.
void Copy(const ElementPtr _elem)
Copy values from an Element.
void AddElementDescription(ElementPtr _elem)
Add a new element description.
void Clear()
Remove all child elements and reset file path and original version.
std::string ReferenceSDF() const
Get the name of the reference SDF element.
const std::string & GetRequired() const
Get the requirement string.
void SetName(const std::string &_name)
Set the name of the Element.
ElementPtr Clone() const
Create a copy of this Element.
ElementPtr GetFirstElement() const
Get the first child element.
bool HasElement(const std::string &_name) const
Return true if the named element exists.
void SetFilePath(const std::string &_path)
Set the path to the SDF document where this element came from.
void RemoveFromParent()
Remove this element from its parent.
ElementPtr GetParent() const
Get a pointer to this Element's parent.
bool HasElementDescription(const std::string &_name) const
Return true if an element description exists.
void SetRequired(const std::string &_req)
Set the requirement type.
ElementPtr GetElementImpl(const std::string &_name) const
Get a pointer to the named element.
size_t GetElementDescriptionCount() const
Get the number of element descriptions.
void SetInclude(const std::string &_filename)
Set the include filename to the passed in filename.
ParamPtr GetAttribute(const std::string &_key) const
Get the param of an attribute.
std::string GetDescription() const
Get a text description of the element.
ElementPtr GetElementDescription(const std::string &_key) const
Get an element description using a key.
std::string ToString(const std::string &_prefix) const
Convert the element values to a string representation.
void PrintDescription(const std::string &_prefix) const
Output Element's description to stdout.
ElementPtr GetElementDescription(unsigned int _index) const
Get an element description using an index.
void InsertElement(ElementPtr _elem)
Add an element object.
void ClearElements()
Remove all child elements.
void AddValue(const std::string &_type, const std::string &_defaultValue, bool _required, const std::string &_description="")
Add a value to this Element.
void PrintDocRightPane(std::string &_html, int _spacing, int &_index) const
Helper function for SDF::PrintDoc.
void SetCopyChildren(bool _value)
Set whether this element should copy its child elements during parsing.
std::any GetAny(const std::string &_key="") const
Get the element value/attribute as a std::any.
ParamPtr GetValue() const
Get the param of the elements value return A Param pointer to the value of this element.
virtual ~Element()
Destructor.
const std::string & FilePath() const
Get the path to the SDF document where this element came from.
void SetOriginalVersion(const std::string &_version)
Set the spec version that this was originally parsed from.
const std::string & OriginalVersion() const
Get the spec version that this was originally parsed from.
void SetParent(const ElementPtr _parent)
Set the parent of this Element.
ElementPtr AddElement(const std::string &_name)
Add a named element.
bool HasUniqueChildNames(const std::string &_type="") const
Checks whether any child elements of the specified element type have identical name attribute values ...
const std::string & GetName() const
Get the Element's name.
bool HasAttribute(const std::string &_key) const
Return true if an attribute exists.
void SetReferenceSDF(const std::string &_value)
Set reference SDF element.
std::string GetInclude() const
Get the include filename.
bool GetCopyChildren() const
Return true if this Element's child elements should be copied during parsing.
std::set< std::string > GetElementTypeNames() const
Get set of child element type names.
void Reset()
Call reset on each element and element description before deleting all of them.
void RemoveChild(ElementPtr _child)
Remove a child element.
bool GetAttributeSet(const std::string &_key) const
Return true if the attribute was set (i.e.
void SetDescription(const std::string &_desc)
Set a text description for the element.
size_t GetAttributeCount() const
Get the number of attributes.
void PrintDocLeftPane(std::string &_html, int _spacing, int &_index) const
Helper function for SDF::PrintDoc.
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:57
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:57
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:61
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:53
std::vector< ParamPtr > Param_V
Definition: Param.hh:61
namespace for Simulation Description Format parser
Definition: Actor.hh:33
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:48