SST  13.0.0
StructuralSimulationToolkit
attributeInfo.h
1 // Copyright 2009-2023 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-2023, 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 <vector>
20 
21 namespace SST {
22 namespace ELI {
23 
24 template <class T, class Enable = 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 <class T>
35 struct GetAttributes<T, typename MethodDetect<decltype(T::ELI_getAttributes())>::type>
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  ProvidesAttributes(T* UNUSED(t)) : attributes_(GetAttributes<T>::get())
67  {}
68 
69 private:
70  std::vector<ElementInfoAttribute> attributes_;
71 };
72 
73 } // namespace ELI
74 } // namespace SST
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<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>::type>::get(); \
83  SST::ELI::combineEliInfo(var, parent); \
84  return var; \
85  }
86 // clang-format on
87 
88 #define SST_ELI_DELETE_ATTRIBUTE(attribute) \
89  { \
90  attribute, nullptr \
91  }
92 
93 #endif // SST_CORE_ELI_ATTRIBUTE_INFO_H
Definition: elibase.h:80
Definition: action.cc:18
Definition: attributeInfo.h:25
Definition: elibase.h:129
Definition: attributeInfo.h:40