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;
108 public:
void SetRequired(
const std::string &_req);
113 public:
const std::string &GetRequired()
const;
118 public:
void SetCopyChildren(
bool _value);
123 public:
bool GetCopyChildren()
const;
127 public:
void SetReferenceSDF(
const std::string &_value);
131 public: std::string ReferenceSDF()
const;
135 public:
void PrintDescription(
const std::string &_prefix)
const;
139 public:
void PrintValues(std::string _prefix)
const;
147 public:
void PrintDocLeftPane(std::string &_html,
148 int _spacing,
int &_index)
const;
155 public:
void PrintDocRightPane(std::string &_html,
156 int _spacing,
int &_index)
const;
161 public: std::string ToString(
const std::string &_prefix)
const;
170 public:
void AddAttribute(
const std::string &_key,
171 const std::string &_type,
172 const std::string &_defaultvalue,
174 const std::string &_description=
"");
182 public:
void AddValue(
const std::string &_type,
183 const std::string &_defaultValue,
bool _required,
184 const std::string &_description=
"");
195 public:
void AddValue(
const std::string &_type,
196 const std::string &_defaultValue,
bool _required,
197 const std::string &_minValue,
198 const std::string &_maxValue,
199 const std::string &_description =
"");
204 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
208 public:
size_t GetAttributeCount()
const;
213 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
217 public:
size_t GetElementDescriptionCount()
const;
222 public:
ElementPtr GetElementDescription(
unsigned int _index)
const;
227 public:
ElementPtr GetElementDescription(
const std::string &_key)
const;
232 public:
bool HasElementDescription(
const std::string &_name)
const;
237 public:
bool HasAttribute(
const std::string &_key)
const;
242 public:
bool GetAttributeSet(
const std::string &_key)
const;
246 public:
void RemoveAttribute(
const std::string &_key);
249 public:
void RemoveAllAttributes();
259 public: std::any GetAny(
const std::string &_key =
"")
const;
267 public:
template<
typename T>
268 T Get(
const std::string &_key =
"")
const;
276 public:
template<
typename T>
277 std::pair<T, bool> Get(
const std::string &_key,
278 const T &_defaultValue)
const;
286 public:
template<
typename T>
287 bool Get(
const std::string &_key,
289 const T &_defaultValue)
const;
294 public:
template<
typename T>
295 bool Set(
const T &_value);
300 public:
bool HasElement(
const std::string &_name)
const;
318 public:
ElementPtr GetNextElement(
const std::string &_name =
"")
const;
322 public: std::set<std::string> GetElementTypeNames()
const;
331 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
340 public: std::map<std::string, std::size_t>
341 CountNamedElements(
const std::string &_type =
"")
const;
352 public:
ElementPtr GetElement(
const std::string &_name);
357 public:
ElementPtr AddElement(
const std::string &_name);
364 public:
void RemoveFromParent();
371 public:
void ClearElements();
375 public:
void Clear();
379 public:
void Update();
384 public:
void Reset();
388 public:
void SetInclude(
const std::string &_filename);
392 public: std::string GetInclude()
const;
396 public:
void SetFilePath(
const std::string &_path);
400 public:
const std::string &FilePath()
const;
404 public:
void SetOriginalVersion(
const std::string &_version);
408 public:
const std::string &OriginalVersion()
const;
412 public: std::string GetDescription()
const;
416 public:
void SetDescription(
const std::string &_desc);
420 public:
void AddElementDescription(
ElementPtr _elem);
425 public:
ElementPtr GetElementImpl(
const std::string &_name)
const;
430 private:
void ToString(
const std::string &_prefix,
431 std::ostringstream &_out)
const;
436 private:
void PrintValuesImpl(
const std::string &_prefix,
437 std::ostringstream &_out)
const;
447 private:
ParamPtr CreateParam(
const std::string &_key,
448 const std::string &_type,
449 const std::string &_defaultValue,
451 const std::string &_description=
"");
455 private: std::unique_ptr<ElementPrivate> dataPtr;
504 T Element::Get(
const std::string &_key)
const
508 std::pair<T, bool> ret = this->Get<T>(_key, result);
515 bool Element::Get(
const std::string &_key,
517 const T &_defaultValue)
const
519 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
526 std::pair<T, bool> Element::Get(
const std::string &_key,
527 const T &_defaultValue)
const
529 std::pair<T, bool> result(_defaultValue,
true);
531 if (_key.empty() && this->dataPtr->value)
533 this->dataPtr->value->Get<T>(result.first);
535 else if (!_key.empty())
537 ParamPtr param = this->GetAttribute(_key);
540 param->Get(result.first);
542 else if (this->HasElement(_key))
544 result.first = this->GetElementImpl(_key)->Get<T>();
546 else if (this->HasElementDescription(_key))
548 result.first = this->GetElementDescription(_key)->Get<T>();
552 result.second =
false;
557 result.second =
false;
565 bool Element::Set(
const T &_value)
567 if (this->dataPtr->value)
569 this->dataPtr->value->Set(_value);