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;
252 public: std::any GetAny(
const std::string &_key =
"")
const;
260 public:
template<
typename T>
261 T Get(
const std::string &_key =
"")
const;
269 public:
template<
typename T>
270 std::pair<T, bool> Get(
const std::string &_key,
271 const T &_defaultValue)
const;
279 public:
template<
typename T>
280 bool Get(
const std::string &_key,
282 const T &_defaultValue)
const;
287 public:
template<
typename T>
288 bool Set(
const T &_value);
293 public:
bool HasElement(
const std::string &_name)
const;
311 public:
ElementPtr GetNextElement(
const std::string &_name =
"")
const;
315 public: std::set<std::string> GetElementTypeNames()
const;
324 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
333 public: std::map<std::string, std::size_t>
334 CountNamedElements(
const std::string &_type =
"")
const;
345 public:
ElementPtr GetElement(
const std::string &_name);
350 public:
ElementPtr AddElement(
const std::string &_name);
357 public:
void RemoveFromParent();
364 public:
void ClearElements();
368 public:
void Clear();
372 public:
void Update();
377 public:
void Reset();
381 public:
void SetInclude(
const std::string &_filename);
385 public: std::string GetInclude()
const;
389 public:
void SetFilePath(
const std::string &_path);
393 public:
const std::string &FilePath()
const;
397 public:
void SetOriginalVersion(
const std::string &_version);
401 public:
const std::string &OriginalVersion()
const;
405 public: std::string GetDescription()
const;
409 public:
void SetDescription(
const std::string &_desc);
413 public:
void AddElementDescription(
ElementPtr _elem);
418 public:
ElementPtr GetElementImpl(
const std::string &_name)
const;
423 private:
void ToString(
const std::string &_prefix,
424 std::ostringstream &_out)
const;
429 private:
void PrintValuesImpl(
const std::string &_prefix,
430 std::ostringstream &_out)
const;
440 private:
ParamPtr CreateParam(
const std::string &_key,
441 const std::string &_type,
442 const std::string &_defaultValue,
444 const std::string &_description=
"");
448 private: std::unique_ptr<ElementPrivate> dataPtr;
497 T Element::Get(
const std::string &_key)
const
501 std::pair<T, bool> ret = this->Get<T>(_key, result);
508 bool Element::Get(
const std::string &_key,
510 const T &_defaultValue)
const
512 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
519 std::pair<T, bool> Element::Get(
const std::string &_key,
520 const T &_defaultValue)
const
522 std::pair<T, bool> result(_defaultValue,
true);
524 if (_key.empty() && this->dataPtr->value)
526 this->dataPtr->value->Get<T>(result.first);
528 else if (!_key.empty())
530 ParamPtr param = this->GetAttribute(_key);
533 param->Get(result.first);
535 else if (this->HasElement(_key))
537 result.first = this->GetElementImpl(_key)->Get<T>();
539 else if (this->HasElementDescription(_key))
541 result.first = this->GetElementDescription(_key)->Get<T>();
545 result.second =
false;
550 result.second =
false;
558 bool Element::Set(
const T &_value)
560 if (this->dataPtr->value)
562 this->dataPtr->value->Set(_value);