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>
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;
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);
459 public:
ElementPtr AddElement(
const std::string &_name);
466 public:
void RemoveFromParent();
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);