SST  7.1.0
StructuralSimulationToolkit
componentInfo.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-NA0003525 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2017, Sandia Corporation
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_COMPONENTINFO_H
13 #define SST_CORE_COMPONENTINFO_H
14 
15 #include <sst/core/sst_types.h>
16 #include <sst/core/params.h>
17 
18 #include <unordered_set>
19 #include <string>
20 #include <functional>
21 
22 namespace SST {
23 
24 class LinkMap;
25 class BaseComponent;
26 
27 class ConfigComponent;
28 class ComponentInfoMap;
29 
30 namespace Statistics {
31 class StatisticInfo;
32 }
33 
35 
36 public:
37  typedef std::vector<Statistics::StatisticInfo> statEnableList_t; /*!< List of Enabled Statistics */
38 
39 private:
40  friend class Simulation;
41  friend class BaseComponent;
42  friend class ComponentInfoMap;
43  const ComponentId_t id;
44  const std::string name;
45  const std::string slot_name;
46  int slot_num;
47  const std::string type;
48  LinkMap* link_map;
49  BaseComponent* component;
50  // std::map<std::string, ComponentInfo> subComponents;
51  std::vector<ComponentInfo> subComponents;
52  const Params *params;
53 
54  statEnableList_t * enabledStats;
55  std::vector<double> coordinates;
56 
57  inline void setComponent(BaseComponent* comp) { component = comp; }
58 
59  /* Lookup Key style constructor */
60  ComponentInfo(ComponentId_t id, const std::string &name);
61  void finalizeLinkConfiguration();
62 
63 public:
64  /* Old ELI Style subcomponent constructor */
65  ComponentInfo(const std::string &type, const Params *params, const ComponentInfo *parent);
66 
67  /* New ELI Style */
68  ComponentInfo(ConfigComponent *ccomp, const std::string& name, LinkMap* link_map);
70  ~ComponentInfo();
71 
72  inline ComponentId_t getID() const { return id; }
73 
74  inline const std::string& getName() const { return name; }
75 
76  inline const std::string& getSlotName() const { return slot_name; }
77 
78  inline int getSlotNum() const { return slot_num; }
79 
80  inline const std::string& getType() const { return type; }
81 
82  inline BaseComponent* getComponent() const { return component; }
83 
84  inline LinkMap* getLinkMap() const { return link_map; }
85 
86  inline const Params* getParams() const { return params; }
87 
88  // inline std::map<std::string, ComponentInfo>& getSubComponents() { return subComponents; }
89  inline std::vector<ComponentInfo>& getSubComponents() { return subComponents; }
90 
91  ComponentInfo* findSubComponent(std::string slot, int slot_num);
92  ComponentInfo* findSubComponent(ComponentId_t id);
93  std::vector<LinkId_t> getAllLinkIds() const;
94 
95  statEnableList_t* getStatEnableList() { return enabledStats; }
96 
97  struct HashName {
98  size_t operator() (const ComponentInfo* info) const {
99  std::hash<std::string> hash;
100  return hash(info->name);
101  }
102  };
103 
104  struct EqualsName {
105  bool operator() (const ComponentInfo* lhs, const ComponentInfo* rhs) const {
106  return lhs->name == rhs->name;
107  }
108  };
109 
110  struct HashID {
111  size_t operator() (const ComponentInfo* info) const {
112  std::hash<ComponentId_t> hash;
113  return hash(info->id);
114  }
115  };
116 
117  struct EqualsID {
118  bool operator() (const ComponentInfo* lhs, const ComponentInfo* rhs) const {
119  return lhs->id == rhs->id;
120  }
121  };
122 };
123 
124 
126 private:
127  std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID> dataByID;
128 
129 public:
130  typedef std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID>::const_iterator const_iterator;
131 
132  const_iterator begin() const {
133  return dataByID.begin();
134  }
135 
136  const_iterator end() const {
137  return dataByID.end();
138  }
139 
140  ComponentInfoMap() {}
141 
142  void insert(ComponentInfo* info) {
143  dataByID.insert(info);
144  }
145 
146  ComponentInfo* getByID(const ComponentId_t key) const {
147  ComponentInfo infoKey(COMPONENT_ID_MASK(key), "");
148  auto value = dataByID.find(&infoKey);
149  if ( value == dataByID.end() ) return NULL;
150  if ( SUBCOMPONENT_ID_MASK(key) != 0 ) {
151  // Looking for a subcomponent
152  return (*value)->findSubComponent(key);
153  }
154  return *value;
155  }
156 
157  bool empty() {
158  return dataByID.empty();
159  }
160 
161  void clear() {
162  for ( auto i : dataByID ) {
163  delete i;
164  }
165  dataByID.clear();
166  }
167 };
168 
169 } //namespace SST
170 
171 #endif // SST_CORE_COMPONENTINFO_H
Main control class for a SST Simulation.
Definition: simulation.h:72
std::vector< Statistics::StatisticInfo > statEnableList_t
Definition: componentInfo.h:37
Maps port names to the Links that are connected to it.
Definition: linkMap.h:28
Represents the configuration of a generic component.
Definition: configGraph.h:238
Definition: action.cc:17
Definition: componentInfo.h:117
Definition: componentInfo.h:125
Definition: componentInfo.h:97
Main component object for the simulation.
Definition: baseComponent.h:104
Definition: componentInfo.h:110
Definition: componentInfo.h:104
Parameter store.
Definition: params.h:45
Definition: componentInfo.h:34