SST  15.1.0
StructuralSimulationToolkit
attributeInfo.h
1 // Copyright 2009-2025 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2025, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_ELI_ATTRIBUTE_INFO_H
13 #define SST_CORE_ELI_ATTRIBUTE_INFO_H
14 
15 #include "sst/core/eli/elibase.h"
16 #include "sst/core/warnmacros.h"
17 
18 #include <string>
19 #include <type_traits>
20 #include <vector>
21 
22 namespace SST::ELI {
23 
24 template <typename, typename = void>
26 {
27  static const std::vector<SST::ElementInfoAttribute>& get()
28  {
29  static std::vector<SST::ElementInfoAttribute> var = {};
30  return var;
31  }
32 };
33 
34 template <typename T>
35 struct GetAttributes<T, std::void_t<decltype(T::ELI_getAttributes())>>
36 {
37  static const std::vector<SST::ElementInfoAttribute>& get() { return T::ELI_getAttributes(); }
38 };
39 
41 {
42 public:
43  const std::vector<ElementInfoAttribute>& getAttributes() const { return attributes_; }
44 
45  void toString(std::ostream& os) const;
46 
47  template <class XMLNode>
48  void outputXML(XMLNode* node) const
49  {
50  // Build the Element to Represent the Component
51  int idx = 0;
52  for ( const ElementInfoAttribute& attribute : attributes_ ) {
53  ;
54  // Build the Element to Represent the Attribute
55  auto* XMLAttributeElement = new XMLNode("Attribute");
56  XMLAttributeElement->SetAttribute("Index", idx);
57  XMLAttributeElement->SetAttribute("Name", attribute.name);
58  XMLAttributeElement->SetAttribute("Value", attribute.value ? attribute.value : "none");
59  node->LinkEndChild(XMLAttributeElement);
60  ++idx;
61  }
62  }
63 
64 protected:
65  template <class T>
66  explicit ProvidesAttributes(T* UNUSED(t)) :
67  attributes_(GetAttributes<T>::get())
68  {}
69 
70 private:
71  std::vector<ElementInfoAttribute> attributes_;
72 };
73 
74 } // namespace SST::ELI
75 
76 // clang-format off
77 #define SST_ELI_DOCUMENT_ATTRIBUTES(...) \
78  static const std::vector<SST::ElementInfoAttribute>& ELI_getAttributes() \
79  { \
80  static std::vector<SST::ElementInfoAttribute> var = { __VA_ARGS__ }; \
81  auto parent = SST::ELI::GetAttributes< \
82  std::conditional_t<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>>::get(); \
83  SST::ELI::combineEliInfo(var, parent); \
84  return var; \
85  }
86 // clang-format on
87 
88 #define SST_ELI_DELETE_ATTRIBUTE(attribute) { attribute, nullptr }
89 
90 #endif // SST_CORE_ELI_ATTRIBUTE_INFO_H
Definition: elibase.h:81
Definition: attributeInfo.h:25
Definition: attributeInfo.h:22
Definition: attributeInfo.h:40