SST 15.0
Structural Simulation Toolkit
defaultInfo.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_DEFAULTINFO_H
13#define SST_CORE_ELI_DEFAULTINFO_H
14
15#include "sst/core/eli/elibase.h"
16
17#include <string>
18#include <vector>
19
20namespace SST::ELI {
21
22class ProvidesDefaultInfo
23{
24 friend class ModuleDocOldEli;
25
26public:
27 const std::string& getLibrary() const { return lib_; }
28 const std::string& getDescription() const { return desc_; }
29 const std::string& getName() const { return name_; }
30 const std::vector<int>& getVersion() const { return version_; }
31 const std::string& getCompileFile() const { return file_; }
32 const std::string& getCompileDate() const { return date_; }
33 const std::vector<int>& getELICompiledVersion() const;
34 const std::string& getAlias() const { return alias_; }
35
36 std::string getELIVersionString() const;
37
38 void toString(std::ostream& os) const;
39
40 template <class XMLNode>
41 void outputXML(XMLNode* node) const
42 {
43 if ( !getAlias().empty() ) node->SetAttribute("Alias", getAlias().c_str());
44 node->SetAttribute("Name", getName().c_str());
45 node->SetAttribute("Description", getDescription().c_str());
46 }
47
48 template <class T>
49 ProvidesDefaultInfo(const std::string& lib, const std::string& name, T* UNUSED(t)) :
50 lib_(lib),
51 name_(name),
52 desc_(T::ELI_getDescription()),
53 version_(T::ELI_getVersion()),
54 file_(T::ELI_getCompileFile()),
55 date_(T::ELI_getCompileDate()),
56 alias_(GetAlias<T>::get())
57 {}
58
59protected:
60 template <class T>
61 explicit ProvidesDefaultInfo(T* t) :
62 ProvidesDefaultInfo(T::ELI_getLibrary(), T::ELI_getName(), t)
63 {}
64
65private:
66 std::string lib_;
67 std::string name_;
68 std::string desc_;
69 std::vector<int> version_;
70 std::string file_;
71 std::string date_;
72 std::vector<int> compiled_;
73 std::string alias_;
74};
75
76} // namespace SST::ELI
77
78#define SST_ELI_INSERT_COMPILE_INFO() \
79 static const std::string& ELI_getCompileDate() \
80 { \
81 static std::string time = __TIME__; \
82 static std::string date = __DATE__; \
83 static std::string date_time = date + " " + time; \
84 return date_time; \
85 } \
86 static const std::string ELI_getCompileFile() \
87 { \
88 return __FILE__; \
89 }
90
91#define SST_ELI_DEFAULT_INFO(lib, name, version, desc) \
92 SST_ELI_INSERT_COMPILE_INFO() \
93 static constexpr unsigned majorVersion() \
94 { \
95 return SST::SST_ELI_getMajorNumberFromVersion(version); \
96 } \
97 static constexpr unsigned minorVersion() \
98 { \
99 return SST::SST_ELI_getMinorNumberFromVersion(version); \
100 } \
101 static constexpr unsigned tertiaryVersion() \
102 { \
103 return SST::SST_ELI_getTertiaryNumberFromVersion(version); \
104 } \
105 static const std::vector<int>& ELI_getVersion() \
106 { \
107 static std::vector<int> var = version; \
108 return var; \
109 } \
110 static const char* ELI_getLibrary() \
111 { \
112 return lib; \
113 } \
114 static const char* ELI_getName() \
115 { \
116 return name; \
117 } \
118 static const char* ELI_getDescription() \
119 { \
120 return desc; \
121 }
122
123#define SST_ELI_ELEMENT_VERSION(...) { __VA_ARGS__ }
124
125#define SST_ELI_REGISTER_ALIAS(alias) \
126 static std::string ELI_getAlias() \
127 { \
128 return alias; \
129 }
130
131#endif // SST_CORE_ELI_DEFAULTINFO_H