SST  11.0.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_SUBCOMPSLOTINFO_H
13 #define SST_CORE_SUBCOMPSLOTINFO_H
14 
15 #include <string>
16 #include <vector>
17 
18 #include "sst/core/eli/elibase.h"
19 
20 namespace SST {
21 namespace ELI {
22 
23 template <class T, class Enable=void>
24 struct InfoSubs {
25  static const std::vector<SST::ElementInfoSubComponentSlot>& get() {
26  static std::vector<SST::ElementInfoSubComponentSlot> var = { };
27  return var;
28  }
29 };
30 
31 template <class T>
32 struct InfoSubs<T,
33  typename MethodDetect<decltype(T::ELI_getSubComponentSlots())>::type> {
34  static const std::vector<SST::ElementInfoSubComponentSlot>& get() {
35  return T::ELI_getSubComponentSlots();
36  }
37 };
38 
40  public:
41  const std::vector<ElementInfoSubComponentSlot>& getSubComponentSlots() const {
42  return slots_;
43  }
44 
45  void toString(std::ostream& os) const;
46 
47  template <class XMLNode> void outputXML(XMLNode* node) const {
48  int idx = 0;
49  for (const ElementInfoSubComponentSlot& slot : slots_){
50  auto* element = new XMLNode("SubComponentSlot");
51  element->SetAttribute("Index", idx);
52  element->SetAttribute("Name", slot.name);
53  element->SetAttribute("Description", slot.description ? slot.description : "none");
54  element->SetAttribute("Interface", slot.superclass ? slot.superclass : "none");
55  node->LinkEndChild(element);
56  ++idx;
57  }
58  }
59 
60  protected:
61  template <class T> ProvidesSubComponentSlots(T* UNUSED(t)) :
62  slots_(InfoSubs<T>::get())
63  {
64  }
65 
66  private:
67  std::vector<ElementInfoSubComponentSlot> slots_;
68 };
69 
70 }
71 }
72 
73 #define SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(...) \
74  static const std::vector<SST::ElementInfoSubComponentSlot>& ELI_getSubComponentSlots() { \
75  static std::vector<SST::ElementInfoSubComponentSlot> var = { __VA_ARGS__ } ; \
76  return var; \
77  }
78 
79 #endif
80 
Definition: elibase.h:95
Definition: elibase.h:105
Definition: subcompSlotInfo.h:39
Definition: subcompSlotInfo.h:24