SST 15.0
Structural Simulation Toolkit
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 <vector>
20
21namespace SST::ELI {
22
23template <typename, typename = void>
25{
26 static const std::vector<SST::ElementInfoAttribute>& get()
27 {
28 static std::vector<SST::ElementInfoAttribute> var = {};
29 return var;
30 }
31};
32
33template <typename T>
34struct GetAttributes<T, std::void_t<decltype(T::ELI_getAttributes())>>
35{
36 static const std::vector<SST::ElementInfoAttribute>& get() { return T::ELI_getAttributes(); }
37};
38
39class ProvidesAttributes
40{
41public:
42 const std::vector<ElementInfoAttribute>& getAttributes() const { return attributes_; }
43
44 void toString(std::ostream& os) const;
45
46 template <class XMLNode>
47 void outputXML(XMLNode* node) const
48 {
49 // Build the Element to Represent the Component
50 int idx = 0;
51 for ( const ElementInfoAttribute& attribute : attributes_ ) {
52 ;
53 // Build the Element to Represent the Attribute
54 auto* XMLAttributeElement = new XMLNode("Attribute");
55 XMLAttributeElement->SetAttribute("Index", idx);
56 XMLAttributeElement->SetAttribute("Name", attribute.name);
57 XMLAttributeElement->SetAttribute("Value", attribute.value ? attribute.value : "none");
58 node->LinkEndChild(XMLAttributeElement);
59 ++idx;
60 }
61 }
62
63protected:
64 template <class T>
65 explicit ProvidesAttributes(T* UNUSED(t)) :
66 attributes_(GetAttributes<T>::get())
67 {}
68
69private:
70 std::vector<ElementInfoAttribute> attributes_;
71};
72
73} // namespace SST::ELI
74
75// clang-format off
76#define SST_ELI_DOCUMENT_ATTRIBUTES(...) \
77 static const std::vector<SST::ElementInfoAttribute>& ELI_getAttributes() \
78 { \
79 static std::vector<SST::ElementInfoAttribute> var = { __VA_ARGS__ }; \
80 auto parent = SST::ELI::GetAttributes< \
81 std::conditional_t<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>>::get(); \
82 SST::ELI::combineEliInfo(var, parent); \
83 return var; \
84 }
85// clang-format on
86
87#define SST_ELI_DELETE_ATTRIBUTE(attribute) { attribute, nullptr }
88
89#endif // SST_CORE_ELI_ATTRIBUTE_INFO_H
Definition attributeInfo.h:25
Definition elibase.h:81