SST  7.2.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 
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  void prepareForComplete();
63 
64 public:
65  /* Old ELI Style subcomponent constructor */
66  ComponentInfo(const std::string &type, const Params *params, const ComponentInfo *parent);
67 
68  /* New ELI Style */
69  ComponentInfo(ConfigComponent *ccomp, const std::string& name, LinkMap* link_map);
71  ~ComponentInfo();
72 
73  inline ComponentId_t getID() const { return id; }
74 
75  inline const std::string& getName() const { return name; }
76 
77  inline const std::string& getSlotName() const { return slot_name; }
78 
79  inline int getSlotNum() const { return slot_num; }
80 
81  inline const std::string& getType() const { return type; }
82 
83  inline BaseComponent* getComponent() const { return component; }
84 
85  inline LinkMap* getLinkMap() const { return link_map; }
86 
87  inline const Params* getParams() const { return params; }
88 
89  // inline std::map<std::string, ComponentInfo>& getSubComponents() { return subComponents; }
90  inline std::vector<ComponentInfo>& getSubComponents() { return subComponents; }
91 
92  ComponentInfo* findSubComponent(std::string slot, int slot_num);
93  ComponentInfo* findSubComponent(ComponentId_t id);
94  std::vector<LinkId_t> getAllLinkIds() const;
95 
96  statEnableList_t* getStatEnableList() { return enabledStats; }
97 
98  struct HashName {
99  size_t operator() (const ComponentInfo* info) const {
100  std::hash<std::string> hash;
101  return hash(info->name);
102  }
103  };
104 
105  struct EqualsName {
106  bool operator() (const ComponentInfo* lhs, const ComponentInfo* rhs) const {
107  return lhs->name == rhs->name;
108  }
109  };
110 
111  struct HashID {
112  size_t operator() (const ComponentInfo* info) const {
113  std::hash<ComponentId_t> hash;
114  return hash(info->id);
115  }
116  };
117 
118  struct EqualsID {
119  bool operator() (const ComponentInfo* lhs, const ComponentInfo* rhs) const {
120  return lhs->id == rhs->id;
121  }
122  };
123 };
124 
125 
127 private:
128  std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID> dataByID;
129 
130 public:
131  typedef std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID>::const_iterator const_iterator;
132 
133  const_iterator begin() const {
134  return dataByID.begin();
135  }
136 
137  const_iterator end() const {
138  return dataByID.end();
139  }
140 
141  ComponentInfoMap() {}
142 
143  void insert(ComponentInfo* info) {
144  dataByID.insert(info);
145  }
146 
147  ComponentInfo* getByID(const ComponentId_t key) const {
148  ComponentInfo infoKey(COMPONENT_ID_MASK(key), "");
149  auto value = dataByID.find(&infoKey);
150  if ( value == dataByID.end() ) return NULL;
151  if ( SUBCOMPONENT_ID_MASK(key) != 0 ) {
152  // Looking for a subcomponent
153  return (*value)->findSubComponent(key);
154  }
155  return *value;
156  }
157 
158  bool empty() {
159  return dataByID.empty();
160  }
161 
162  void clear() {
163  for ( auto i : dataByID ) {
164  delete i;
165  }
166  dataByID.clear();
167  }
168 };
169 
170 } //namespace SST
171 
172 #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:195
Definition: action.cc:17
Definition: componentInfo.h:118
Definition: componentInfo.h:126
Definition: componentInfo.h:98
Main component object for the simulation.
Definition: baseComponent.h:104
Definition: componentInfo.h:111
Definition: componentInfo.h:105
Parameter store.
Definition: params.h:45
Definition: componentInfo.h:34