SST  9.0.0
StructuralSimulationToolkit
statsInfo.h
1 #ifndef SST_CORE_STATS_INFO_H
2 #define SST_CORE_STATS_INFO_H
3 
4 #include <vector>
5 #include <string>
6 #include <sst/core/eli/elibase.h>
7 
8 namespace SST {
9 namespace ELI {
10 
11 template <class T, class Enable=void>
12 struct InfoStats {
13  static const std::vector<SST::ElementInfoStatistic>& get() {
14  static std::vector<SST::ElementInfoStatistic> var = { };
15  return var;
16  }
17 };
18 
19 template <class T>
20 struct InfoStats<T,
21  typename MethodDetect<decltype(T::ELI_getStatistics())>::type> {
22  static const std::vector<SST::ElementInfoStatistic>& get() {
23  return T::ELI_getStatistics();
24  }
25 };
26 
28  private:
29  std::vector<std::string> statnames;
30  std::vector<ElementInfoStatistic> stats_;
31 
32  void init(){
33  for (auto& item : stats_) {
34  statnames.push_back(item.name);
35  }
36  }
37 
38  protected:
39  template <class T> ProvidesStats(T* UNUSED(t)) :
40  stats_(InfoStats<T>::get())
41  {
42  init();
43  }
44 
45 
46  public:
47  const std::vector<ElementInfoStatistic>& getValidStats() const {
48  return stats_;
49  }
50  const std::vector<std::string>& getStatnames() const { return statnames; }
51 
52  void toString(std::ostream& os) const;
53 
54  template <class XMLNode> void outputXML(XMLNode* node) const {
55  // Build the Element to Represent the Component
56  int idx = 0;
57  for (const ElementInfoStatistic& stat : stats_){
58  // Build the Element to Represent the Parameter
59  auto* XMLStatElement = new XMLNode("Statistic");
60  XMLStatElement->SetAttribute("Index", idx);
61  XMLStatElement->SetAttribute("Name", stat.name);
62  XMLStatElement->SetAttribute("Description", stat.description ? stat.description : "none");
63  XMLStatElement->SetAttribute("Units", stat.units ? stat.units : "none");
64  XMLStatElement->SetAttribute("EnableLevel", stat.enableLevel);
65  node->LinkEndChild(XMLStatElement);
66  ++idx;
67  }
68  }
69 };
70 
71 }
72 }
73 
74 #define SST_ELI_DOCUMENT_STATISTICS(...) \
75  static const std::vector<SST::ElementInfoStatistic>& ELI_getStatistics() { \
76  static std::vector<SST::ElementInfoStatistic> var = { __VA_ARGS__ } ; \
77  return var; \
78  }
79 
80 #endif
81 
Definition: statsInfo.h:27
Definition: elibase.h:105
Describes Statistics used by a Component.
Definition: elibase.h:37
Definition: statsInfo.h:12