17 #ifndef SDF_ELEMENT_HH_
18 #define SDF_ELEMENT_HH_
39 #pragma warning(disable: 4251)
47 inline namespace SDF_VERSION_NAMESPACE {
75 public std::enable_shared_from_this<Element>
108 public:
void SetParent(
const ElementPtr _parent);
112 public:
void SetName(
const std::string &_name);
116 public:
const std::string &GetName()
const;
125 public:
void SetRequired(
const std::string &_req);
130 public:
const std::string &GetRequired()
const;
137 public:
void SetExplicitlySetInFile(
const bool _value);
141 public:
bool GetExplicitlySetInFile()
const;
146 public:
void SetCopyChildren(
bool _value);
151 public:
bool GetCopyChildren()
const;
155 public:
void SetReferenceSDF(
const std::string &_value);
159 public: std::string ReferenceSDF()
const;
163 public:
void PrintDescription(
const std::string &_prefix)
const;
168 public:
void PrintDescription(
sdf::Errors &_errors,
169 const std::string &_prefix)
const;
174 public:
void PrintValues(std::string _prefix,
190 public:
void PrintValues(
const std::string &_prefix,
191 bool _includeDefaultElements,
192 bool _includeDefaultAttributes,
202 const std::string &_prefix,
203 bool _includeDefaultElements,
204 bool _includeDefaultAttributes,
213 public:
void PrintDocLeftPane(std::string &_html,
214 int _spacing,
int &_index)
const;
221 public:
void PrintDocRightPane(std::string &_html,
222 int _spacing,
int &_index)
const;
228 public: std::string ToString(
229 const std::string &_prefix,
237 public: std::string ToString(
239 const std::string &_prefix,
251 public: std::string ToString(
252 const std::string &_prefix,
253 bool _includeDefaultElements,
254 bool _includeDefaultAttributes,
267 public: std::string ToString(
269 const std::string &_prefix,
270 bool _includeDefaultElements,
271 bool _includeDefaultAttributes,
281 public:
void AddAttribute(
const std::string &_key,
282 const std::string &_type,
283 const std::string &_defaultvalue,
285 const std::string &_description =
"");
295 public:
void AddAttribute(
const std::string &_key,
296 const std::string &_type,
297 const std::string &_defaultvalue,
300 const std::string &_description =
"");
308 public:
void AddValue(
const std::string &_type,
309 const std::string &_defaultValue,
bool _required,
310 const std::string &_description =
"");
319 public:
void AddValue(
const std::string &_type,
320 const std::string &_defaultValue,
bool _required,
322 const std::string &_description =
"");
333 public:
void AddValue(
const std::string &_type,
334 const std::string &_defaultValue,
bool _required,
335 const std::string &_minValue,
336 const std::string &_maxValue,
337 const std::string &_description =
"");
349 public:
void AddValue(
const std::string &_type,
350 const std::string &_defaultValue,
bool _required,
351 const std::string &_minValue,
352 const std::string &_maxValue,
354 const std::string &_description =
"");
359 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
363 public:
size_t GetAttributeCount()
const;
367 public:
const Param_V &GetAttributes()
const;
372 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
376 public:
size_t GetElementDescriptionCount()
const;
381 public:
ElementPtr GetElementDescription(
unsigned int _index)
const;
386 public:
ElementPtr GetElementDescription(
const std::string &_key)
const;
391 public:
bool HasElementDescription(
const std::string &_name)
const;
396 public:
bool HasAttribute(
const std::string &_key)
const;
401 public:
bool GetAttributeSet(
const std::string &_key)
const;
405 public:
void RemoveAttribute(
const std::string &_key);
408 public:
void RemoveAllAttributes();
418 public: std::any GetAny(
const std::string &_key =
"")
const;
426 const std::string &_key =
"")
const;
435 public:
template<
typename T>
437 const std::string &_key =
"")
const;
445 public:
template<
typename T>
446 T Get(
const std::string &_key =
"")
const;
455 public:
template<
typename T>
457 const std::string &_key,
458 const T &_defaultValue)
const;
465 public:
template<
typename T>
466 std::pair<T, bool> Get(
const std::string &_key,
467 const T &_defaultValue)
const;
475 public:
template<
typename T>
476 bool Get(
const std::string &_key,
478 const T &_defaultValue)
const;
487 public:
template<
typename T>
489 const std::string &_key,
491 const T &_defaultValue)
const;
496 public:
template<
typename T>
497 bool Set(
const T &_value);
503 public:
template<
typename T>
509 public:
bool HasElement(
const std::string &_name)
const;
527 public:
ElementPtr GetNextElement(
const std::string &_name =
"")
const;
531 public: std::set<std::string> GetElementTypeNames()
const;
540 public:
bool HasUniqueChildNames(
const std::string &_type =
"")
const;
550 public:
bool HasUniqueChildNames(
sdf::Errors &_errors,
551 const std::string &_type =
"")
const;
563 public:
bool HasUniqueChildNames(
564 const std::string &_type,
565 const std::vector<std::string> &_ignoreElements)
const;
578 public:
bool HasUniqueChildNames(
580 const std::string &_type,
581 const std::vector<std::string> &_ignoreElements)
const;
590 public: std::map<std::string, std::size_t>
591 CountNamedElements(
const std::string &_type =
"")
const;
601 public: std::map<std::string, std::size_t>
603 const std::string &_type =
"")
const;
615 public: std::map<std::string, std::size_t> CountNamedElements(
616 const std::string &_type,
617 const std::vector<std::string> &_ignoreElements)
const;
630 public: std::map<std::string, std::size_t> CountNamedElements(
632 const std::string &_type,
633 const std::vector<std::string> &_ignoreElements)
const;
645 public:
ElementPtr GetElement(
const std::string &_name);
658 public:
ElementPtr GetElement(
const std::string &_name,
670 public:
ElementPtr FindElement(
const std::string &_name);
686 public:
ElementPtr AddElement(
const std::string &_name);
692 public:
ElementPtr AddElement(
const std::string &_name,
704 public:
void InsertElement(
ElementPtr _elem,
bool _setParentToSelf);
707 public:
void RemoveFromParent();
719 public:
void ClearElements();
723 public:
void Clear();
727 public:
void Update();
737 public:
void Reset();
754 public:
void SetFilePath(
const std::string &_path);
758 public:
const std::string &FilePath()
const;
762 public:
void SetLineNumber(
int _lineNumber);
767 public: std::optional<int> LineNumber()
const;
783 public:
void SetXmlPath(
const std::string &_path);
787 public:
const std::string &XmlPath()
const;
791 public:
void SetOriginalVersion(
const std::string &_version);
795 public:
const std::string &OriginalVersion()
const;
799 public: std::string GetDescription()
const;
803 public:
void SetDescription(
const std::string &_desc);
807 public:
void AddElementDescription(
ElementPtr _elem);
812 public:
ElementPtr GetElementImpl(
const std::string &_name)
const;
817 public:
static std::vector<std::string> NameUniquenessExceptions();
827 std::ostringstream &_out,
828 const std::string &_prefix,
829 bool _includeDefaultElements,
830 bool _includeDefaultAttributes,
840 private:
void PrintValuesImpl(
sdf::Errors &_errors,
841 const std::string &_prefix,
842 bool _includeDefaultElements,
843 bool _includeDefaultAttributes,
845 std::ostringstream &_out)
const;
856 private:
ParamPtr CreateParam(
const std::string &_key,
857 const std::string &_type,
858 const std::string &_defaultValue,
861 const std::string &_description =
"");
864 private: std::unique_ptr<ElementPrivate> dataPtr;
944 std::ostringstream &_out)
const;
952 bool _includeDefaultAttributes,
954 std::ostringstream &_out)
const;
963 std::pair<T, bool> ret = this->Get<T>(_errors, _key, result);
974 std::pair<T, bool> ret = this->Get<T>(_key, result);
982 const std::string &_key,
984 const T &_defaultValue)
const
986 std::pair<T, bool> ret = this->Get<T>(_errors, _key, _defaultValue);
995 const T &_defaultValue)
const
997 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
1003 template<
typename T>
1005 const T &_defaultValue)
const
1008 std::pair<T, bool> result = this->Get<T>(errors, _key, _defaultValue);
1009 for(
auto& error : errors)
1017 template<
typename T>
1019 const std::string &_key,
1020 const T &_defaultValue)
const
1022 std::pair<T, bool> result(_defaultValue,
true);
1024 if (_key.empty() && this->dataPtr->value)
1026 this->dataPtr->value->Get<T>(result.first, _errors);
1028 else if (!_key.empty())
1033 param->Get(result.first, _errors);
1045 result.second =
false;
1050 result.second =
false;
1057 template<
typename T>
1061 bool result = this->Set<T>(errors, _value);
1062 for(
auto& error : errors)
1070 template<
typename T>
1073 if (this->dataPtr->value)
1075 return this->dataPtr->value->Set(_value, _errors);
1084 #pragma warning(pop)