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;
119 public:
void SetCopyChildren(
bool _value);
124 public:
bool GetCopyChildren()
const;
128 public:
void SetReferenceSDF(
const std::string &_value);
132 public: std::string ReferenceSDF()
const;
136 public:
void PrintDescription(
const std::string &_prefix)
const;
140 public:
void PrintValues(std::string _prefix)
const;
148 public:
void PrintDocLeftPane(std::string &_html,
149 int _spacing,
int &_index)
const;
156 public:
void PrintDocRightPane(std::string &_html,
157 int _spacing,
int &_index)
const;
162 public: std::string ToString(
const std::string &_prefix)
const;
171 public:
void AddAttribute(
const std::string &_key,
172 const std::string &_type,
173 const std::string &_defaultvalue,
175 const std::string &_description=
"");
183 public:
void AddValue(
const std::string &_type,
184 const std::string &_defaultValue,
bool _required,
185 const std::string &_description=
"");
196 public:
void AddValue(
const std::string &_type,
197 const std::string &_defaultValue,
bool _required,
198 const std::string &_minValue,
199 const std::string &_maxValue,
200 const std::string &_description =
"");
205 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
209 public:
size_t GetAttributeCount()
const;
214 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
218 public:
size_t GetElementDescriptionCount()
const;
223 public:
ElementPtr GetElementDescription(
unsigned int _index)
const;
228 public:
ElementPtr GetElementDescription(
const std::string &_key)
const;
233 public:
bool HasElementDescription(
const std::string &_name)
const;
238 public:
bool HasAttribute(
const std::string &_key)
const;
243 public:
bool GetAttributeSet(
const std::string &_key)
const;
247 public:
void RemoveAttribute(
const std::string &_key);
250 public:
void RemoveAllAttributes();
260 public: std::any GetAny(
const std::string &_key =
"")
const;
268 public:
template<
typename T>
269 T Get(
const std::string &_key =
"")
const;
277 public:
template<
typename T>
278 std::pair<T, bool> Get(
const std::string &_key,
279 const T &_defaultValue)
const;
287 public:
template<
typename T>
288 bool Get(
const std::string &_key,
290 const T &_defaultValue)
const;
295 public:
template<
typename T>
296 bool Set(
const T &_value);
301 public:
bool HasElement(
const std::string &_name)
const;
319 public:
ElementPtr GetNextElement(
const std::string &_name =
"")
const;
323 public: std::set<std::string> GetElementTypeNames()
const;
332 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
341 public: std::map<std::string, std::size_t>
342 CountNamedElements(
const std::string &_type =
"")
const;
353 public:
ElementPtr GetElement(
const std::string &_name);
358 public:
ElementPtr AddElement(
const std::string &_name);
365 public:
void RemoveFromParent();
372 public:
void ClearElements();
376 public:
void Clear();
380 public:
void Update();
385 public:
void Reset();
389 public:
void SetInclude(
const std::string &_filename)
SDF_DEPRECATED(11.0);
410 public:
void SetFilePath(
const std::string &_path);
414 public:
const std::string &FilePath()
const;
418 public:
void SetOriginalVersion(
const std::string &_version);
422 public:
const std::string &OriginalVersion()
const;
426 public: std::string GetDescription()
const;
430 public:
void SetDescription(
const std::string &_desc);
434 public:
void AddElementDescription(
ElementPtr _elem);
439 public:
ElementPtr GetElementImpl(
const std::string &_name)
const;
444 private:
void ToString(
const std::string &_prefix,
445 std::ostringstream &_out)
const;
450 private:
void PrintValuesImpl(
const std::string &_prefix,
451 std::ostringstream &_out)
const;
461 private:
ParamPtr CreateParam(
const std::string &_key,
462 const std::string &_type,
463 const std::string &_defaultValue,
465 const std::string &_description=
"");
469 private: std::unique_ptr<ElementPrivate> dataPtr;
540 T Element::Get(
const std::string &_key)
const
544 std::pair<T, bool> ret = this->Get<T>(_key, result);
551 bool Element::Get(
const std::string &_key,
553 const T &_defaultValue)
const
555 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
562 std::pair<T, bool> Element::Get(
const std::string &_key,
563 const T &_defaultValue)
const
565 std::pair<T, bool> result(_defaultValue,
true);
567 if (_key.empty() && this->dataPtr->value)
569 this->dataPtr->value->Get<T>(result.first);
571 else if (!_key.empty())
573 ParamPtr param = this->GetAttribute(_key);
576 param->Get(result.first);
578 else if (this->HasElement(_key))
580 result.first = this->GetElementImpl(_key)->Get<T>();
582 else if (this->HasElementDescription(_key))
584 result.first = this->GetElementDescription(_key)->Get<T>();
588 result.second =
false;
593 result.second =
false;
601 bool Element::Set(
const T &_value)
603 if (this->dataPtr->value)
605 this->dataPtr->value->Set(_value);