SST  15.1.0
StructuralSimulationToolkit
simpleInfo.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_SIMPLE_INFO_H
13 #define SST_CORE_ELI_SIMPLE_INFO_H
14 
15 #include "sst/core/eli/elibase.h"
16 
17 #include <type_traits>
18 
19 namespace SST::ELI {
20 
21 // ProvidesSimpleInfo is a class to quickly add ELI info to an ELI
22 // Base API. This class should only be used for APIs that aren't
23 // reported in sst-info, since you can't override the plain text and
24 // XML printing functions.
25 
26 
27 // Class used to differentiate the different versions of ELI_getSimpleInfo
28 template <int num, typename InfoType>
30 {};
31 
32 // Class to check for an ELI_getSimpleInfo Function. The std::void_t<
33 // decltype()> way to detect a member function's type doesn't seem to
34 // work for functions with specific type signatures and we need to
35 // differentiate between the various versions using the first
36 // parameter to the function (index + type).
37 template <class T, int index, class InfoType>
39 {
40  template <typename F, F>
41  struct check;
42 
43  using Match = char;
44  using NotMatch = long;
45 
46  using functionsig = const InfoType& (*)(SimpleInfoPlaceHolder<index, InfoType>);
47 
48  template <typename F>
49  static Match HasFunction(check<functionsig, &F::ELI_getSimpleInfo>*);
50 
51  template <typename F>
52  static NotMatch HasFunction(...);
53 
54 public:
55  static bool const value = (sizeof(HasFunction<T>(0)) == sizeof(Match));
56 };
57 
58 template <class T, int index, class InfoType>
59 inline constexpr bool checkForELI_getSimpleInfoFunction_v =
61 
62 // Actual functions that use checkForELI_getSimpleInfoFunction class
63 // to create functions to get the information from the class
64 template <class T, int index, class InfoType>
65 std::enable_if_t<checkForELI_getSimpleInfoFunction_v<T, index, InfoType>, const InfoType&>
66 ELI_templatedGetSimpleInfo()
67 {
68  return T::ELI_getSimpleInfo(SimpleInfoPlaceHolder<index, InfoType>());
69 }
70 
71 template <class T, int index, class InfoType>
72 std::enable_if_t<!checkForELI_getSimpleInfoFunction_v<T, index, InfoType>, const InfoType&>
73 ELI_templatedGetSimpleInfo()
74 {
75  static InfoType var;
76  return var;
77 }
78 
79 // Class that lets you add ELI information to an ELI API. This class
80 // can be used with any type/class that can be initialized using list
81 // initialization (x = {}). You have to provide an index as well as
82 // the type to be store so that the templating system can
83 // differentiate between different items of the same type. It would
84 // be cool if we could template on a string instead so they could be
85 // named, but that doesn't seem to work in c++ 11.
86 template <int num, typename InfoType>
88 {
89 public:
90  const InfoType& getSimpleInfo() const { return info_; }
91 
92 protected:
93  template <class T>
94  explicit ProvidesSimpleInfo(T* UNUSED(t)) :
95  info_(ELI_templatedGetSimpleInfo<T, num, InfoType>())
96  {}
97 
98 private:
99  InfoType info_;
100 };
101 
102 } // namespace SST::ELI
103 
104 // Macro used by the API to create macros to populate the added ELI
105 // info
106 #define SST_ELI_DOCUMENT_SIMPLE_INFO(type, index, ...) \
107  static const type& ELI_getSimpleInfo(SST::ELI::SimpleInfoPlaceHolder<index, type> UNUSED(a)) \
108  { \
109  static type my_info = { __VA_ARGS__ }; \
110  return my_info; \
111  }
112 
113 #endif // SST_CORE_ELI_SIMPLE_INFO_H
Definition: simpleInfo.h:87
Definition: attributeInfo.h:22
Definition: simpleInfo.h:29