17 #ifndef SDF_ELEMENT_HH_ 18 #define SDF_ELEMENT_HH_ 27 #include "sdf/sdf_config.h" 35 #pragma warning(disable: 4251) 43 inline namespace SDF_VERSION_NAMESPACE {
67 public std::enable_shared_from_this<Element>
77 public: ElementPtr Clone()
const;
81 public:
void Copy(
const ElementPtr _elem);
86 public: ElementPtr GetParent()
const;
90 public:
void SetParent(
const ElementPtr _parent);
94 public:
void SetName(
const std::string &_name);
98 public:
const std::string &GetName()
const;
106 public:
void SetRequired(
const std::string &_req);
111 public:
const std::string &GetRequired()
const;
116 public:
void SetCopyChildren(
bool _value);
121 public:
bool GetCopyChildren()
const;
125 public:
void SetReferenceSDF(
const std::string &_value);
129 public: std::string ReferenceSDF()
const;
133 public:
void PrintDescription(
const std::string &_prefix)
const;
137 public:
void PrintValues(std::string _prefix)
const;
145 public:
void PrintDocLeftPane(std::string &_html,
146 int _spacing,
int &_index)
const;
153 public:
void PrintDocRightPane(std::string &_html,
154 int _spacing,
int &_index)
const;
159 public: std::string ToString(
const std::string &_prefix)
const;
168 public:
void AddAttribute(
const std::string &_key,
169 const std::string &_type,
170 const std::string &_defaultvalue,
172 const std::string &_description=
"");
180 public:
void AddValue(
const std::string &_type,
181 const std::string &_defaultValue,
bool _required,
182 const std::string &_description=
"");
187 public:
ParamPtr GetAttribute(
const std::string &_key)
const;
191 public:
size_t GetAttributeCount()
const;
196 public:
ParamPtr GetAttribute(
unsigned int _index)
const;
200 public:
size_t GetElementDescriptionCount()
const;
205 public: ElementPtr GetElementDescription(
unsigned int _index)
const;
210 public: ElementPtr GetElementDescription(
const std::string &_key)
const;
215 public:
bool HasElementDescription(
const std::string &_name)
const;
220 public:
bool HasAttribute(
const std::string &_key)
const;
225 public:
bool GetAttributeSet(
const std::string &_key)
const;
235 public: std::any GetAny(
const std::string &_key =
"")
const;
243 public:
template<
typename T>
244 T Get(
const std::string &_key =
"")
const;
252 public:
template<
typename T>
253 std::pair<T, bool> Get(
const std::string &_key,
254 const T &_defaultValue)
const;
262 public:
template<
typename T>
263 bool Get(
const std::string &_key,
265 const T &_defaultValue)
const;
270 public:
template<
typename T>
271 bool Set(
const T &_value);
276 public:
bool HasElement(
const std::string &_name)
const;
281 public: ElementPtr GetFirstElement()
const;
294 public: ElementPtr GetNextElement(
const std::string &_name =
"")
const;
305 public: ElementPtr GetElement(
const std::string &_name);
310 public: ElementPtr AddElement(
const std::string &_name);
314 public:
void InsertElement(ElementPtr _elem);
317 public:
void RemoveFromParent();
321 public:
void RemoveChild(ElementPtr _child);
324 public:
void ClearElements();
328 public:
void Update();
333 public:
void Reset();
337 public:
void SetInclude(
const std::string &_filename);
341 public: std::string GetInclude()
const;
345 public: std::string GetDescription()
const;
349 public:
void SetDescription(
const std::string &_desc);
353 public:
void AddElementDescription(ElementPtr _elem);
358 public: ElementPtr GetElementImpl(
const std::string &_name)
const;
363 private:
void ToString(
const std::string &_prefix,
364 std::ostringstream &_out)
const;
369 private:
void PrintValuesImpl(
const std::string &_prefix,
370 std::ostringstream &_out)
const;
380 private:
ParamPtr CreateParam(
const std::string &_key,
381 const std::string &_type,
382 const std::string &_defaultValue,
384 const std::string &_description=
"");
388 private: std::unique_ptr<ElementPrivate> dataPtr;
431 T Element::Get(
const std::string &_key)
const 435 std::pair<T, bool> ret = this->Get<T>(_key, result);
442 bool Element::Get(
const std::string &_key,
444 const T &_defaultValue)
const 446 std::pair<T, bool> ret = this->Get<T>(_key, _defaultValue);
453 std::pair<T, bool> Element::Get(
const std::string &_key,
454 const T &_defaultValue)
const 456 std::pair<T, bool> result(_defaultValue,
true);
458 if (_key.empty() && this->dataPtr->value)
460 this->dataPtr->value->Get<T>(result.first);
462 else if (!_key.empty())
464 ParamPtr param = this->GetAttribute(_key);
467 param->Get(result.first);
469 else if (this->HasElement(_key))
471 result.first = this->GetElementImpl(_key)->Get<T>();
473 else if (this->HasElementDescription(_key))
475 result.first = this->GetElementDescription(_key)->Get<T>();
479 result.second =
false;
484 result.second =
false;
492 bool Element::Set(
const T &_value)
494 if (this->dataPtr->value)
496 this->dataPtr->value->Set(_value);
std::string includeFilename
name of the include file that was used to create this element
Definition: Element.hh:423
std::string required
True if element is required.
Definition: Element.hh:399
std::string referenceSDF
Name of reference sdf.
Definition: Element.hh:426
class SDFORMAT_VISIBLE Element
Definition: Element.hh:47
std::vector< ElementPtr > ElementPtr_V
Definition: Element.hh:59
SDF Element class.
Definition: Element.hh:66
Param_V attributes
Definition: Element.hh:411
ElementPtr_V elements
Definition: Element.hh:417
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:51
std::string name
Element name.
Definition: Element.hh:396
std::string description
Element description.
Definition: Element.hh:402
ElementPtr_V elementDescriptions
Definition: Element.hh:420
ParamPtr value
Definition: Element.hh:414
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:48
ElementWeakPtr parent
Element's parent.
Definition: Element.hh:408
bool copyChildren
True if element's children should be copied.
Definition: Element.hh:405
std::vector< ParamPtr > Param_V
Definition: Param.hh:61
std::weak_ptr< Element > ElementWeakPtr
Definition: Element.hh:55
Definition: Element.hh:393
namespace for Simulation Description Format parser
Definition: AirPressure.hh:25
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:57