Go to the documentation of this file.
17 #ifndef SDF_ELEMENT_HH_
18 #define SDF_ELEMENT_HH_
38 #pragma warning(disable: 4251)
46 inline namespace SDF_VERSION_NAMESPACE {
74 public std::enable_shared_from_this<Element>
97 public:
void SetParent(
const ElementPtr _parent);
101 public:
void SetName(
const std::string &_name);
105 public:
const std::string &GetName()
const;
114 public:
void SetRequired(
const std::string &_req);
119 public:
const std::string &GetRequired()
const;
126 public:
void SetExplicitlySetInFile(
const bool _value);
130 public:
bool GetExplicitlySetInFile()
const;
135 public:
void SetCopyChildren(
bool _value);
140 public:
bool GetCopyChildren()
const;
144 public:
void SetReferenceSDF(
const std::string &_value);
148 public: std::string ReferenceSDF()
const;
152 public:
void PrintDescription(
const std::string &_prefix)
const;
157 public:
void PrintValues(std::string _prefix,
165 public:
void PrintValues(
const std::string &_prefix,
166 bool _includeDefaultElements,
167 bool _includeDefaultAttributes,
176 public:
void PrintDocLeftPane(std::string &_html,
177 int _spacing,
int &_index)
const;
184 public:
void PrintDocRightPane(std::string &_html,
185 int _spacing,
int &_index)
const;
191 public: std::string ToString(
192 const std::string &_prefix,
204 public: std::string ToString(
205 const std::string &_prefix,
206 bool _includeDefaultElements,
207 bool _includeDefaultAttributes,
217 public:
void AddAttribute(
const std::string &_key,
218 const std::string &_type,
219 const std::string &_defaultvalue,
221 const std::string &_description =
"");
229 public:
void AddValue(
const std::string &_type,
230 const std::string &_defaultValue,
bool _required,
231 const std::string &_description =
"");
242 public:
void AddValue(
const std::string &_type,
243 const std::string &_defaultValue,
bool _required,
244 const std::string &_minValue,
245 const std::string &_maxValue,
246 const std::string &_description =
"");
251 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
255 public:
size_t GetAttributeCount()
const;
259 public:
const Param_V &GetAttributes()
const;
264 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
268 public:
size_t GetElementDescriptionCount()
const;
273 public:
ElementPtr GetElementDescription(
unsigned int _index)
const;
278 public:
ElementPtr GetElementDescription(
const std::string &_key)
const;
283 public:
bool HasElementDescription(
const std::string &_name)
const;
288 public:
bool HasAttribute(
const std::string &_key)
const;
293 public:
bool GetAttributeSet(
const std::string &_key)
const;
297 public:
void RemoveAttribute(
const std::string &_key);
300 public:
void RemoveAllAttributes();
310 public: std::any GetAny(
const std::string &_key =
"")
const;
318 public:
template<
typename T>
319 T Get(
const std::string &_key =
"")
const;
327 public:
template<
typename T>
328 std::pair<T, bool> Get(
const std::string &_key,
329 const T &_defaultValue)
const;
337 public:
template<
typename T>
338 bool Get(
const std::string &_key,
340 const T &_defaultValue)
const;
345 public:
template<
typename T>
346 bool Set(
const T &_value);
351 public:
bool HasElement(
const std::string &_name)
const;
369 public:
ElementPtr GetNextElement(
const std::string &_name =
"")
const;
373 public: std::set<std::string> GetElementTypeNames()
const;
382 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
394 public:
bool HasUniqueChildNames(
395 const std::string &_type,
396 const std::vector<std::string> &_ignoreElements)
const;
405 public: std::map<std::string, std::size_t>
406 CountNamedElements(
const std::string &_type =
"")
const;
418 public: std::map<std::string, std::size_t> CountNamedElements(
419 const std::string &_type,
420 const std::vector<std::string> &_ignoreElements)
const;
432 public:
ElementPtr GetElement(
const std::string &_name);
443 public:
ElementPtr FindElement(
const std::string &_name);
459 public:
ElementPtr AddElement(
const std::string &_name);
470 public:
void InsertElement(
ElementPtr _elem,
bool _setParentToSelf);
473 public:
void RemoveFromParent();
480 public:
void ClearElements();
484 public:
void Clear();
488 public:
void Update();
493 public:
void Reset();
510 public:
void SetFilePath(
const std::string &_path);
514 public:
const std::string &FilePath()
const;
518 public:
void SetLineNumber(
int _lineNumber);
523 public: std::optional<int> LineNumber()
const;
539 public:
void SetXmlPath(
const std::string &_path);
543 public:
const std::string &XmlPath()
const;
547 public:
void SetOriginalVersion(
const std::string &_version);
551 public:
const std::string &OriginalVersion()
const;
555 public: std::string GetDescription()
const;
559 public:
void SetDescription(
const std::string &_desc);
563 public:
void AddElementDescription(
ElementPtr _elem);
568 public:
ElementPtr GetElementImpl(
const std::string &_name)
const;
573 public:
static std::vector<std::string> NameUniquenessExceptions();
581 private:
void ToString(
const std::string &_prefix,
582 bool _includeDefaultElements,
583 bool _includeDefaultAttributes,
585 std::ostringstream &_out)
const;
593 private:
void PrintValuesImpl(
const std::string &_prefix,
594 bool _includeDefaultElements,
595 bool _includeDefaultAttributes,
597 std::ostringstream &_out)
const;
607 private:
ParamPtr CreateParam(
const std::string &_key,
608 const std::string &_type,
609 const std::string &_defaultValue,
611 const std::string &_description =
"");
615 private: std::unique_ptr<ElementPrivate> dataPtr;
695 std::ostringstream &_out)
const;
704 std::pair<T, bool> ret = this->Get<T>(_key, result);
713 const T &_defaultValue)
const
715 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
723 const T &_defaultValue)
const
725 std::pair<T, bool> result(_defaultValue,
true);
727 if (_key.empty() && this->dataPtr->value)
729 this->dataPtr->value->Get<T>(result.first);
731 else if (!_key.empty())
736 param->Get(result.first);
748 result.second =
false;
753 result.second =
false;
763 if (this->dataPtr->value)
765 this->dataPtr->value->Set(_value);
ElementPtr_V elements
Definition: Element.hh:644
std::string path
Path to file where this element came from.
Definition: Element.hh:675
ElementPtr includeElement
The element that was used to load this entity.
Definition: Element.hh:669
SDF Element class.
Definition: Element.hh:73
ParamPtr GetAttribute(const std::string &_key) const
Get the param of an attribute.
namespace for Simulation Description Format parser
Definition: Actor.hh:34
std::optional< int > lineNumber
Line number in file where this element came from.
Definition: Element.hh:684
This class contains configuration options for printing elements.
Definition: PrintConfig.hh:31
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:672
std::string originalVersion
Spec version that this was originally parsed from.
Definition: Element.hh:678
std::shared_ptr< const Element > ElementConstPtr
Definition: Element.hh:58
std::string name
Element name.
Definition: Element.hh:623
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:70
#define SDFORMAT_VISIBLE
Definition: system_util.hh:25
bool HasElement(const std::string &_name) const
Return true if the named element exists.
std::string description
Element description.
Definition: Element.hh:629
ParamPtr value
Definition: Element.hh:641
T Get(const std::string &_key="") const
Get the value of a key.
Definition: Element.hh:700
ElementPtr GetElementDescription(unsigned int _index) const
Get an element description using an index.
ElementPtr GetElementImpl(const std::string &_name) const
Get a pointer to the named element.
bool HasElementDescription(const std::string &_name) const
Return true if an element description exists.
ElementPtr_V elementDescriptions
Definition: Element.hh:647
class GZ_SDFORMAT_VISIBLE Element
Definition: Element.hh:50
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:632
Definition: Element.hh:620
std::string xmlPath
XML path of this element.
Definition: Element.hh:687
std::string required
True if element is required.
Definition: Element.hh:626
Param_V attributes
Definition: Element.hh:638
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:66
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:62
bool Set(const T &_value)
Set the value of this element.
Definition: Element.hh:761
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:635
void PrintAttributes(bool _includeDefaultAttributes, const PrintConfig &_config, std::ostringstream &_out) const
Generate the string (XML) for the attributes.
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:54
bool explicitlySetInFile
True if the element was set in the SDF file.
Definition: Element.hh:681
std::vector< ParamPtr > Param_V
Definition: Param.hh:74