SST  11.0.0
StructuralSimulationToolkit
elibase.h
1 // Copyright 2009-2021 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-2021, 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_ELIBASE_H
13 #define SST_CORE_ELIBASE_H
14 
15 #include "sst/core/sst_types.h"
16 
17 #include <functional>
18 #include <string>
19 #include <vector>
20 #include <set>
21 #include <list>
22 #include <map>
23 #include <functional>
24 #include <memory>
25 
26 // Component Category Definitions
27 #define COMPONENT_CATEGORY_UNCATEGORIZED 0x00
28 #define COMPONENT_CATEGORY_PROCESSOR 0x01
29 #define COMPONENT_CATEGORY_MEMORY 0x02
30 #define COMPONENT_CATEGORY_NETWORK 0x04
31 #define COMPONENT_CATEGORY_SYSTEM 0x08
32 
33 namespace SST {
34 
35 /** Describes Statistics used by a Component.
36  */
38  const char* name; /*!< Name of the Statistic to be Enabled */
39  const char* description; /*!< Brief description of the Statistic */
40  const char* units; /*!< Units associated with this Statistic value */
41  const uint8_t enableLevel; /*!< Level to meet to enable statistic 0 = disabled */
42 };
43 
44 /** Describes Parameters to a Component.
45  */
47  const char *name; /*!< Name of the parameter */
48  const char *description; /*!< Brief description of the parameter (ie, what it controls) */
49  const char *defaultValue; /*!< Default value (if any) nullptr == required parameter with no default, "" == optional parameter, blank default, "foo" == default value */
50 };
51 
52 /** Describes Ports that the Component can use
53  */
55  const char *name; /*!< Name of the port. Can contain %d for a dynamic port, also %(xxx)d for dynamic port with xxx being the controlling component parameter */
56  const char *description; /*!< Brief description of the port (ie, what it is used for) */
57  const char **validEvents; /*!< List of fully-qualified event types that this Port expects to send or receive */
58 };
59 
60 /** Describes Ports that the Component can use
61  */
63  const char *name; /*!< Name of the port. Can contain %d for a dynamic port, also %(xxx)d for dynamic port with xxx being the controlling component parameter */
64  const char *description; /*!< Brief description of the port (ie, what it is used for) */
65  const std::vector<std::string> validEvents; /*!< List of fully-qualified event types that this Port expects to send or receive */
66 
67  // For backwards compatibility, convert from ElementInfoPort to ElementInfoPort2
68 private:
69  std::vector<std::string> createVector(const char** events) {
70  std::vector<std::string> vec;
71  if ( events == nullptr ) return vec;
72  const char** ev = events;
73  while ( nullptr != *ev ) {
74  vec.push_back(*ev);
75  ev++;
76  }
77  return vec;
78  }
79 
80 public:
81 
82  ElementInfoPort2(const ElementInfoPort* port) :
83  name(port->name),
84  description(port->description),
85  validEvents(createVector(port->validEvents))
86  {}
87 
88  ElementInfoPort2(const char* name, const char* description, const std::vector<std::string> validEvents) :
89  name(name),
90  description(description),
91  validEvents(validEvents)
92  {}
93 };
94 
96  const char * name;
97  const char * description;
98  const char * superclass;
99 };
100 
102 
103 namespace ELI {
104 
105 template <class T> struct MethodDetect { using type=void; };
106 
108  virtual void load() = 0;
109  virtual ~LibraryLoader(){}
110 };
111 
113 public:
114  using InfoMap=std::map<std::string,std::list<LibraryLoader*>>;
115  using LibraryMap=std::map<std::string,InfoMap>;
116 
117  static bool isLoaded(const std::string& name);
118 
119  /**
120  @return A boolean indicated successfully added
121  */
122  static bool addLoader(const std::string& lib, const std::string& name,
123  LibraryLoader* loader);
124 
125  static const LibraryMap& getLoaders();
126 
127 private:
128  static std::unique_ptr<LibraryMap> loaders_;
129 
130 };
131 
132 } //namespace ELI
133 } //namespace SST
134 
135 #define ELI_FORWARD_AS_ONE(...) __VA_ARGS__
136 
137 #define SST_ELI_DECLARE_BASE(Base) \
138  using __LocalEliBase = Base; \
139  static const char* ELI_baseName(){ return #Base; }
140 
141 #define SST_ELI_DECLARE_INFO_COMMON() \
142  using InfoLibrary = ::SST::ELI::InfoLibrary<__LocalEliBase>; \
143  template <class __TT> static bool addDerivedInfo(const std::string& lib, const std::string& elem){ \
144  return addInfo(lib,elem,new BuilderInfo(lib,elem,(__TT*)nullptr)); \
145  }
146 
147 #define SST_ELI_DECLARE_NEW_BASE(OldBase,NewBase) \
148  using __LocalEliBase = NewBase; \
149  using __ParentEliBase = OldBase; \
150  SST_ELI_DECLARE_INFO_COMMON() \
151  static const char* ELI_baseName(){ return #NewBase; } \
152  template <class InfoImpl> static bool addInfo(const std::string& elemlib, const std::string& elem, \
153  InfoImpl* info){ \
154  return OldBase::addInfo(elemlib, elem, info) \
155  && ::SST::ELI::InfoDatabase::getLibrary<NewBase>(elemlib)->addInfo(elem,info); \
156  }
157 
158 
159 #endif // SST_CORE_ELIBASE_H
Definition: elibase.h:112
Definition: elibase.h:95
const char * defaultValue
Definition: elibase.h:49
const char * description
Definition: elibase.h:48
const char * description
Definition: elibase.h:64
const char ** validEvents
Definition: elibase.h:57
Describes Ports that the Component can use.
Definition: elibase.h:62
Definition: elibase.h:105
Describes Statistics used by a Component.
Definition: elibase.h:37
Definition: elibase.h:107
const char * description
Definition: elibase.h:56
const char * name
Definition: elibase.h:47
const char * name
Definition: elibase.h:38
Describes Parameters to a Component.
Definition: elibase.h:46
const char * description
Definition: elibase.h:39
const char * name
Definition: elibase.h:55
const uint8_t enableLevel
Definition: elibase.h:41
const char * name
Definition: elibase.h:63
Describes Ports that the Component can use.
Definition: elibase.h:54
const std::vector< std::string > validEvents
Definition: elibase.h:65
static bool addLoader(const std::string &lib, const std::string &name, LibraryLoader *loader)
Definition: elibase.cc:29
const char * units
Definition: elibase.h:40