Element.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef SDF_ELEMENT_HH_
18 #define SDF_ELEMENT_HH_
19 
20 #include <any>
21 #include <map>
22 #include <memory>
23 #include <set>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 #include "sdf/Error.hh"
29 #include "sdf/Param.hh"
30 #include "sdf/PrintConfig.hh"
31 #include "sdf/sdf_config.h"
32 #include "sdf/system_util.hh"
33 #include "sdf/Types.hh"
34 
35 #ifdef _WIN32
36 // Disable warning C4251 which is triggered by
37 // std::enable_shared_from_this
38 #pragma warning(push)
39 #pragma warning(disable: 4251)
40 #endif
41 
44 namespace sdf
45 {
46  // Inline bracket to help doxygen filtering.
47  inline namespace SDF_VERSION_NAMESPACE {
48  //
49 
50  class ElementPrivate;
52 
55  typedef std::shared_ptr<Element> ElementPtr;
56 
59  typedef std::shared_ptr<const Element> ElementConstPtr;
60 
63  typedef std::weak_ptr<Element> ElementWeakPtr;
64 
67  typedef std::vector<ElementPtr> ElementPtr_V;
68 
71 
75  public std::enable_shared_from_this<Element>
76  {
78  public: Element();
79 
81  public: virtual ~Element();
82 
85  public: ElementPtr Clone() const;
86 
90  public: ElementPtr Clone(sdf::Errors &_errors) const;
91 
94  public: void Copy(const ElementPtr _elem);
95 
99  public: void Copy(const ElementPtr _elem, sdf::Errors &_errors);
100 
104  public: ElementPtr GetParent() const;
105 
108  public: void SetParent(const ElementPtr _parent);
109 
112  public: void SetName(const std::string &_name);
113 
116  public: const std::string &GetName() const;
117 
125  public: void SetRequired(const std::string &_req);
126 
130  public: const std::string &GetRequired() const;
131 
137  public: void SetExplicitlySetInFile(const bool _value);
138 
141  public: bool GetExplicitlySetInFile() const;
142 
146  public: void SetCopyChildren(bool _value);
147 
151  public: bool GetCopyChildren() const;
152 
155  public: void SetReferenceSDF(const std::string &_value);
156 
159  public: std::string ReferenceSDF() const;
160 
163  public: void PrintDescription(const std::string &_prefix) const;
164 
168  public: void PrintDescription(sdf::Errors &_errors,
169  const std::string &_prefix) const;
170 
174  public: void PrintValues(std::string _prefix,
175  const PrintConfig &_config = PrintConfig()) const;
176 
181  public: void PrintValues(sdf::Errors &_errors,
182  std::string _prefix,
183  const PrintConfig &_config = PrintConfig()) const;
184 
190  public: void PrintValues(const std::string &_prefix,
191  bool _includeDefaultElements,
192  bool _includeDefaultAttributes,
193  const PrintConfig &_config = PrintConfig()) const;
194 
201  public: void PrintValues(sdf::Errors &_errors,
202  const std::string &_prefix,
203  bool _includeDefaultElements,
204  bool _includeDefaultAttributes,
205  const PrintConfig &_config = PrintConfig()) const;
206 
213  public: void PrintDocLeftPane(std::string &_html,
214  int _spacing, int &_index) const;
215 
221  public: void PrintDocRightPane(std::string &_html,
222  int _spacing, int &_index) const;
223 
228  public: std::string ToString(
229  const std::string &_prefix,
230  const PrintConfig &_config = PrintConfig()) const;
231 
237  public: std::string ToString(
238  sdf::Errors &_errors,
239  const std::string &_prefix,
240  const PrintConfig &_config = PrintConfig()) const;
241 
251  public: std::string ToString(
252  const std::string &_prefix,
253  bool _includeDefaultElements,
254  bool _includeDefaultAttributes,
255  const PrintConfig &_config = PrintConfig()) const;
256 
267  public: std::string ToString(
268  sdf::Errors &_errors,
269  const std::string &_prefix,
270  bool _includeDefaultElements,
271  bool _includeDefaultAttributes,
272  const PrintConfig &_config = PrintConfig()) const;
273 
281  public: void AddAttribute(const std::string &_key,
282  const std::string &_type,
283  const std::string &_defaultvalue,
284  bool _required,
285  const std::string &_description = "");
286 
295  public: void AddAttribute(const std::string &_key,
296  const std::string &_type,
297  const std::string &_defaultvalue,
298  bool _required,
299  sdf::Errors &_errors,
300  const std::string &_description = "");
301 
308  public: void AddValue(const std::string &_type,
309  const std::string &_defaultValue, bool _required,
310  const std::string &_description = "");
311 
319  public: void AddValue(const std::string &_type,
320  const std::string &_defaultValue, bool _required,
321  sdf::Errors &_errors,
322  const std::string &_description = "");
323 
333  public: void AddValue(const std::string &_type,
334  const std::string &_defaultValue, bool _required,
335  const std::string &_minValue,
336  const std::string &_maxValue,
337  const std::string &_description = "");
338 
349  public: void AddValue(const std::string &_type,
350  const std::string &_defaultValue, bool _required,
351  const std::string &_minValue,
352  const std::string &_maxValue,
353  sdf::Errors &_errors,
354  const std::string &_description = "");
355 
359  public: ParamPtr GetAttribute(const std::string &_key) const;
360 
363  public: size_t GetAttributeCount() const;
364 
367  public: const Param_V &GetAttributes() const;
368 
372  public: ParamPtr GetAttribute(unsigned int _index) const;
373 
376  public: size_t GetElementDescriptionCount() const;
377 
381  public: ElementPtr GetElementDescription(unsigned int _index) const;
382 
386  public: ElementPtr GetElementDescription(const std::string &_key) const;
387 
391  public: bool HasElementDescription(const std::string &_name) const;
392 
396  public: bool HasAttribute(const std::string &_key) const;
397 
401  public: bool GetAttributeSet(const std::string &_key) const;
402 
405  public: void RemoveAttribute(const std::string &_key);
406 
408  public: void RemoveAllAttributes();
409 
412  public: ParamPtr GetValue() const;
413 
418  public: std::any GetAny(const std::string &_key = "") const;
419 
425  public: std::any GetAny(sdf::Errors &_errors,
426  const std::string &_key = "") const;
427 
435  public: template<typename T>
436  T Get(sdf::Errors &_errors,
437  const std::string &_key = "") const;
438 
445  public: template<typename T>
446  T Get(const std::string &_key = "") const;
447 
455  public: template<typename T>
456  std::pair<T, bool> Get(sdf::Errors &_errors,
457  const std::string &_key,
458  const T &_defaultValue) const;
465  public: template<typename T>
466  std::pair<T, bool> Get(const std::string &_key,
467  const T &_defaultValue) const;
468 
475  public: template<typename T>
476  bool Get(const std::string &_key,
477  T &_param,
478  const T &_defaultValue) const;
479 
487  public: template<typename T>
488  bool Get(sdf::Errors &_errors,
489  const std::string &_key,
490  T &_param,
491  const T &_defaultValue) const;
492 
496  public: template<typename T>
497  bool Set(const T &_value);
498 
503  public: template<typename T>
504  bool Set(sdf::Errors &_errors, const T &_value);
505 
509  public: bool HasElement(const std::string &_name) const;
510 
514  public: ElementPtr GetFirstElement() const;
515 
527  public: ElementPtr GetNextElement(const std::string &_name = "") const;
528 
531  public: std::set<std::string> GetElementTypeNames() const;
532 
540  public: bool HasUniqueChildNames(const std::string &_type = "") const;
541 
550  public: bool HasUniqueChildNames(sdf::Errors &_errors,
551  const std::string &_type = "") const;
552 
563  public: bool HasUniqueChildNames(
564  const std::string &_type,
565  const std::vector<std::string> &_ignoreElements) const;
566 
578  public: bool HasUniqueChildNames(
579  sdf::Errors &_errors,
580  const std::string &_type,
581  const std::vector<std::string> &_ignoreElements) const;
582 
590  public: std::map<std::string, std::size_t>
591  CountNamedElements(const std::string &_type = "") const;
592 
601  public: std::map<std::string, std::size_t>
603  const std::string &_type = "") const;
604 
615  public: std::map<std::string, std::size_t> CountNamedElements(
616  const std::string &_type,
617  const std::vector<std::string> &_ignoreElements) const;
618 
630  public: std::map<std::string, std::size_t> CountNamedElements(
631  sdf::Errors &_errors,
632  const std::string &_type,
633  const std::vector<std::string> &_ignoreElements) const;
634 
645  public: ElementPtr GetElement(const std::string &_name);
646 
658  public: ElementPtr GetElement(const std::string &_name,
659  sdf::Errors &_errors);
660 
670  public: ElementPtr FindElement(const std::string &_name);
671 
681  public: ElementConstPtr FindElement(const std::string &_name) const;
682 
686  public: ElementPtr AddElement(const std::string &_name);
687 
692  public: ElementPtr AddElement(const std::string &_name,
693  sdf::Errors &_errors);
694 
697  public: void InsertElement(ElementPtr _elem);
698 
704  public: void InsertElement(ElementPtr _elem, bool _setParentToSelf);
705 
707  public: void RemoveFromParent();
708 
711  public: void RemoveChild(ElementPtr _child);
712 
716  public: void RemoveChild(ElementPtr _child, sdf::Errors &_errors);
717 
719  public: void ClearElements();
720 
723  public: void Clear();
724 
727  public: void Update();
728 
732  public: void Update(sdf::Errors &_errors);
733 
737  public: void Reset();
738 
744  public: void SetIncludeElement(sdf::ElementPtr _includeElem);
745 
751 
754  public: void SetFilePath(const std::string &_path);
755 
758  public: const std::string &FilePath() const;
759 
762  public: void SetLineNumber(int _lineNumber);
763 
767  public: std::optional<int> LineNumber() const;
768 
783  public: void SetXmlPath(const std::string &_path);
784 
787  public: const std::string &XmlPath() const;
788 
791  public: void SetOriginalVersion(const std::string &_version);
792 
795  public: const std::string &OriginalVersion() const;
796 
799  public: std::string GetDescription() const;
800 
803  public: void SetDescription(const std::string &_desc);
804 
807  public: void AddElementDescription(ElementPtr _elem);
808 
812  public: ElementPtr GetElementImpl(const std::string &_name) const;
813 
817  public: static std::vector<std::string> NameUniquenessExceptions();
818 
826  private: void ToString(sdf::Errors &_errors,
827  std::ostringstream &_out,
828  const std::string &_prefix,
829  bool _includeDefaultElements,
830  bool _includeDefaultAttributes,
831  const PrintConfig &_config) const;
832 
840  private: void PrintValuesImpl(sdf::Errors &_errors,
841  const std::string &_prefix,
842  bool _includeDefaultElements,
843  bool _includeDefaultAttributes,
844  const PrintConfig &_config,
845  std::ostringstream &_out) const;
846 
856  private: ParamPtr CreateParam(const std::string &_key,
857  const std::string &_type,
858  const std::string &_defaultValue,
859  bool _required,
860  sdf::Errors &_errors,
861  const std::string &_description = "");
862 
864  private: std::unique_ptr<ElementPrivate> dataPtr;
865  };
866 
870  {
872  public: std::string name;
873 
875  public: std::string required;
876 
878  public: std::string description;
879 
881  public: bool copyChildren;
882 
885 
886  // Attributes of this element
888 
889  // Value of this element
890  public: ParamPtr value;
891 
892  // The existing child elements
894 
895  // The possible child elements
897 
919 
921  public: std::string referenceSDF;
922 
924  public: std::string path;
925 
927  public: std::string originalVersion;
928 
930  public: bool explicitlySetInFile;
931 
933  public: std::optional<int> lineNumber;
934 
936  public: std::string xmlPath;
937 
942  public: void PrintAttributes(bool _includeDefaultAttributes,
943  const PrintConfig &_config,
944  std::ostringstream &_out) const;
945 
951  public: void PrintAttributes(sdf::Errors &_errors,
952  bool _includeDefaultAttributes,
953  const PrintConfig &_config,
954  std::ostringstream &_out) const;
955  };
956 
958  template<typename T>
959  T Element::Get(sdf::Errors &_errors, const std::string &_key) const
960  {
961  T result = T();
962 
963  std::pair<T, bool> ret = this->Get<T>(_errors, _key, result);
964 
965  return ret.first;
966  }
967 
969  template<typename T>
970  T Element::Get(const std::string &_key) const
971  {
972  T result = T();
973 
974  std::pair<T, bool> ret = this->Get<T>(_key, result);
975 
976  return ret.first;
977  }
978 
980  template<typename T>
981  bool Element::Get(sdf::Errors &_errors,
982  const std::string &_key,
983  T &_param,
984  const T &_defaultValue) const
985  {
986  std::pair<T, bool> ret = this->Get<T>(_errors, _key, _defaultValue);
987  _param = ret.first;
988  return ret.second;
989  }
990 
992  template<typename T>
993  bool Element::Get(const std::string &_key,
994  T &_param,
995  const T &_defaultValue) const
996  {
997  std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
998  _param = ret.first;
999  return ret.second;
1000  }
1001 
1003  template<typename T>
1004  std::pair<T, bool> Element::Get(const std::string &_key,
1005  const T &_defaultValue) const
1006  {
1007  sdf::Errors errors;
1008  std::pair<T, bool> result = this->Get<T>(errors, _key, _defaultValue);
1009  for(auto& error : errors)
1010  {
1012  }
1013  return result;
1014  }
1015 
1017  template<typename T>
1018  std::pair<T, bool> Element::Get(sdf::Errors &_errors,
1019  const std::string &_key,
1020  const T &_defaultValue) const
1021  {
1022  std::pair<T, bool> result(_defaultValue, true);
1023 
1024  if (_key.empty() && this->dataPtr->value)
1025  {
1026  this->dataPtr->value->Get<T>(result.first, _errors);
1027  }
1028  else if (!_key.empty())
1029  {
1030  ParamPtr param = this->GetAttribute(_key);
1031  if (param)
1032  {
1033  param->Get(result.first, _errors);
1034  }
1035  else if (this->HasElement(_key))
1036  {
1037  result.first = this->GetElementImpl(_key)->Get<T>(_errors);
1038  }
1039  else if (this->HasElementDescription(_key))
1040  {
1041  result.first = this->GetElementDescription(_key)->Get<T>(_errors);
1042  }
1043  else
1044  {
1045  result.second = false;
1046  }
1047  }
1048  else
1049  {
1050  result.second = false;
1051  }
1052 
1053  return result;
1054  }
1055 
1057  template<typename T>
1058  bool Element::Set(const T &_value)
1059  {
1060  sdf::Errors errors;
1061  bool result = this->Set<T>(errors, _value);
1062  for(auto& error : errors)
1063  {
1065  }
1066  return result;
1067  }
1068 
1070  template<typename T>
1071  bool Element::Set(sdf::Errors &_errors, const T &_value)
1072  {
1073  if (this->dataPtr->value)
1074  {
1075  return this->dataPtr->value->Set(_value, _errors);
1076  }
1077  return false;
1078  }
1080  }
1081 }
1082 
1083 #ifdef _WIN32
1084 #pragma warning(pop)
1085 #endif
1086 
1087 #endif
Definition: Element.hh:870
bool explicitlySetInFile
True if the element was set in the SDF file.
Definition: Element.hh:930
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:884
std::string description
Element description.
Definition: Element.hh:878
void PrintAttributes(bool _includeDefaultAttributes, const PrintConfig &_config, std::ostringstream &_out) const
Generate the string (XML) for the attributes.
ElementPtr_V elements
Definition: Element.hh:893
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:921
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:881
Param_V attributes
Definition: Element.hh:887
std::string required
True if element is required.
Definition: Element.hh:875
void PrintAttributes(sdf::Errors &_errors, bool _includeDefaultAttributes, const PrintConfig &_config, std::ostringstream &_out) const
Generate the string (XML) for the attributes.
ParamPtr value
Definition: Element.hh:890
std::string name
Element name.
Definition: Element.hh:872
ElementPtr_V elementDescriptions
Definition: Element.hh:896
std::string originalVersion
Spec version that this was originally parsed from.
Definition: Element.hh:927
std::string xmlPath
XML path of this element.
Definition: Element.hh:936
std::string path
Path to file where this element came from.
Definition: Element.hh:924
std::optional< int > lineNumber
Line number in file where this element came from.
Definition: Element.hh:933
ElementPtr includeElement
The element that was used to load this entity.
Definition: Element.hh:918
SDF Element class.
Definition: Element.hh:76
void SetOriginalVersion(const std::string &_version)
Set the spec version that this was originally parsed from.
const std::string & GetRequired() const
Get the requirement string.
void Copy(const ElementPtr _elem)
Copy values from an Element.
void RemoveChild(ElementPtr _child)
Remove a child element.
std::string GetDescription() const
Get a text description of the element.
size_t GetAttributeCount() const
Get the number of attributes.
ElementPtr GetNextElement(const std::string &_name="") const
Get the next sibling of this element.
ParamPtr GetValue() const
Get the param of the elements value return A Param pointer to the value of this element.
bool HasElementDescription(const std::string &_name) const
Return true if an element description exists.
void AddElementDescription(ElementPtr _elem)
Add a new element description.
const std::string & FilePath() const
Get the path to the SDF document where this element came from.
void PrintValues(sdf::Errors &_errors, std::string _prefix, const PrintConfig &_config=PrintConfig()) const
Output Element's values to stdout.
void Clear()
Remove all child elements and reset file path and original version.
void PrintDescription(sdf::Errors &_errors, const std::string &_prefix) const
Output Element's description to stdout.
std::string ToString(sdf::Errors &_errors, const std::string &_prefix, const PrintConfig &_config=PrintConfig()) const
Convert the element values to a string representation.
void Reset()
Call reset on each element and element description before deleting all of them.
std::string ReferenceSDF() const
Get the name of the reference SDF element.
bool HasUniqueChildNames(sdf::Errors &_errors, 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 _ignoreElemen...
void Update()
Call the Update() callback on each element, as well as the embedded Param.
bool HasUniqueChildNames(sdf::Errors &_errors, const std::string &_type="") const
Checks whether any child elements of the specified element type have identical name attribute values ...
void PrintValues(const std::string &_prefix, bool _includeDefaultElements, bool _includeDefaultAttributes, const PrintConfig &_config=PrintConfig()) const
Output Element's values to stdout.
const std::string & OriginalVersion() const
Get the spec version that this was originally parsed from.
void SetLineNumber(int _lineNumber)
Set the line number of this element within the SDF document.
ElementPtr AddElement(const std::string &_name, sdf::Errors &_errors)
Add a named element.
void SetRequired(const std::string &_req)
Set the requirement type.
std::string ToString(const std::string &_prefix, bool _includeDefaultElements, bool _includeDefaultAttributes, const PrintConfig &_config=PrintConfig()) const
Convert the element values to a string representation.
void RemoveAttribute(const std::string &_key)
Remove an attribute.
void SetCopyChildren(bool _value)
Set whether this element should copy its child elements during parsing.
const Param_V & GetAttributes() const
Get all the attribute params.
void InsertElement(ElementPtr _elem)
Add an element object.
bool GetAttributeSet(const std::string &_key) const
Return true if the attribute was set (i.e.
void RemoveAllAttributes()
Removes all attributes.
void Copy(const ElementPtr _elem, sdf::Errors &_errors)
Copy values from an Element.
void SetIncludeElement(sdf::ElementPtr _includeElem)
Set the element that was used to load this element.
void ClearElements()
Remove all child elements.
void Update(sdf::Errors &_errors)
Call the Update() callback on each element, as well as the embedded Param.
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.
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 _ignoreElemen...
void SetExplicitlySetInFile(const bool _value)
Set if the element and children where set or default in the original file.
void InsertElement(ElementPtr _elem, bool _setParentToSelf)
Add an element object, and optionally set the given element's parent to this object.
std::map< std::string, std::size_t > CountNamedElements(sdf::Errors &_errors, 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 va...
ElementPtr GetElementImpl(const std::string &_name) const
Get a pointer to the named element.
ElementPtr GetElementDescription(const std::string &_key) const
Get an element description using a key.
void AddAttribute(const std::string &_key, const std::string &_type, const std::string &_defaultvalue, bool _required, sdf::Errors &_errors, const std::string &_description="")
Add an attribute value.
void SetParent(const ElementPtr _parent)
Set the parent of this Element.
void PrintDocRightPane(std::string &_html, int _spacing, int &_index) const
Helper function for SDF::PrintDoc.
std::any GetAny(sdf::Errors &_errors, const std::string &_key="") const
Get the element value/attribute as a std::any.
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 va...
std::optional< int > LineNumber() const
Get the line number of this element within the SDF document.
ParamPtr GetAttribute(const std::string &_key) const
Get the param of an attribute.
bool GetCopyChildren() const
Return true if this Element's child elements should be copied during parsing.
ElementPtr GetElementDescription(unsigned int _index) const
Get an element description using an index.
sdf::ElementPtr GetIncludeElement() const
Get the element that was used to load this element.
void SetXmlPath(const std::string &_path)
Private data pointer.
void RemoveFromParent()
Remove this element from its parent.
bool GetExplicitlySetInFile() const
Return if the element was been explicitly set in the file.
std::any GetAny(const std::string &_key="") const
Get the element value/attribute as a std::any.
void AddValue(const std::string &_type, const std::string &_defaultValue, bool _required, const std::string &_description="")
Add a value to this Element.
void PrintDescription(const std::string &_prefix) const
Output Element's description to stdout.
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...
void PrintValues(std::string _prefix, const PrintConfig &_config=PrintConfig()) const
Output Element's values to stdout.
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 AddValue(const std::string &_type, const std::string &_defaultValue, bool _required, sdf::Errors &_errors, const std::string &_description="")
Add a value to this Element.
bool HasAttribute(const std::string &_key) const
Return true if an attribute exists.
bool HasElement(const std::string &_name) const
Return true if the named element exists.
void PrintDocLeftPane(std::string &_html, int _spacing, int &_index) const
Helper function for SDF::PrintDoc.
void SetDescription(const std::string &_desc)
Set a text description for the element.
ElementPtr Clone(sdf::Errors &_errors) const
Create a copy of this Element.
const std::string & XmlPath() const
Get the XML path of this element.
ParamPtr GetAttribute(unsigned int _index) const
Get an attribute using an index.
std::set< std::string > GetElementTypeNames() const
Get set of child element type names.
static std::vector< std::string > NameUniquenessExceptions()
List of elements to which exceptions are made when checking for name uniqueness.
bool HasUniqueChildNames(const std::string &_type="") const
Checks whether any child elements of the specified element type have identical name attribute values ...
ElementPtr AddElement(const std::string &_name)
Add a named element.
ElementPtr Clone() const
Create a copy of this Element.
std::string ToString(const std::string &_prefix, const PrintConfig &_config=PrintConfig()) const
Convert the element values to a string representation.
ElementPtr GetElement(const std::string &_name, sdf::Errors &_errors)
Return a pointer to the child element with the provided name.
void SetReferenceSDF(const std::string &_value)
Set reference SDF element.
void PrintValues(sdf::Errors &_errors, const std::string &_prefix, bool _includeDefaultElements, bool _includeDefaultAttributes, const PrintConfig &_config=PrintConfig()) const
Output Element's values to stdout.
void RemoveChild(ElementPtr _child, sdf::Errors &_errors)
Remove a child element.
std::map< std::string, std::size_t > CountNamedElements(sdf::Errors &_errors, const std::string &_type="") const
Count the number of child elements of the specified element type that have the same name attribute va...
size_t GetElementDescriptionCount() const
Get the number of element descriptions.
void AddValue(const std::string &_type, const std::string &_defaultValue, bool _required, const std::string &_minValue, const std::string &_maxValue, sdf::Errors &_errors, const std::string &_description="")
Add a value to this Element.
ElementPtr GetFirstElement() const
Get the first child element.
ElementPtr FindElement(const std::string &_name)
Return a pointer to the child element with the provided name.
ElementPtr GetElement(const std::string &_name)
Return a pointer to the child element with the provided name.
ElementConstPtr FindElement(const std::string &_name) const
Return a pointer to the child element with the provided name.
ElementPtr GetParent() const
Get a pointer to this Element's parent.
void SetFilePath(const std::string &_path)
Set the path to the SDF document where this element came from.
const std::string & GetName() const
Get the Element's name.
void SetName(const std::string &_name)
Set the name of the Element.
std::string ToString(sdf::Errors &_errors, const std::string &_prefix, bool _includeDefaultElements, bool _includeDefaultAttributes, const PrintConfig &_config=PrintConfig()) const
Convert the element values to a string representation.
This class contains configuration options for printing elements.
Definition: PrintConfig.hh:33
#define sdferr
Output an error message.
Definition: Console.hh:57
T Get(sdf::Errors &_errors, const std::string &_key="") const
Get the value of a key.
Definition: Element.hh:959
bool Set(const T &_value)
Set the value of this element.
Definition: Element.hh:1058
void GZ_SDFORMAT_VISIBLE throwOrPrintError(sdf::Console::ConsoleStream &_out, const sdf::Error &_error)
Prints the error to _out or throw using SDF_ASSERT depending on the ErrorCode in _error.
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:70
std::vector< ParamPtr > Param_V
Definition: Param.hh:74
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:67
std::shared_ptr< const Element > ElementConstPtr
Definition: Element.hh:59
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:95
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:63
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:55
namespace for Simulation Description Format parser
Definition: Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25