SST 16.0.0
Structural Simulation Toolkit
portsInfo.h
1// Copyright 2009-2026 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-2026, 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 <ostream>
18#include <string>
19#include <type_traits>
20#include <vector>
21
22namespace SST::ELI {
23
24template <typename, typename = void>
26{
27 static const std::vector<SST::ElementInfoPort>& get()
28 {
29 static std::vector<SST::ElementInfoPort> var = {};
30 return var;
31 }
32};
33
34template <typename T>
35struct InfoPorts<T, std::void_t<decltype(T::ELI_getPorts())>>
36{
37 static const std::vector<SST::ElementInfoPort>& get() { return T::ELI_getPorts(); }
38};
39
40class ProvidesPorts
41{
42public:
43 const std::vector<std::string>& getPortnames() { return portnames; }
44 const std::vector<ElementInfoPort>& getValidPorts() const { return ports_; }
45
46 void toString(std::ostream& os) const;
47
48 template <class XMLNode>
49 void outputXML(XMLNode* node) const
50 {
51 // Build the Element to Represent the Component
52 int idx = 0;
53 for ( auto& port : ports_ ) {
54 auto* XMLPortElement = new XMLNode("Port");
55 XMLPortElement->SetAttribute("Index", idx);
56 XMLPortElement->SetAttribute("Name", port.name);
57 XMLPortElement->SetAttribute("Description", port.description ? port.description : "none");
58 node->LinkEndChild(XMLPortElement);
59 ++idx;
60 }
61 }
62
63protected:
64 template <class T>
65 explicit ProvidesPorts(T* UNUSED(t)) :
66 ports_(InfoPorts<T>::get())
67 {
68 init();
69 }
70
71private:
72 void init();
73
74 std::vector<std::string> portnames;
75 std::vector<ElementInfoPort> ports_;
76};
77
78} // namespace SST::ELI
79
80// clang-format off
81#define SST_ELI_DOCUMENT_PORTS(...) \
82 static const std::vector<SST::ElementInfoPort>& ELI_getPorts() \
83 { \
84 static std::vector<SST::ElementInfoPort> var = { __VA_ARGS__ }; \
85 auto parent = SST::ELI::InfoPorts< \
86 std::conditional_t<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>>::get(); \
87 SST::ELI::combineEliInfo(var, parent); \
88 return var; \
89 }
90// clang-format on
91
92#define SST_ELI_DELETE_PORT(port) \
93 { \
94 port, nullptr, {} \
95 }
96
97#endif // SST_CORE_ELI_PORTS_INFO_H
Definition portsInfo.h:26