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