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>
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 =
"");
224 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
228 public:
size_t GetAttributeCount()
const;
233 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
237 public:
size_t GetElementDescriptionCount()
const;
242 public:
ElementPtr GetElementDescription(
unsigned int _index)
const;
247 public:
ElementPtr GetElementDescription(
const std::string &_key)
const;
252 public:
bool HasElementDescription(
const std::string &_name)
const;
257 public:
bool HasAttribute(
const std::string &_key)
const;
262 public:
bool GetAttributeSet(
const std::string &_key)
const;
266 public:
void RemoveAttribute(
const std::string &_key);
269 public:
void RemoveAllAttributes();
279 public: std::any GetAny(
const std::string &_key =
"")
const;
287 public:
template<
typename T>
288 T Get(
const std::string &_key =
"")
const;
296 public:
template<
typename T>
297 std::pair<T, bool> Get(
const std::string &_key,
298 const T &_defaultValue)
const;
306 public:
template<
typename T>
307 bool Get(
const std::string &_key,
309 const T &_defaultValue)
const;
314 public:
template<
typename T>
315 bool Set(
const T &_value);
320 public:
bool HasElement(
const std::string &_name)
const;
338 public:
ElementPtr GetNextElement(
const std::string &_name =
"")
const;
342 public: std::set<std::string> GetElementTypeNames()
const;
351 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
363 public:
bool HasUniqueChildNames(
364 const std::string &_type,
365 const std::vector<std::string> &_ignoreElements)
const;
374 public: std::map<std::string, std::size_t>
375 CountNamedElements(
const std::string &_type =
"")
const;
387 public: std::map<std::string, std::size_t> CountNamedElements(
388 const std::string &_type,
389 const std::vector<std::string> &_ignoreElements)
const;
401 public:
ElementPtr GetElement(
const std::string &_name);
412 public:
ElementPtr FindElement(
const std::string &_name);
428 public:
ElementPtr AddElement(
const std::string &_name);
435 public:
void RemoveFromParent();
442 public:
void ClearElements();
446 public:
void Clear();
450 public:
void Update();
455 public:
void Reset();
459 public:
void SetInclude(
const std::string &_filename);
463 public: std::string GetInclude()
const;
467 public:
void SetFilePath(
const std::string &_path);
471 public:
const std::string &FilePath()
const;
475 public:
void SetOriginalVersion(
const std::string &_version);
479 public:
const std::string &OriginalVersion()
const;
483 public: std::string GetDescription()
const;
487 public:
void SetDescription(
const std::string &_desc);
491 public:
void AddElementDescription(
ElementPtr _elem);
496 public:
ElementPtr GetElementImpl(
const std::string &_name)
const;
501 public:
static std::vector<std::string> NameUniquenessExceptions();
508 private:
void ToString(
const std::string &_prefix,
509 bool _includeDefaultElements,
510 bool _includeDefaultAttributes,
511 std::ostringstream &_out)
const;
518 private:
void PrintValuesImpl(
const std::string &_prefix,
519 bool _includeDefaultElements,
520 bool _includeDefaultAttributes,
521 std::ostringstream &_out)
const;
531 private:
ParamPtr CreateParam(
const std::string &_key,
532 const std::string &_type,
533 const std::string &_defaultValue,
535 const std::string &_description =
"");
539 private: std::unique_ptr<ElementPrivate> dataPtr;
591 T Element::Get(
const std::string &_key)
const
595 std::pair<T, bool> ret = this->Get<T>(_key, result);
602 bool Element::Get(
const std::string &_key,
604 const T &_defaultValue)
const
606 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
613 std::pair<T, bool> Element::Get(
const std::string &_key,
614 const T &_defaultValue)
const
616 std::pair<T, bool> result(_defaultValue,
true);
618 if (_key.empty() && this->dataPtr->value)
620 this->dataPtr->value->Get<T>(result.first);
622 else if (!_key.empty())
624 ParamPtr param = this->GetAttribute(_key);
627 param->Get(result.first);
629 else if (this->HasElement(_key))
631 result.first = this->GetElementImpl(_key)->Get<T>();
633 else if (this->HasElementDescription(_key))
635 result.first = this->GetElementDescription(_key)->Get<T>();
639 result.second =
false;
644 result.second =
false;
652 bool Element::Set(
const T &_value)
654 if (this->dataPtr->value)
656 return this->dataPtr->value->Set(_value);