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;
112 public:
void SetRequired(
const std::string &_req);
117 public:
const std::string &GetRequired()
const;
124 public:
void SetExplicitlySetInFile(
const bool _value);
128 public:
bool GetExplicitlySetInFile()
const;
133 public:
void SetCopyChildren(
bool _value);
138 public:
bool GetCopyChildren()
const;
142 public:
void SetReferenceSDF(
const std::string &_value);
146 public: std::string ReferenceSDF()
const;
150 public:
void PrintDescription(
const std::string &_prefix)
const;
154 public:
void PrintValues(std::string _prefix)
const;
160 public:
void PrintValues(
const std::string &_prefix,
161 bool _includeDefaultElements,
162 bool _includeDefaultAttributes)
const;
170 public:
void PrintDocLeftPane(std::string &_html,
171 int _spacing,
int &_index)
const;
178 public:
void PrintDocRightPane(std::string &_html,
179 int _spacing,
int &_index)
const;
184 public: std::string ToString(
const std::string &_prefix)
const;
194 public: std::string ToString(
const std::string &_prefix,
195 bool _includeDefaultElements,
196 bool _includeDefaultAttributes)
const;
205 public:
void AddAttribute(
const std::string &_key,
206 const std::string &_type,
207 const std::string &_defaultvalue,
209 const std::string &_description =
"");
217 public:
void AddValue(
const std::string &_type,
218 const std::string &_defaultValue,
bool _required,
219 const std::string &_description =
"");
230 public:
void AddValue(
const std::string &_type,
231 const std::string &_defaultValue,
bool _required,
232 const std::string &_minValue,
233 const std::string &_maxValue,
234 const std::string &_description =
"");
239 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
243 public:
size_t GetAttributeCount()
const;
248 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
252 public:
size_t GetElementDescriptionCount()
const;
257 public: ElementPtr GetElementDescription(
unsigned int _index)
const;
262 public: ElementPtr GetElementDescription(
const std::string &_key)
const;
267 public:
bool HasElementDescription(
const std::string &_name)
const;
272 public:
bool HasAttribute(
const std::string &_key)
const;
277 public:
bool GetAttributeSet(
const std::string &_key)
const;
281 public:
void RemoveAttribute(
const std::string &_key);
284 public:
void RemoveAllAttributes();
294 public: std::any GetAny(
const std::string &_key =
"")
const;
302 public:
template<
typename T>
303 T Get(
const std::string &_key =
"")
const;
311 public:
template<
typename T>
312 std::pair<T, bool> Get(
const std::string &_key,
313 const T &_defaultValue)
const;
321 public:
template<
typename T>
322 bool Get(
const std::string &_key,
324 const T &_defaultValue)
const;
329 public:
template<
typename T>
330 bool Set(
const T &_value);
335 public:
bool HasElement(
const std::string &_name)
const;
340 public: ElementPtr GetFirstElement()
const;
353 public: ElementPtr GetNextElement(
const std::string &_name =
"")
const;
357 public: std::set<std::string> GetElementTypeNames()
const;
366 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
378 public:
bool HasUniqueChildNames(
379 const std::string &_type,
380 const std::vector<std::string> &_ignoreElements)
const;
389 public: std::map<std::string, std::size_t>
390 CountNamedElements(
const std::string &_type =
"")
const;
402 public: std::map<std::string, std::size_t> CountNamedElements(
403 const std::string &_type,
404 const std::vector<std::string> &_ignoreElements)
const;
416 public: ElementPtr GetElement(
const std::string &_name);
427 public: ElementPtr FindElement(
const std::string &_name);
438 public: ElementConstPtr FindElement(
const std::string &_name)
const;
443 public: ElementPtr AddElement(
const std::string &_name);
447 public:
void InsertElement(ElementPtr _elem);
450 public:
void RemoveFromParent();
454 public:
void RemoveChild(ElementPtr _child);
457 public:
void ClearElements();
461 public:
void Clear();
465 public:
void Update();
470 public:
void Reset();
474 public:
void SetInclude(
const std::string &_filename);
478 public: std::string GetInclude()
const;
482 public:
void SetFilePath(
const std::string &_path);
486 public:
const std::string &FilePath()
const;
490 public:
void SetOriginalVersion(
const std::string &_version);
494 public:
const std::string &OriginalVersion()
const;
498 public: std::string GetDescription()
const;
502 public:
void SetDescription(
const std::string &_desc);
506 public:
void AddElementDescription(ElementPtr _elem);
511 public: ElementPtr GetElementImpl(
const std::string &_name)
const;
516 public:
static std::vector<std::string> NameUniquenessExceptions();
523 private:
void ToString(
const std::string &_prefix,
524 bool _includeDefaultElements,
525 bool _includeDefaultAttributes,
526 std::ostringstream &_out)
const;
533 private:
void PrintValuesImpl(
const std::string &_prefix,
534 bool _includeDefaultElements,
535 bool _includeDefaultAttributes,
536 std::ostringstream &_out)
const;
546 private:
ParamPtr CreateParam(
const std::string &_key,
547 const std::string &_type,
548 const std::string &_defaultValue,
550 const std::string &_description =
"");
554 private: std::unique_ptr<ElementPrivate> dataPtr;
610 std::pair<T, bool> ret = this->Get<T>(_key, result);
619 const T &_defaultValue)
const 621 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
629 const T &_defaultValue)
const 631 std::pair<T, bool> result(_defaultValue,
true);
633 if (_key.empty() && this->dataPtr->value)
635 this->dataPtr->value->Get<T>(result.first);
637 else if (!_key.empty())
639 ParamPtr param = this->GetAttribute(_key);
642 param->Get(result.first);
644 else if (this->HasElement(_key))
646 result.first = this->GetElementImpl(_key)->Get<T>();
648 else if (this->HasElementDescription(_key))
650 result.first = this->GetElementDescription(_key)->Get<T>();
654 result.second =
false;
659 result.second =
false;
669 if (this->dataPtr->value)
671 this->dataPtr->value->Set(_value);
std::string required
True if element is required.
Definition: Element.hh:565
std::string includeFilename
name of the include file that was used to create this element
Definition: Element.hh:589
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:58
std::string name
Element name.
Definition: Element.hh:562
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:65
std::vector< ParamPtr > Param_V
Definition: Param.hh:62
Param_V attributes
Definition: Element.hh:577
ParamPtr value
Definition: Element.hh:580
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:53
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:61
std::string path
Path to file where this element came from.
Definition: Element.hh:595
ElementPtr_V elementDescriptions
Definition: Element.hh:586
bool Set(const T &_value)
Set the value of this element.
Definition: Element.hh:667
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:592
std::string description
Element description.
Definition: Element.hh:568
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25
Definition: Element.hh:559
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:571
class SDFORMAT_VISIBLE Element
Definition: Element.hh:49
std::string originalVersion
Spec version that this was originally parsed from.
Definition: Element.hh:598
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:574
T Get(const std::string &_key="") const
Get the value of a key.
Definition: Element.hh:606
SDF Element class.
Definition: Element.hh:72
namespace for Simulation Description Format parser
Definition: Actor.hh:32
ElementPtr_V elements
Definition: Element.hh:583
bool explicitlySetInFile
True if the element was set in the SDF file.
Definition: Element.hh:601
std::shared_ptr< const Element > ElementConstPtr
Definition: Element.hh:57