SST  9.0.0
StructuralSimulationToolkit
elibase.h
1 // Copyright 2009-2019 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-2019, 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) NULL == 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 == NULL ) return vec;
72  const char** ev = events;
73  while ( NULL != *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 public:
109  using InfoMap=std::map<std::string, std::function<void()>>;
110  using LibraryMap=std::map<std::string,InfoMap>;
111 
112  static bool isLoaded(const std::string& name);
113 
114  /**
115  @return A boolean indicated successfully added
116  */
117  static bool addLoader(const std::string& lib, const std::string& name,
118  std::function<void()>&& loader);
119 
120  static const LibraryMap& getLoaders();
121 
122 private:
123  static std::unique_ptr<LibraryMap> loaders_;
124 
125 };
126 
127 } //namespace ELI
128 } //namespace SST
129 
130 #define ELI_FORWARD_AS_ONE(...) __VA_ARGS__
131 
132 #define SST_ELI_DECLARE_BASE(Base) \
133  using __LocalEliBase = Base; \
134  static const char* ELI_baseName(){ return #Base; }
135 
136 #define SST_ELI_DECLARE_INFO_COMMON() \
137  using InfoLibrary = ::SST::ELI::InfoLibrary<__LocalEliBase>; \
138  template <class __TT> static bool addDerivedInfo(const std::string& lib, const std::string& elem){ \
139  return addInfo(lib,elem,new BuilderInfo(lib,elem,(__TT*)nullptr)); \
140  }
141 
142 #define SST_ELI_DECLARE_NEW_BASE(OldBase,NewBase) \
143  using __LocalEliBase = NewBase; \
144  using __ParentEliBase = OldBase; \
145  SST_ELI_DECLARE_INFO_COMMON() \
146  static const char* ELI_baseName(){ return #NewBase; } \
147  template <class InfoImpl> static bool addInfo(const std::string& elemlib, const std::string& elem, \
148  InfoImpl* info){ \
149  return OldBase::addInfo(elemlib, elem, info) \
150  && ::SST::ELI::InfoDatabase::getLibrary<NewBase>(elemlib)->addInfo(elem,info); \
151  }
152 
153 
154 #endif // SST_CORE_ELIBASE_H
static bool addLoader(const std::string &lib, const std::string &name, std::function< void()> &&loader)
Definition: elibase.cc:32
Definition: elibase.h:107
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
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
const char * units
Definition: elibase.h:40