SST 15.0
Structural Simulation Toolkit
portsInfo.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_PORTS_INFO_H
13#define SST_CORE_ELI_PORTS_INFO_H
14
15#include "sst/core/eli/elibase.h"
16
17#include <string>
18#include <vector>
19
20namespace SST::ELI {
21
22template <typename, typename = void>
24{
25 static const std::vector<SST::ElementInfoPort>& get()
26 {
27 static std::vector<SST::ElementInfoPort> var = {};
28 return var;
29 }
30};
31
32template <typename T>
33struct InfoPorts<T, std::void_t<decltype(T::ELI_getPorts())>>
34{
35 static const std::vector<SST::ElementInfoPort>& get() { return T::ELI_getPorts(); }
36};
37
38class ProvidesPorts
39{
40public:
41 const std::vector<std::string>& getPortnames() { return portnames; }
42 const std::vector<ElementInfoPort>& getValidPorts() const { return ports_; }
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 ( auto& port : ports_ ) {
52 auto* XMLPortElement = new XMLNode("Port");
53 XMLPortElement->SetAttribute("Index", idx);
54 XMLPortElement->SetAttribute("Name", port.name);
55 XMLPortElement->SetAttribute("Description", port.description ? port.description : "none");
56 node->LinkEndChild(XMLPortElement);
57 ++idx;
58 }
59 }
60
61protected:
62 template <class T>
63 explicit ProvidesPorts(T* UNUSED(t)) :
64 ports_(InfoPorts<T>::get())
65 {
66 init();
67 }
68
69private:
70 void init();
71
72 std::vector<std::string> portnames;
73 std::vector<ElementInfoPort> ports_;
74};
75
76} // namespace SST::ELI
77
78// clang-format off
79#define SST_ELI_DOCUMENT_PORTS(...) \
80 static const std::vector<SST::ElementInfoPort>& ELI_getPorts() \
81 { \
82 static std::vector<SST::ElementInfoPort> var = { __VA_ARGS__ }; \
83 auto parent = SST::ELI::InfoPorts< \
84 std::conditional_t<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>>::get(); \
85 SST::ELI::combineEliInfo(var, parent); \
86 return var; \
87 }
88// clang-format on
89
90#define SST_ELI_DELETE_PORT(port) \
91 { \
92 port, nullptr, {} \
93 }
94
95#endif // SST_CORE_ELI_PORTS_INFO_H
Definition portsInfo.h:24