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