Loading...
Searching...
No Matches
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 <optional>
24#include <set>
25#include <string>
26#include <unordered_set>
27#include <utility>
28#include <vector>
29
30#include "sdf/Error.hh"
31#include "sdf/Param.hh"
32#include "sdf/PrintConfig.hh"
33#include "sdf/config.hh"
34#include "sdf/system_util.hh"
35#include "sdf/Types.hh"
36
37#ifdef _WIN32
38// Disable warning C4251 which is triggered by
39// std::enable_shared_from_this
40#pragma warning(push)
41#pragma warning(disable: 4251)
42#endif
43
46namespace sdf
47{
48 // Inline bracket to help doxygen filtering.
49 inline namespace SDF_VERSION_NAMESPACE {
50 //
51
52 class ElementPrivate;
54
57 typedef std::shared_ptr<Element> ElementPtr;
58
61 typedef std::shared_ptr<const Element> ElementConstPtr;
62
65 typedef std::weak_ptr<Element> ElementWeakPtr;
66
69 typedef std::vector<ElementPtr> ElementPtr_V;
70
73
77 public std::enable_shared_from_this<Element>
78 {
80 public: Element();
81
83 public: virtual ~Element();
84
87 public: ElementPtr Clone() const;
88
92 public: ElementPtr Clone(sdf::Errors &_errors) const;
93
96 public: void Copy(const ElementPtr _elem);
97
101 public: void Copy(const ElementPtr _elem, sdf::Errors &_errors);
102
106 public: ElementPtr GetParent() const;
107
110 public: void SetParent(const ElementPtr _parent);
111
114 public: void SetName(const std::string &_name);
115
118 public: const std::string &GetName() const;
119
127 public: void SetRequired(const std::string &_req);
128
132 public: const std::string &GetRequired() const;
133
139 public: void SetExplicitlySetInFile(const bool _value);
140
143 public: bool GetExplicitlySetInFile() const;
144
148 public: void SetCopyChildren(bool _value);
149
153 public: bool GetCopyChildren() const;
154
157 public: void SetReferenceSDF(const std::string &_value);
158
161 public: std::string ReferenceSDF() const;
162
165 public: void PrintDescription(const std::string &_prefix) const;
166
170 public: void PrintDescription(sdf::Errors &_errors,
171 const std::string &_prefix) const;
172
176 public: void PrintValues(std::string _prefix,
177 const PrintConfig &_config = PrintConfig()) const;
178
183 public: void PrintValues(sdf::Errors &_errors,
184 std::string _prefix,
185 const PrintConfig &_config = PrintConfig()) const;
186
192 public: void PrintValues(const std::string &_prefix,
193 bool _includeDefaultElements,
194 bool _includeDefaultAttributes,
195 const PrintConfig &_config = PrintConfig()) const;
196
203 public: void PrintValues(sdf::Errors &_errors,
204 const std::string &_prefix,
205 bool _includeDefaultElements,
206 bool _includeDefaultAttributes,
207 const PrintConfig &_config = PrintConfig()) const;
208
215 public: void PrintDocLeftPane(std::string &_html,
216 int _spacing, int &_index) const;
217
223 public: void PrintDocRightPane(std::string &_html,
224 int _spacing, int &_index) const;
225
230 public: std::string ToString(
231 const std::string &_prefix,
232 const PrintConfig &_config = PrintConfig()) const;
233
239 public: std::string ToString(
240 sdf::Errors &_errors,
241 const std::string &_prefix,
242 const PrintConfig &_config = PrintConfig()) const;
243
253 public: std::string ToString(
254 const std::string &_prefix,
255 bool _includeDefaultElements,
256 bool _includeDefaultAttributes,
257 const PrintConfig &_config = PrintConfig()) const;
258
269 public: std::string ToString(
270 sdf::Errors &_errors,
271 const std::string &_prefix,
272 bool _includeDefaultElements,
273 bool _includeDefaultAttributes,
274 const PrintConfig &_config = PrintConfig()) const;
275
283 public: void AddAttribute(const std::string &_key,
284 const std::string &_type,
285 const std::string &_defaultvalue,
286 bool _required,
287 const std::string &_description = "");
288
297 public: void AddAttribute(const std::string &_key,
298 const std::string &_type,
299 const std::string &_defaultvalue,
300 bool _required,
301 sdf::Errors &_errors,
302 const std::string &_description = "");
303
310 public: void AddValue(const std::string &_type,
311 const std::string &_defaultValue, bool _required,
312 const std::string &_description = "");
313
321 public: void AddValue(const std::string &_type,
322 const std::string &_defaultValue, bool _required,
323 sdf::Errors &_errors,
324 const std::string &_description = "");
325
335 public: void AddValue(const std::string &_type,
336 const std::string &_defaultValue, bool _required,
337 const std::string &_minValue,
338 const std::string &_maxValue,
339 const std::string &_description = "");
340
351 public: void AddValue(const std::string &_type,
352 const std::string &_defaultValue, bool _required,
353 const std::string &_minValue,
354 const std::string &_maxValue,
355 sdf::Errors &_errors,
356 const std::string &_description = "");
357
361 public: ParamPtr GetAttribute(const std::string &_key) const;
362
365 public: size_t GetAttributeCount() const;
366
369 public: const Param_V &GetAttributes() const;
370
374 public: ParamPtr GetAttribute(unsigned int _index) const;
375
378 public: size_t GetElementDescriptionCount() const;
379
383 public: ElementPtr GetElementDescription(unsigned int _index) const;
384
388 public: ElementPtr GetElementDescription(const std::string &_key) const;
389
394 public: ElementConstPtr ElementDescription(unsigned int _index) const;
395
400 public: ElementConstPtr ElementDescription(const std::string &_key) const;
401
405 public: ElementPtr MutableElementDescription(unsigned int _index);
406
410 public: ElementPtr MutableElementDescription(const std::string &_key);
411
415 public: bool HasElementDescription(const std::string &_name) const;
416
420 public: bool HasAttribute(const std::string &_key) const;
421
425 public: bool GetAttributeSet(const std::string &_key) const;
426
429 public: void RemoveAttribute(const std::string &_key);
430
432 public: void RemoveAllAttributes();
433
436 public: ParamPtr GetValue() const;
437
442 public: std::any GetAny(const std::string &_key = "") const;
443
449 public: std::any GetAny(sdf::Errors &_errors,
450 const std::string &_key = "") const;
451
459 public: template<typename T>
460 T Get(sdf::Errors &_errors,
461 const std::string &_key = "") const;
462
469 public: template<typename T>
470 T Get(const std::string &_key = "") const;
471
479 public: template<typename T>
480 std::pair<T, bool> Get(sdf::Errors &_errors,
481 const std::string &_key,
482 const T &_defaultValue) const;
489 public: template<typename T>
490 std::pair<T, bool> Get(const std::string &_key,
491 const T &_defaultValue) const;
492
499 public: template<typename T>
500 bool Get(const std::string &_key,
501 T &_param,
502 const T &_defaultValue) const;
503
511 public: template<typename T>
512 bool Get(sdf::Errors &_errors,
513 const std::string &_key,
514 T &_param,
515 const T &_defaultValue) const;
516
520 public: template<typename T>
521 bool Set(const T &_value);
522
527 public: template<typename T>
528 bool Set(sdf::Errors &_errors, const T &_value);
529
533 public: bool HasElement(const std::string &_name) const;
534
539
551 public: ElementPtr GetNextElement(const std::string &_name = "") const;
552
555 public: std::set<std::string> GetElementTypeNames() const;
556
564 public: bool HasUniqueChildNames(const std::string &_type = "") const;
565
574 public: bool HasUniqueChildNames(sdf::Errors &_errors,
575 const std::string &_type = "") const;
576
588 const std::string &_type,
589 const std::vector<std::string> &_ignoreElements) const;
590
603 sdf::Errors &_errors,
604 const std::string &_type,
605 const std::vector<std::string> &_ignoreElements) const;
606
614 public: std::map<std::string, std::size_t>
615 CountNamedElements(const std::string &_type = "") const;
616
625 public: std::map<std::string, std::size_t>
627 const std::string &_type = "") const;
628
639 public: std::map<std::string, std::size_t> CountNamedElements(
640 const std::string &_type,
641 const std::vector<std::string> &_ignoreElements) const;
642
654 public: std::map<std::string, std::size_t> CountNamedElements(
655 sdf::Errors &_errors,
656 const std::string &_type,
657 const std::vector<std::string> &_ignoreElements) const;
658
669 public: ElementPtr GetElement(const std::string &_name);
670
682 public: ElementPtr GetElement(const std::string &_name,
683 sdf::Errors &_errors);
684
694 public: ElementPtr FindElement(const std::string &_name);
695
705 public: ElementConstPtr FindElement(const std::string &_name) const;
706
710 public: ElementPtr AddElement(const std::string &_name);
711
716 public: ElementPtr AddElement(const std::string &_name,
717 sdf::Errors &_errors);
718
721 public: void InsertElement(ElementPtr _elem);
722
728 public: void InsertElement(ElementPtr _elem, bool _setParentToSelf);
729
731 public: void RemoveFromParent();
732
735 public: void RemoveChild(ElementPtr _child);
736
740 public: void RemoveChild(ElementPtr _child, sdf::Errors &_errors);
741
743 public: void ClearElements();
744
747 public: void Clear();
748
751 public: void Update();
752
756 public: void Update(sdf::Errors &_errors);
757
761 public: void Reset();
762
768 public: void SetIncludeElement(sdf::ElementPtr _includeElem);
769
775
778 public: void SetFilePath(const std::string &_path);
779
782 public: const std::string &FilePath() const;
783
786 public: void SetLineNumber(int _lineNumber);
787
791 public: std::optional<int> LineNumber() const;
792
807 public: void SetXmlPath(const std::string &_path);
808
811 public: const std::string &XmlPath() const;
812
815 public: void SetOriginalVersion(const std::string &_version);
816
819 public: const std::string &OriginalVersion() const;
820
823 public: std::string GetDescription() const;
824
827 public: void SetDescription(const std::string &_desc);
828
832
836 public: ElementPtr GetElementImpl(const std::string &_name) const;
837
841 public: static std::vector<std::string> NameUniquenessExceptions();
842
850 private: void ToString(sdf::Errors &_errors,
851 std::ostringstream &_out,
852 const std::string &_prefix,
853 bool _includeDefaultElements,
854 bool _includeDefaultAttributes,
855 const PrintConfig &_config) const;
856
864 private: void PrintValuesImpl(sdf::Errors &_errors,
865 const std::string &_prefix,
866 bool _includeDefaultElements,
867 bool _includeDefaultAttributes,
868 const PrintConfig &_config,
869 std::ostringstream &_out) const;
870
880 private: ParamPtr CreateParam(const std::string &_key,
881 const std::string &_type,
882 const std::string &_defaultValue,
883 bool _required,
884 sdf::Errors &_errors,
885 const std::string &_description = "");
886
888 private: std::unique_ptr<ElementPrivate> dataPtr;
889 };
890
894 {
896 public: std::string name;
897
899 public: std::string required;
900
902 public: std::string description;
903
905 public: bool copyChildren;
906
909
910 // Attributes of this element
912
913 // Value of this element
915
916 // The existing child elements
918
919 // The possible child elements
921
943
945 public: std::string referenceSDF;
946
948 public: std::string path;
949
951 public: std::string originalVersion;
952
955
957 public: std::optional<int> lineNumber;
958
960 public: std::string xmlPath;
961
964 public: std::unordered_set<ElementConstPtr> clonedElementDescriptions;
965
970 public: void PrintAttributes(bool _includeDefaultAttributes,
971 const PrintConfig &_config,
972 std::ostringstream &_out) const;
973
979 public: void PrintAttributes(sdf::Errors &_errors,
980 bool _includeDefaultAttributes,
981 const PrintConfig &_config,
982 std::ostringstream &_out) const;
983
988 public:
989 std::optional<unsigned int> ElementDescriptionIndex(
990 const std::string &_key);
991 };
992
994 template<typename T>
995 T Element::Get(sdf::Errors &_errors, const std::string &_key) const
996 {
997 T result = T();
998
999 std::pair<T, bool> ret = this->Get<T>(_errors, _key, result);
1000
1001 return ret.first;
1002 }
1003
1005 template<typename T>
1006 T Element::Get(const std::string &_key) const
1007 {
1008 T result = T();
1009
1010 std::pair<T, bool> ret = this->Get<T>(_key, result);
1011
1012 return ret.first;
1013 }
1014
1016 template<typename T>
1018 const std::string &_key,
1019 T &_param,
1020 const T &_defaultValue) const
1021 {
1022 std::pair<T, bool> ret = this->Get<T>(_errors, _key, _defaultValue);
1023 _param = ret.first;
1024 return ret.second;
1025 }
1026
1028 template<typename T>
1029 bool Element::Get(const std::string &_key,
1030 T &_param,
1031 const T &_defaultValue) const
1032 {
1033 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
1034 _param = ret.first;
1035 return ret.second;
1036 }
1037
1039 template<typename T>
1040 std::pair<T, bool> Element::Get(const std::string &_key,
1041 const T &_defaultValue) const
1042 {
1043 sdf::Errors errors;
1044 std::pair<T, bool> result = this->Get<T>(errors, _key, _defaultValue);
1045 for(auto& error : errors)
1046 {
1048 }
1049 return result;
1050 }
1051
1053 template<typename T>
1054 std::pair<T, bool> Element::Get(sdf::Errors &_errors,
1055 const std::string &_key,
1056 const T &_defaultValue) const
1057 {
1058 std::pair<T, bool> result(_defaultValue, true);
1059
1060 if (_key.empty() && this->dataPtr->value)
1061 {
1062 this->dataPtr->value->Get<T>(result.first, _errors);
1063 }
1064 else if (!_key.empty())
1065 {
1066 ParamPtr param = this->GetAttribute(_key);
1067 if (param)
1068 {
1069 param->Get(result.first, _errors);
1070 }
1071 else if (this->HasElement(_key))
1072 {
1073 result.first = this->GetElementImpl(_key)->Get<T>(_errors);
1074 }
1075 else if (this->HasElementDescription(_key))
1076 {
1077 result.first = this->ElementDescription(_key)->Get<T>(_errors);
1078 }
1079 else
1080 {
1081 result.second = false;
1082 }
1083 }
1084 else
1085 {
1086 result.second = false;
1087 }
1088
1089 return result;
1090 }
1091
1093 template<typename T>
1094 bool Element::Set(const T &_value)
1095 {
1096 sdf::Errors errors;
1097 bool result = this->Set<T>(errors, _value);
1098 for(auto& error : errors)
1099 {
1101 }
1102 return result;
1103 }
1104
1106 template<typename T>
1107 bool Element::Set(sdf::Errors &_errors, const T &_value)
1108 {
1109 if (this->dataPtr->value)
1110 {
1111 return this->dataPtr->value->Set(_value, _errors);
1112 }
1113 return false;
1114 }
1116 }
1117}
1118
1119#ifdef _WIN32
1120#pragma warning(pop)
1121#endif
1122
1123#endif
Definition Element.hh:894
bool explicitlySetInFile
True if the element was set in the SDF file.
Definition Element.hh:954
ElementWeakPtr parent
Element's parent.
Definition Element.hh:908
std::string description
Element description.
Definition Element.hh:902
void PrintAttributes(bool _includeDefaultAttributes, const PrintConfig &_config, std::ostringstream &_out) const
Generate the string (XML) for the attributes.
ElementPtr_V elements
Definition Element.hh:917
std::unordered_set< ElementConstPtr > clonedElementDescriptions
Used to keep track of which element descriptions we have cloned in order to provide a mutable pointer...
Definition Element.hh:964
std::string referenceSDF
Name of reference sdf.
Definition Element.hh:945
bool copyChildren
True if element's children should be copied.
Definition Element.hh:905
Param_V attributes
Definition Element.hh:911
std::string required
True if element is required.
Definition Element.hh:899
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:914
std::string name
Element name.
Definition Element.hh:896
std::optional< unsigned int > ElementDescriptionIndex(const std::string &_key)
Helper function to get the index of an element description identified by a given key.
ElementPtr_V elementDescriptions
Definition Element.hh:920
std::string originalVersion
Spec version that this was originally parsed from.
Definition Element.hh:951
std::string xmlPath
XML path of this element.
Definition Element.hh:960
std::string path
Path to file where this element came from.
Definition Element.hh:948
std::optional< int > lineNumber
Line number in file where this element came from.
Definition Element.hh:957
ElementPtr includeElement
The element that was used to load this entity.
Definition Element.hh:942
SDF Element class.
Definition Element.hh:78
void SetOriginalVersion(const std::string &_version)
Set the spec version that this was originally parsed from.
void Copy(const ElementPtr _elem)
Copy values from an Element.
const std::string & XmlPath() const
Get the XML path of this element.
void RemoveChild(ElementPtr _child)
Remove a child element.
ElementConstPtr ElementDescription(unsigned int _index) const
Get an element description using an index.
std::string GetDescription() const
Get a text description of the element.
const std::string & FilePath() const
Get the path to the SDF document where this element came from.
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 GetAttributeCount() const
Get the number of attributes.
const std::string & GetRequired() const
Get the requirement string.
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.
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.
std::optional< int > LineNumber() const
Get the line number of this element within the SDF document.
ElementPtr MutableElementDescription(unsigned int _index)
Get a mutable element description using an index.
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.
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...
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.
const std::string & OriginalVersion() const
Get the spec version that this was originally parsed from.
void RemoveAttribute(const std::string &_key)
Remove an attribute.
void SetCopyChildren(bool _value)
Set whether this element should copy its child elements during parsing.
void InsertElement(ElementPtr _elem)
Add an element object.
bool GetAttributeSet(const std::string &_key) const
Return true if the attribute was set (i.e.
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 RemoveAllAttributes()
Removes all attributes.
const std::string & GetName() const
Get the Element's name.
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.
ElementPtr MutableElementDescription(const std::string &_key)
Get a mutable element description using a key.
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.
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.
ElementConstPtr ElementDescription(const std::string &_key) const
Get an element description using a key.
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.
std::set< std::string > GetElementTypeNames() const
Get set of child element type names.
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.
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.
ParamPtr GetAttribute(unsigned int _index) const
Get an attribute using an index.
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::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...
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.
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.
const Param_V & GetAttributes() const
Get all the attribute params.
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.
static std::vector< std::string > NameUniquenessExceptions()
List of elements to which exceptions are made when checking for name uniqueness.
void SetFilePath(const std::string &_path)
Set the path to the SDF document where this element came from.
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:995
bool Set(const T &_value)
Set the value of this element.
Definition Element.hh:1094
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:69
std::shared_ptr< const Element > ElementConstPtr
Definition Element.hh:61
std::vector< Error > Errors
A vector of Error.
Definition Types.hh:80
std::weak_ptr< Element > ElementWeakPtr
Definition Element.hh:65
std::shared_ptr< Element > ElementPtr
Definition Element.hh:57
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