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 {
69 public std::enable_shared_from_this<Element>
92 public:
void SetParent(
const ElementPtr _parent);
96 public:
void SetName(
const std::string &_name);
100 public:
const std::string &GetName()
const;
109 public:
void SetRequired(
const std::string &_req);
114 public:
const std::string &GetRequired()
const;
121 public:
void SetExplicitlySetInFile(
const bool _value);
125 public:
bool GetExplicitlySetInFile()
const;
130 public:
void SetCopyChildren(
bool _value);
135 public:
bool GetCopyChildren()
const;
139 public:
void SetReferenceSDF(
const std::string &_value);
143 public: std::string ReferenceSDF()
const;
147 public:
void PrintDescription(
const std::string &_prefix)
const;
151 public:
void PrintValues(std::string _prefix)
const;
159 public:
void PrintDocLeftPane(std::string &_html,
160 int _spacing,
int &_index)
const;
167 public:
void PrintDocRightPane(std::string &_html,
168 int _spacing,
int &_index)
const;
173 public: std::string ToString(
const std::string &_prefix)
const;
182 public:
void AddAttribute(
const std::string &_key,
183 const std::string &_type,
184 const std::string &_defaultvalue,
186 const std::string &_description=
"");
194 public:
void AddValue(
const std::string &_type,
195 const std::string &_defaultValue,
bool _required,
196 const std::string &_description=
"");
207 public:
void AddValue(
const std::string &_type,
208 const std::string &_defaultValue,
bool _required,
209 const std::string &_minValue,
210 const std::string &_maxValue,
211 const std::string &_description =
"");
216 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
220 public:
size_t GetAttributeCount()
const;
225 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
229 public:
size_t GetElementDescriptionCount()
const;
234 public:
ElementPtr GetElementDescription(
unsigned int _index)
const;
239 public:
ElementPtr GetElementDescription(
const std::string &_key)
const;
244 public:
bool HasElementDescription(
const std::string &_name)
const;
249 public:
bool HasAttribute(
const std::string &_key)
const;
254 public:
bool GetAttributeSet(
const std::string &_key)
const;
258 public:
void RemoveAttribute(
const std::string &_key);
261 public:
void RemoveAllAttributes();
271 public: std::any GetAny(
const std::string &_key =
"")
const;
279 public:
template<
typename T>
280 T Get(
const std::string &_key =
"")
const;
288 public:
template<
typename T>
289 std::pair<T, bool> Get(
const std::string &_key,
290 const T &_defaultValue)
const;
298 public:
template<
typename T>
299 bool Get(
const std::string &_key,
301 const T &_defaultValue)
const;
306 public:
template<
typename T>
307 bool Set(
const T &_value);
312 public:
bool HasElement(
const std::string &_name)
const;
330 public:
ElementPtr GetNextElement(
const std::string &_name =
"")
const;
334 public: std::set<std::string> GetElementTypeNames()
const;
343 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
352 public: std::map<std::string, std::size_t>
353 CountNamedElements(
const std::string &_type =
"")
const;
364 public:
ElementPtr GetElement(
const std::string &_name);
369 public:
ElementPtr AddElement(
const std::string &_name);
376 public:
void RemoveFromParent();
383 public:
void ClearElements();
387 public:
void Clear();
391 public:
void Update();
396 public:
void Reset();
400 public:
void SetInclude(
const std::string &_filename)
SDF_DEPRECATED(11.0);
421 public:
void SetFilePath(
const std::string &_path);
425 public:
const std::string &FilePath()
const;
429 public:
void SetLineNumber(
int _lineNumber);
434 public: std::optional<int> LineNumber()
const;
450 public:
void SetXmlPath(
const std::string &_path);
454 public:
const std::string &XmlPath()
const;
458 public:
void SetOriginalVersion(
const std::string &_version);
462 public:
const std::string &OriginalVersion()
const;
466 public: std::string GetDescription()
const;
470 public:
void SetDescription(
const std::string &_desc);
474 public:
void AddElementDescription(
ElementPtr _elem);
479 public:
ElementPtr GetElementImpl(
const std::string &_name)
const;
484 private:
void ToString(
const std::string &_prefix,
485 std::ostringstream &_out)
const;
490 private:
void PrintValuesImpl(
const std::string &_prefix,
491 std::ostringstream &_out)
const;
501 private:
ParamPtr CreateParam(
const std::string &_key,
502 const std::string &_type,
503 const std::string &_defaultValue,
505 const std::string &_description=
"");
509 private: std::unique_ptr<ElementPrivate> dataPtr;
589 T Element::Get(
const std::string &_key)
const
593 std::pair<T, bool> ret = this->Get<T>(_key, result);
600 bool Element::Get(
const std::string &_key,
602 const T &_defaultValue)
const
604 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
611 std::pair<T, bool> Element::Get(
const std::string &_key,
612 const T &_defaultValue)
const
614 std::pair<T, bool> result(_defaultValue,
true);
616 if (_key.empty() && this->dataPtr->value)
618 this->dataPtr->value->Get<T>(result.first);
620 else if (!_key.empty())
622 ParamPtr param = this->GetAttribute(_key);
625 param->Get(result.first);
627 else if (this->HasElement(_key))
629 result.first = this->GetElementImpl(_key)->Get<T>();
631 else if (this->HasElementDescription(_key))
633 result.first = this->GetElementDescription(_key)->Get<T>();
637 result.second =
false;
642 result.second =
false;
650 bool Element::Set(
const T &_value)
652 if (this->dataPtr->value)
654 this->dataPtr->value->Set(_value);