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;
360 public: std::map<std::string, std::size_t>
361 CountNamedElements(
const std::string &_type =
"")
const;
373 public:
ElementPtr GetElement(
const std::string &_name);
384 public:
ElementPtr FindElement(
const std::string &_name);
400 public:
ElementPtr AddElement(
const std::string &_name);
407 public:
void RemoveFromParent();
414 public:
void ClearElements();
418 public:
void Clear();
422 public:
void Update();
427 public:
void Reset();
431 public:
void SetInclude(
const std::string &_filename);
435 public: std::string GetInclude()
const;
439 public:
void SetFilePath(
const std::string &_path);
443 public:
const std::string &FilePath()
const;
447 public:
void SetOriginalVersion(
const std::string &_version);
451 public:
const std::string &OriginalVersion()
const;
455 public: std::string GetDescription()
const;
459 public:
void SetDescription(
const std::string &_desc);
463 public:
void AddElementDescription(
ElementPtr _elem);
468 public:
ElementPtr GetElementImpl(
const std::string &_name)
const;
475 private:
void ToString(
const std::string &_prefix,
476 bool _includeDefaultElements,
477 bool _includeDefaultAttributes,
478 std::ostringstream &_out)
const;
485 private:
void PrintValuesImpl(
const std::string &_prefix,
486 bool _includeDefaultElements,
487 bool _includeDefaultAttributes,
488 std::ostringstream &_out)
const;
498 private:
ParamPtr CreateParam(
const std::string &_key,
499 const std::string &_type,
500 const std::string &_defaultValue,
502 const std::string &_description =
"");
506 private: std::unique_ptr<ElementPrivate> dataPtr;
558 T Element::Get(
const std::string &_key)
const
562 std::pair<T, bool> ret = this->Get<T>(_key, result);
569 bool Element::Get(
const std::string &_key,
571 const T &_defaultValue)
const
573 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
580 std::pair<T, bool> Element::Get(
const std::string &_key,
581 const T &_defaultValue)
const
583 std::pair<T, bool> result(_defaultValue,
true);
585 if (_key.empty() && this->dataPtr->value)
587 this->dataPtr->value->Get<T>(result.first);
589 else if (!_key.empty())
591 ParamPtr param = this->GetAttribute(_key);
594 param->Get(result.first);
596 else if (this->HasElement(_key))
598 result.first = this->GetElementImpl(_key)->Get<T>();
600 else if (this->HasElementDescription(_key))
602 result.first = this->GetElementDescription(_key)->Get<T>();
606 result.second =
false;
611 result.second =
false;
619 bool Element::Set(
const T &_value)
621 if (this->dataPtr->value)
623 this->dataPtr->value->Set(_value);