SST  6.1.0
StructuralSimulationToolkit
componentInfo.h
1 // Copyright 2009-2016 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2016, 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 
17 #include <unordered_set>
18 #include <string>
19 #include <functional>
20 
21 /* #include <sst/core/clock.h> */
22 /* #include <sst/core/oneshot.h> */
23 /* #include <sst/core/event.h> */
24 /* //#include <sst/core/params.h> */
25 /* //#include <sst/core/link.h> */
26 /* //#include <sst/core/timeConverter.h> */
27 /* #include "sst/core/simulation.h" */
28 /* #include "sst/core/unitAlgebra.h" */
29 /* #include "sst/core/statapi/statbase.h" */
30 
31 namespace SST {
32 
33 class LinkMap;
34 class Component;
35 
36 struct ComponentInfo {
37 
38  friend class Simulation;
39 
40 private:
41  const ComponentId_t id;
42  const std::string name;
43  const std::string type;
44  LinkMap* link_map;
45  Component* component;
46 
47  inline void setComponent(Component* comp) { component = comp; }
48 
49 
50 public:
51  ComponentInfo(ComponentId_t id, std::string name, std::string type, LinkMap* link_map) :
52  id(id),
53  name(name),
54  type(type),
55  link_map(link_map),
56  component(NULL)
57  {}
58 
59  ~ComponentInfo();
60 
61  // ComponentInfo() :
62  // id(0),
63  // name(""),
64  // type(""),
65  // link_map(NULL)
66  // {}
67 
68  inline ComponentId_t getID() const { return id; }
69 
70  inline const std::string& getName() const { return name; }
71 
72  inline const std::string& getType() const { return type; }
73 
74  inline Component* getComponent() const { return component; }
75 
76  inline LinkMap* getLinkMap() const { return link_map; }
77 
78 
79  struct HashName {
80  size_t operator() (const ComponentInfo* info) const {
81  std::hash<std::string> hash;
82  return hash(info->name);
83  }
84  };
85 
86  struct EqualsName {
87  bool operator() (const ComponentInfo* lhs, const ComponentInfo* rhs) const {
88  return lhs->name == rhs->name;
89  }
90  };
91 
92  struct HashID {
93  size_t operator() (const ComponentInfo* info) const {
94  std::hash<ComponentId_t> hash;
95  return hash(info->id);
96  }
97  };
98 
99  struct EqualsID {
100  bool operator() (const ComponentInfo* lhs, const ComponentInfo* rhs) const {
101  return lhs->id == rhs->id;
102  }
103  };
104 
105 };
106 
107 
109 private:
110  std::unordered_set<ComponentInfo*, ComponentInfo::HashName, ComponentInfo::EqualsName> dataByName;
111  std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID> dataByID;
112 
113 public:
114  typedef std::unordered_set<ComponentInfo*, ComponentInfo::HashName, ComponentInfo::EqualsName>::const_iterator const_iterator;
115 
116  const_iterator begin() const {
117  return dataByName.begin();
118  }
119 
120  const_iterator end() const {
121  return dataByName.end();
122  }
123 
124  ComponentInfoMap() {}
125 
126  void insert(ComponentInfo* info) {
127  dataByName.insert(info);
128  dataByID.insert(info);
129  }
130 
131  ComponentInfo* getByName(const std::string& key) const {
132  ComponentInfo infoKey(0, key, "", NULL);
133  auto value = dataByName.find(&infoKey);
134  if ( value == dataByName.end() ) return NULL;
135  return *value;
136  }
137 
138  ComponentInfo* getByID(const ComponentId_t key) const {
139  ComponentInfo infoKey(key, "", "", NULL);
140  auto value = dataByID.find(&infoKey);
141  if ( value == dataByID.end() ) return NULL;
142  return *value;
143  }
144 
145  bool empty() {
146  return dataByName.empty();
147  }
148 
149  void clear() {
150  for ( auto i : dataByName ) {
151  delete i;
152  }
153  dataByName.clear();
154  dataByID.clear();
155  }
156 };
157 
158 } //namespace SST
159 
160 #endif // SST_CORE_COMPONENTINFO_H
Main control class for a SST Simulation.
Definition: simulation.h:75
Maps port names to the Links that are connected to it.
Definition: linkMap.h:28
Main component object for the simulation.
Definition: component.h:56
Definition: action.cc:17
Definition: componentInfo.h:99
Definition: componentInfo.h:108
Definition: componentInfo.h:79
Definition: componentInfo.h:92
Definition: componentInfo.h:86
Definition: componentInfo.h:36