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