SST  15.1.0
StructuralSimulationToolkit
statsInfo.h
1 // Copyright 2009-2025 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-2025, 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_STATS_INFO_H
13 #define SST_CORE_ELI_STATS_INFO_H
14 
15 #include "sst/core/eli/elibase.h"
16 
17 #include <string>
18 #include <type_traits>
19 #include <vector>
20 
21 namespace SST::ELI {
22 
23 template <typename, typename = void>
24 struct InfoStats
25 {
26  static const std::vector<SST::ElementInfoStatistic>& get()
27  {
28  static std::vector<SST::ElementInfoStatistic> var = {};
29  return var;
30  }
31 };
32 
33 template <typename T>
34 struct InfoStats<T, std::void_t<decltype(T::ELI_getStatistics())>>
35 {
36  static const std::vector<SST::ElementInfoStatistic>& get() { return T::ELI_getStatistics(); }
37 };
38 
40 {
41 private:
42  std::vector<ElementInfoStatistic> stats_;
43 
44 protected:
45  template <class T>
46  explicit ProvidesStats(T* UNUSED(t)) :
47  stats_(InfoStats<T>::get())
48  {}
49 
50 public:
51  const std::vector<ElementInfoStatistic>& getValidStats() const { return stats_; }
52 
53  void toString(std::ostream& os) const;
54 
55  template <class XMLNode>
56  void outputXML(XMLNode* node) const
57  {
58  // Build the Element to Represent the Component
59  int idx = 0;
60  for ( const auto& stat : stats_ ) {
61  // Build the Element to Represent the Parameter
62  auto* XMLStatElement = new XMLNode("Statistic");
63  XMLStatElement->SetAttribute("Index", idx);
64  XMLStatElement->SetAttribute("Name", stat.name);
65  XMLStatElement->SetAttribute("Description", stat.description ? stat.description : "none");
66  XMLStatElement->SetAttribute("Units", stat.units ? stat.units : "none");
67  XMLStatElement->SetAttribute("EnableLevel", stat.enable_level);
68  node->LinkEndChild(XMLStatElement);
69  ++idx;
70  }
71  }
72 };
73 
74 } // namespace SST::ELI
75 
76 // clang-format off
77 #define SST_ELI_DOCUMENT_STATISTICS(...) \
78  static const std::vector<SST::ElementInfoStatistic>& ELI_getStatistics() \
79  { \
80  static std::vector<SST::ElementInfoStatistic> var = { __VA_ARGS__ }; \
81  auto parent = SST::ELI::InfoStats< \
82  std::conditional_t<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>>::get(); \
83  SST::ELI::combineEliInfo(var, parent); \
84  return var; \
85  }
86 // clang-format on
87 
88 #define SST_ELI_DELETE_STAT(stat) { stat, nullptr, nullptr, 0 }
89 
90 #endif
Definition: statsInfo.h:39
Definition: attributeInfo.h:22
Definition: statsInfo.h:24