SST  11.1.0
StructuralSimulationToolkit
subcompSlotInfo.h
1 // Copyright 2009-2021 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-2021, 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_SUBCOMPSLOTINFO_H
13 #define SST_CORE_ELI_SUBCOMPSLOTINFO_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 InfoSubs
25 {
26  static const std::vector<SST::ElementInfoSubComponentSlot>& get()
27  {
28  static std::vector<SST::ElementInfoSubComponentSlot> var = {};
29  return var;
30  }
31 };
32 
33 template <class T>
34 struct InfoSubs<T, typename MethodDetect<decltype(T::ELI_getSubComponentSlots())>::type>
35 {
36  static const std::vector<SST::ElementInfoSubComponentSlot>& get() { return T::ELI_getSubComponentSlots(); }
37 };
38 
40 {
41 public:
42  const std::vector<ElementInfoSubComponentSlot>& getSubComponentSlots() const { return slots_; }
43 
44  void toString(std::ostream& os) const;
45 
46  template <class XMLNode>
47  void outputXML(XMLNode* node) const
48  {
49  int idx = 0;
50  for ( const ElementInfoSubComponentSlot& slot : slots_ ) {
51  auto* element = new XMLNode("SubComponentSlot");
52  element->SetAttribute("Index", idx);
53  element->SetAttribute("Name", slot.name);
54  element->SetAttribute("Description", slot.description ? slot.description : "none");
55  element->SetAttribute("Interface", slot.superclass ? slot.superclass : "none");
56  node->LinkEndChild(element);
57  ++idx;
58  }
59  }
60 
61 protected:
62  template <class T>
63  ProvidesSubComponentSlots(T* UNUSED(t)) : slots_(InfoSubs<T>::get())
64  {}
65 
66 private:
67  std::vector<ElementInfoSubComponentSlot> slots_;
68 };
69 
70 } // namespace ELI
71 } // namespace SST
72 
73 // clang-format off
74 #define SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(...) \
75  static const std::vector<SST::ElementInfoSubComponentSlot>& ELI_getSubComponentSlots() \
76  { \
77  static std::vector<SST::ElementInfoSubComponentSlot> var = { __VA_ARGS__ }; \
78  auto parent = SST::ELI::InfoSubs< \
79  std::conditional<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>::type>::get(); \
80  SST::ELI::combineEliInfo(var, parent); \
81  return var; \
82  }
83 // clang-format on
84 #define SST_ELI_DELETE_SUBCOMPONENT_SLOT(slot) \
85  { \
86  slot, nullptr, nullptr \
87  }
88 
89 #endif // SST_CORE_ELI_SUBCOMPSLOTINFO_H
Definition: elibase.h:66
Definition: elibase.h:114
Definition: subcompSlotInfo.h:39
Definition: subcompSlotInfo.h:24