17 #ifndef SDF_ELEMENT_HH_ 18 #define SDF_ELEMENT_HH_ 30 #include "sdf/sdf_config.h" 38 #pragma warning(disable: 4251) 46 inline namespace SDF_VERSION_NAMESPACE {
74 public std::enable_shared_from_this<Element>
84 public: ElementPtr Clone()
const;
88 public:
void Copy(
const ElementPtr _elem);
93 public: ElementPtr GetParent()
const;
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;
356 public: ElementPtr GetFirstElement()
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);
454 public: ElementConstPtr FindElement(
const std::string &_name)
const;
459 public: ElementPtr AddElement(
const std::string &_name);
463 public:
void InsertElement(ElementPtr _elem);
466 public:
void RemoveFromParent();
470 public:
void RemoveChild(ElementPtr _child);
473 public:
void ClearElements();
477 public:
void Clear();
481 public:
void Update();
486 public:
void Reset();
503 public:
void SetFilePath(
const std::string &_path);
507 public:
const std::string &FilePath()
const;
511 public:
void SetLineNumber(
int _lineNumber);
516 public: std::optional<int> LineNumber()
const;
532 public:
void SetXmlPath(
const std::string &_path);
536 public:
const std::string &XmlPath()
const;
540 public:
void SetOriginalVersion(
const std::string &_version);
544 public:
const std::string &OriginalVersion()
const;
548 public: std::string GetDescription()
const;
552 public:
void SetDescription(
const std::string &_desc);
556 public:
void AddElementDescription(ElementPtr _elem);
561 public: ElementPtr GetElementImpl(
const std::string &_name)
const;
566 public:
static std::vector<std::string> NameUniquenessExceptions();
574 private:
void ToString(
const std::string &_prefix,
575 bool _includeDefaultElements,
576 bool _includeDefaultAttributes,
578 std::ostringstream &_out)
const;
586 private:
void PrintValuesImpl(
const std::string &_prefix,
587 bool _includeDefaultElements,
588 bool _includeDefaultAttributes,
590 std::ostringstream &_out)
const;
600 private:
ParamPtr CreateParam(
const std::string &_key,
601 const std::string &_type,
602 const std::string &_defaultValue,
604 const std::string &_description =
"");
608 private: std::unique_ptr<ElementPrivate> dataPtr;
685 T Element::Get(
const std::string &_key)
const 689 std::pair<T, bool> ret = this->Get<T>(_key, result);
696 bool Element::Get(
const std::string &_key,
698 const T &_defaultValue)
const 700 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
707 std::pair<T, bool> Element::Get(
const std::string &_key,
708 const T &_defaultValue)
const 710 std::pair<T, bool> result(_defaultValue,
true);
712 if (_key.empty() && this->dataPtr->value)
714 this->dataPtr->value->Get<T>(result.first);
716 else if (!_key.empty())
718 ParamPtr param = this->GetAttribute(_key);
721 param->Get(result.first);
723 else if (this->HasElement(_key))
725 result.first = this->GetElementImpl(_key)->Get<T>();
727 else if (this->HasElementDescription(_key))
729 result.first = this->GetElementDescription(_key)->Get<T>();
733 result.second =
false;
738 result.second =
false;
746 bool Element::Set(
const T &_value)
748 if (this->dataPtr->value)
750 this->dataPtr->value->Set(_value);
ParamPtr value
Definition: Element.hh:634
std::string xmlPath
XML path of this element.
Definition: Element.hh:680
ElementPtr includeElement
The element that was used to load this entity.
Definition: Element.hh:662
std::string required
True if element is required.
Definition: Element.hh:619
ElementPtr_V elements
Definition: Element.hh:637
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:665
Param_V attributes
Definition: Element.hh:631
std::string name
Element name.
Definition: Element.hh:616
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:54
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:62
std::shared_ptr< const Element > ElementConstPtr
Definition: Element.hh:58
std::optional< int > lineNumber
Line number in file where this element came from.
Definition: Element.hh:677
This class contains configuration options for printing elements.
Definition: PrintConfig.hh:31
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:625
bool explicitlySetInFile
True if the element was set in the SDF file.
Definition: Element.hh:674
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:66
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:41
std::string description
Element description.
Definition: Element.hh:622
SDF Element class.
Definition: Element.hh:73
ElementPtr_V elementDescriptions
Definition: Element.hh:640
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:628
namespace for Simulation Description Format parser
Definition: Actor.hh:33
Definition: Element.hh:613
std::vector< ParamPtr > Param_V
Definition: Param.hh:69
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:65
std::string path
Path to file where this element came from.
Definition: Element.hh:668
std::string originalVersion
Spec version that this was originally parsed from.
Definition: Element.hh:671