17 #ifndef SDF_ELEMENT_HH_ 18 #define SDF_ELEMENT_HH_ 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;
379 public:
bool HasUniqueChildNames(
380 const std::string &_type,
381 const std::vector<std::string> &_ignoreElements)
const;
390 public: std::map<std::string, std::size_t>
391 CountNamedElements(
const std::string &_type =
"")
const;
403 public: std::map<std::string, std::size_t> CountNamedElements(
404 const std::string &_type,
405 const std::vector<std::string> &_ignoreElements)
const;
417 public: ElementPtr GetElement(
const std::string &_name);
428 public: ElementPtr FindElement(
const std::string &_name);
439 public: ElementConstPtr FindElement(
const std::string &_name)
const;
444 public: ElementPtr AddElement(
const std::string &_name);
448 public:
void InsertElement(ElementPtr _elem);
451 public:
void RemoveFromParent();
455 public:
void RemoveChild(ElementPtr _child);
458 public:
void ClearElements();
462 public:
void Clear();
466 public:
void Update();
471 public:
void Reset();
475 public:
void SetInclude(
const std::string &_filename)
SDF_DEPRECATED(11.0);
496 public:
void SetFilePath(
const std::string &_path);
500 public:
const std::string &FilePath()
const;
504 public:
void SetLineNumber(
int _lineNumber);
509 public: std::optional<int> LineNumber()
const;
525 public:
void SetXmlPath(
const std::string &_path);
529 public:
const std::string &XmlPath()
const;
533 public:
void SetOriginalVersion(
const std::string &_version);
537 public:
const std::string &OriginalVersion()
const;
541 public: std::string GetDescription()
const;
545 public:
void SetDescription(
const std::string &_desc);
549 public:
void AddElementDescription(ElementPtr _elem);
554 public: ElementPtr GetElementImpl(
const std::string &_name)
const;
559 public:
static std::vector<std::string> NameUniquenessExceptions();
566 private:
void ToString(
const std::string &_prefix,
567 bool _includeDefaultElements,
568 bool _includeDefaultAttributes,
569 std::ostringstream &_out)
const;
576 private:
void PrintValuesImpl(
const std::string &_prefix,
577 bool _includeDefaultElements,
578 bool _includeDefaultAttributes,
579 std::ostringstream &_out)
const;
589 private:
ParamPtr CreateParam(
const std::string &_key,
590 const std::string &_type,
591 const std::string &_defaultValue,
593 const std::string &_description =
"");
597 private: std::unique_ptr<ElementPrivate> dataPtr;
681 std::pair<T, bool> ret = this->Get<T>(_key, result);
690 const T &_defaultValue)
const 692 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
700 const T &_defaultValue)
const 702 std::pair<T, bool> result(_defaultValue,
true);
704 if (_key.empty() && this->dataPtr->value)
706 this->dataPtr->value->Get<T>(result.first);
708 else if (!_key.empty())
710 ParamPtr param = this->GetAttribute(_key);
713 param->Get(result.first);
715 else if (this->HasElement(_key))
717 result.first = this->GetElementImpl(_key)->Get<T>();
719 else if (this->HasElementDescription(_key))
721 result.first = this->GetElementDescription(_key)->Get<T>();
725 result.second =
false;
730 result.second =
false;
740 if (this->dataPtr->value)
742 this->dataPtr->value->Set(_value);
std::string required
True if element is required.
Definition: Element.hh:608
std::string includeFilename
name of the include file that was used to create this element
Definition: Element.hh:654
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:60
std::string name
Element name.
Definition: Element.hh:605
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:65
std::vector< ParamPtr > Param_V
Definition: Param.hh:64
Param_V attributes
Definition: Element.hh:620
ParamPtr value
Definition: Element.hh:623
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:53
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:61
ElementPtr includeElement
The element that was used to load this entity.
Definition: Element.hh:651
std::string path
Path to file where this element came from.
Definition: Element.hh:660
std::string xmlPath
XML path of this element.
Definition: Element.hh:672
ElementPtr_V elementDescriptions
Definition: Element.hh:629
std::optional< int > lineNumber
Line number in file where this element came from.
Definition: Element.hh:669
bool Set(const T &_value)
Set the value of this element.
Definition: Element.hh:738
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:657
std::string description
Element description.
Definition: Element.hh:611
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25
Definition: Element.hh:602
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:614
class SDFORMAT_VISIBLE Element
Definition: Element.hh:49
std::string originalVersion
Spec version that this was originally parsed from.
Definition: Element.hh:663
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:617
T Get(const std::string &_key="") const
Get the value of a key.
Definition: Element.hh:677
SDF Element class.
Definition: Element.hh:72
namespace for Simulation Description Format parser
Definition: Actor.hh:33
ElementPtr_V elements
Definition: Element.hh:626
bool explicitlySetInFile
True if the element was set in the SDF file.
Definition: Element.hh:666
#define SDF_DEPRECATED(version)
Definition: Types.hh:39
std::shared_ptr< const Element > ElementConstPtr
Definition: Element.hh:57