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 {
73 public std::enable_shared_from_this<Element>
83 public: ElementPtr Clone()
const;
87 public:
void Copy(
const ElementPtr _elem);
92 public: ElementPtr GetParent()
const;
96 public:
void SetParent(
const ElementPtr _parent);
100 public:
void SetName(
const std::string &_name);
104 public:
const std::string &GetName()
const;
113 public:
void SetRequired(
const std::string &_req);
118 public:
const std::string &GetRequired()
const;
125 public:
void SetExplicitlySetInFile(
const bool _value);
129 public:
bool GetExplicitlySetInFile()
const;
134 public:
void SetCopyChildren(
bool _value);
139 public:
bool GetCopyChildren()
const;
143 public:
void SetReferenceSDF(
const std::string &_value);
147 public: std::string ReferenceSDF()
const;
151 public:
void PrintDescription(
const std::string &_prefix)
const;
155 public:
void PrintValues(std::string _prefix)
const;
161 public:
void PrintValues(
const std::string &_prefix,
162 bool _includeDefaultElements,
163 bool _includeDefaultAttributes)
const;
171 public:
void PrintDocLeftPane(std::string &_html,
172 int _spacing,
int &_index)
const;
179 public:
void PrintDocRightPane(std::string &_html,
180 int _spacing,
int &_index)
const;
185 public: std::string ToString(
const std::string &_prefix)
const;
195 public: std::string ToString(
const std::string &_prefix,
196 bool _includeDefaultElements,
197 bool _includeDefaultAttributes)
const;
206 public:
void AddAttribute(
const std::string &_key,
207 const std::string &_type,
208 const std::string &_defaultvalue,
210 const std::string &_description =
"");
218 public:
void AddValue(
const std::string &_type,
219 const std::string &_defaultValue,
bool _required,
220 const std::string &_description =
"");
231 public:
void AddValue(
const std::string &_type,
232 const std::string &_defaultValue,
bool _required,
233 const std::string &_minValue,
234 const std::string &_maxValue,
235 const std::string &_description =
"");
240 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
244 public:
size_t GetAttributeCount()
const;
249 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
253 public:
size_t GetElementDescriptionCount()
const;
258 public: ElementPtr GetElementDescription(
unsigned int _index)
const;
263 public: ElementPtr GetElementDescription(
const std::string &_key)
const;
268 public:
bool HasElementDescription(
const std::string &_name)
const;
273 public:
bool HasAttribute(
const std::string &_key)
const;
278 public:
bool GetAttributeSet(
const std::string &_key)
const;
282 public:
void RemoveAttribute(
const std::string &_key);
285 public:
void RemoveAllAttributes();
295 public: std::any GetAny(
const std::string &_key =
"")
const;
303 public:
template<
typename T>
304 T Get(
const std::string &_key =
"")
const;
312 public:
template<
typename T>
313 std::pair<T, bool> Get(
const std::string &_key,
314 const T &_defaultValue)
const;
322 public:
template<
typename T>
323 bool Get(
const std::string &_key,
325 const T &_defaultValue)
const;
330 public:
template<
typename T>
331 bool Set(
const T &_value);
336 public:
bool HasElement(
const std::string &_name)
const;
341 public: ElementPtr GetFirstElement()
const;
354 public: ElementPtr GetNextElement(
const std::string &_name =
"")
const;
358 public: std::set<std::string> GetElementTypeNames()
const;
367 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
376 public: std::map<std::string, std::size_t>
377 CountNamedElements(
const std::string &_type =
"")
const;
389 public: ElementPtr GetElement(
const std::string &_name);
400 public: ElementPtr FindElement(
const std::string &_name);
411 public: ElementConstPtr FindElement(
const std::string &_name)
const;
416 public: ElementPtr AddElement(
const std::string &_name);
420 public:
void InsertElement(ElementPtr _elem);
423 public:
void RemoveFromParent();
427 public:
void RemoveChild(ElementPtr _child);
430 public:
void ClearElements();
434 public:
void Clear();
438 public:
void Update();
443 public:
void Reset();
447 public:
void SetInclude(
const std::string &_filename)
SDF_DEPRECATED(11.0);
468 public:
void SetFilePath(
const std::string &_path);
472 public:
const std::string &FilePath()
const;
476 public:
void SetLineNumber(
int _lineNumber);
481 public: std::optional<int> LineNumber()
const;
497 public:
void SetXmlPath(
const std::string &_path);
501 public:
const std::string &XmlPath()
const;
505 public:
void SetOriginalVersion(
const std::string &_version);
509 public:
const std::string &OriginalVersion()
const;
513 public: std::string GetDescription()
const;
517 public:
void SetDescription(
const std::string &_desc);
521 public:
void AddElementDescription(ElementPtr _elem);
526 public: ElementPtr GetElementImpl(
const std::string &_name)
const;
533 private:
void ToString(
const std::string &_prefix,
534 bool _includeDefaultElements,
535 bool _includeDefaultAttributes,
536 std::ostringstream &_out)
const;
543 private:
void PrintValuesImpl(
const std::string &_prefix,
544 bool _includeDefaultElements,
545 bool _includeDefaultAttributes,
546 std::ostringstream &_out)
const;
556 private:
ParamPtr CreateParam(
const std::string &_key,
557 const std::string &_type,
558 const std::string &_defaultValue,
560 const std::string &_description =
"");
564 private: std::unique_ptr<ElementPrivate> dataPtr;
644 T Element::Get(
const std::string &_key)
const 648 std::pair<T, bool> ret = this->Get<T>(_key, result);
655 bool Element::Get(
const std::string &_key,
657 const T &_defaultValue)
const 659 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
666 std::pair<T, bool> Element::Get(
const std::string &_key,
667 const T &_defaultValue)
const 669 std::pair<T, bool> result(_defaultValue,
true);
671 if (_key.empty() && this->dataPtr->value)
673 this->dataPtr->value->Get<T>(result.first);
675 else if (!_key.empty())
677 ParamPtr param = this->GetAttribute(_key);
680 param->Get(result.first);
682 else if (this->HasElement(_key))
684 result.first = this->GetElementImpl(_key)->Get<T>();
686 else if (this->HasElementDescription(_key))
688 result.first = this->GetElementDescription(_key)->Get<T>();
692 result.second =
false;
697 result.second =
false;
705 bool Element::Set(
const T &_value)
707 if (this->dataPtr->value)
709 this->dataPtr->value->Set(_value);
std::shared_ptr< const Element > ElementConstPtr
Definition: Element.hh:57
std::string name
Element name.
Definition: Element.hh:572
ParamPtr value
Definition: Element.hh:590
SDF Element class.
Definition: Element.hh:72
std::string originalVersion
Spec version that this was originally parsed from.
Definition: Element.hh:630
std::string description
Element description.
Definition: Element.hh:578
std::string includeFilename
name of the include file that was used to create this element
Definition: Element.hh:621
ElementPtr includeElement
The element that was used to load this entity.
Definition: Element.hh:618
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:581
ElementPtr_V elements
Definition: Element.hh:593
std::string required
True if element is required.
Definition: Element.hh:575
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:65
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:624
std::string path
Path to file where this element came from.
Definition: Element.hh:627
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:41
Definition: Element.hh:569
std::string xmlPath
XML path of this element.
Definition: Element.hh:639
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:53
bool explicitlySetInFile
True if the element was set in the SDF file.
Definition: Element.hh:633
class SDFORMAT_VISIBLE Element
Definition: Element.hh:49
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:584
namespace for Simulation Description Format parser
Definition: Actor.hh:33
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:60
std::vector< ParamPtr > Param_V
Definition: Param.hh:64
std::optional< int > lineNumber
Line number in file where this element came from.
Definition: Element.hh:636
ElementPtr_V elementDescriptions
Definition: Element.hh:596
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:61
#define SDF_DEPRECATED(version)
Definition: Types.hh:39
Param_V attributes
Definition: Element.hh:587