Go to the documentation of this file.
17 #ifndef _SDF_ELEMENT_HH_
18 #define _SDF_ELEMENT_HH_
33 #pragma warning(disable: 4251)
61 public std::enable_shared_from_this<Element>
88 public:
void SetName(
const std::string &_name);
92 public:
const std::string &
GetName()
const;
140 int _spacing,
int &_index)
const;
148 int _spacing,
int &_index)
const;
153 public: std::string
ToString(
const std::string &_prefix)
const;
163 const std::string &_type,
164 const std::string &_defaultvalue,
166 const std::string &_description=
"");
175 const std::string &_defaultValue,
bool _required,
176 const std::string &_description=
"");
229 public: boost::any
GetAny(
const std::string &_key =
"")
const;
237 public:
template<
typename T>
238 T Get(
const std::string &_key =
"")
const;
246 public:
template<
typename T>
247 std::pair<T, bool> Get(
const std::string &_key,
248 const T &_defaultValue)
const;
256 public:
template<
typename T>
257 bool Get(
const std::string &_key,
259 const T &_defaultValue)
const;
264 public:
template<
typename T>
265 bool Set(
const T &_value);
357 private:
void ToString(
const std::string &_prefix,
358 std::ostringstream &_out)
const;
363 private:
void PrintValuesImpl(
const std::string &_prefix,
364 std::ostringstream &_out)
const;
374 private:
ParamPtr CreateParam(
const std::string &_key,
375 const std::string &_type,
376 const std::string &_defaultValue,
378 const std::string &_description=
"");
382 private: std::unique_ptr<ElementPrivate> dataPtr;
429 std::pair<T, bool> ret = this->Get<T>(_key, result);
438 const T &_defaultValue)
const
440 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
448 const T &_defaultValue)
const
450 std::pair<T, bool> result(_defaultValue,
true);
452 if (_key.empty() && this->dataPtr->value)
454 this->dataPtr->value->Get<T>(result.first);
456 else if (!_key.empty())
461 param->Get(result.first);
473 result.second =
false;
478 result.second =
false;
488 if (this->dataPtr->value)
490 this->dataPtr->value->Set(_value);
ElementPtr GetFirstElement() const
Get the first child element.
void InsertElement(ElementPtr _elem)
Add an element object.
ElementPtr GetParent() const
Get a pointer to this Element's parent.
ElementPtr GetElementDescription(const std::string &_key) const
Get an element description using a key.
Definition: Element.hh:388
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:53
void SetReferenceSDF(const std::string &_value)
Set reference SDF element.
void RemoveChild(ElementPtr _child)
Remove a child element.
void SetRequired(const std::string &_req)
Set the requirement type.
void ClearElements()
Remove all child elements.
ElementPtr Clone() const
Create a copy of this Element.
namespace for Simulation Description Format parser
Definition: Console.hh:36
std::string description
Element description.
Definition: Element.hh:396
Param_V attributes
Definition: Element.hh:405
ParamPtr GetAttribute(const std::string &_key) const
Get the param of an attribute.
void Update()
Call the Update() callback on each element, as well as the embedded Param.
ElementPtr GetElement(const std::string &_name)
Return a pointer to the child element with the provided name.
ParamPtr GetValue() const
Get the param of the elements value return A Param pointer to the value of this element.
ElementPtr GetElementDescription(unsigned int _index) const
Get an element description using an index.
void SetInclude(const std::string &_filename)
Set the include filename to the passed in filename.
void PrintDocLeftPane(std::string &_html, int _spacing, int &_index) const
Helper function for SDF::PrintDoc.
void Copy(const ElementPtr _elem)
Copy values from an Element.
void AddValue(const std::string &_type, const std::string &_defaultValue, bool _required, const std::string &_description="")
Add a value to this Element.
const std::string & GetRequired() const
Get the requirement string.
std::string GetInclude() const
Get the include filename.
void SetParent(const ElementPtr _parent)
Set the parent of this Element.
ElementPtr_V elementDescriptions
Definition: Element.hh:414
const std::string & GetName() const
Get the Element's name.
boost::any GetAny(const std::string &_key="") const
Get the element value/attribute as a boost::any.
ElementPtr_V elements
Definition: Element.hh:411
ParamPtr value
Definition: Element.hh:408
ElementPtr GetNextElement(const std::string &_name="") const
Get the next sibling of this element.
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:420
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:402
#define SDFORMAT_VISIBLE
Definition: system_util.hh:48
size_t GetElementDescriptionCount() const
Get the number of element descriptions.
size_t GetAttributeCount() const
Get the number of attributes.
void AddElementDescription(ElementPtr _elem)
Add a new element description.
std::string GetDescription() const
Get a text description of the element.
std::string includeFilename
name of the include file that was used to create this element
Definition: Element.hh:417
bool HasElement(const std::string &_name) const
Return true if the named element exists.
void PrintDocRightPane(std::string &_html, int _spacing, int &_index) const
Helper function for SDF::PrintDoc.
bool GetCopyChildren() const
Return true if this Element's child elements should be copied during parsing.
T Get(const std::string &_key="") const
Get the value of a key.
Definition: Element.hh:425
void PrintDescription(const std::string &_prefix) const
Output Element's description to stdout.
void SetDescription(const std::string &_desc)
Set a text description for the element.
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:45
bool GetAttributeSet(const std::string &_key) const
Return true if the attribute was set (i.e.
std::vector< ParamPtr > Param_V
Definition: Param.hh:59
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:55
virtual ~Element()
Destructor.
void SetCopyChildren(bool _value)
Set whether this element should copy its child elements during parsing.
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:399
void RemoveFromParent()
Remove this element from its parent.
bool Set(const T &_value)
Set the value of this element.
Definition: Element.hh:486
std::string ReferenceSDF() const
Get the name of the reference SDF element.
std::string ToString(const std::string &_prefix) const
Convert the element values to a string representation.
std::string name
Element name.
Definition: Element.hh:390
ElementPtr GetElementImpl(const std::string &_name) const
Get a pointer to the named element.
void PrintValues(std::string _prefix) const
Output Element's values to stdout.
std::string required
True if element is required.
Definition: Element.hh:393
void SetName(const std::string &_name)
Set the name of the Element.
bool HasElementDescription(const std::string &_name) const
Return true if an element description exists.
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:49
void Reset()
Call reset on each element and element description before deleting all of them.
void AddAttribute(const std::string &_key, const std::string &_type, const std::string &_defaultvalue, bool _required, const std::string &_description="")
Add an attribute value.
ElementPtr AddElement(const std::string &_name)
Add a named element.
bool HasAttribute(const std::string &_key) const
Return true if an attribute exists.
ParamPtr GetAttribute(unsigned int _index) const
Get an attribute using an index.
SDF Element class.
Definition: Element.hh:62