SST  11.0.0
StructuralSimulationToolkit
linkMap.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_LINKMAP_H
13 #define SST_CORE_LINKMAP_H
14 
15 #include "sst/core/sst_types.h"
16 
17 #include <string>
18 #include <map>
19 
20 #include "sst/core/component.h"
21 #include "sst/core/link.h"
22 
23 namespace SST {
24 
25 /**
26  * Maps port names to the Links that are connected to it
27  */
28 class LinkMap {
29 
30 private:
31  std::map<std::string,Link*> linkMap;
32  // const std::vector<std::string> * allowedPorts;
33  std::vector<std::string> selfPorts;
34 
35  // bool checkPort(const char *def, const char *offered) const
36  // {
37  // const char * x = def;
38  // const char * y = offered;
39 
40  // /* Special case. Name of '*' matches everything */
41  // if ( *x == '*' && *(x+1) == '\0' ) return true;
42 
43  // do {
44  // if ( *x == '%' && (*(x+1) == '(' || *(x+1) == 'd') ) {
45  // // We have a %d or %(var)d to eat
46  // x++;
47  // if ( *x == '(' ) {
48  // while ( *x && (*x != ')') ) x++;
49  // x++; /* *x should now == 'd' */
50  // }
51  // if ( *x != 'd') /* Malformed string. Fail all the things */
52  // return false;
53  // x++; /* Finish eating the variable */
54  // /* Now, eat the corresponding digits of y */
55  // while ( *y && isdigit(*y) ) y++;
56  // }
57  // if ( *x != *y ) return false;
58  // if ( *x == '\0' ) return true;
59  // x++;
60  // y++;
61  // } while ( *x && *y );
62  // if ( *x != *y ) return false; // aka, both nullptr
63  // return true;
64  // }
65 
66  // bool checkPort(const std::string& name) const
67  // {
68  // // First check to see if this is a self port
69  // for ( std::vector<std::string>::const_iterator i = selfPorts.begin() ; i != selfPorts.end() ; ++i ) {
70  // /* Compare name with stored name, which may have wildcards */
71  // // if ( checkPort(i->c_str(), x) ) {
72  // if ( name == *i ) {
73  // return true;
74  // }
75  // }
76 
77  // // If no a self port, check against info in library manifest
78  // Component::isValidPortForComponent(
79  // const char *x = name.c_str();
80  // bool found = false;
81  // if ( nullptr != allowedPorts ) {
82  // for ( std::vector<std::string>::const_iterator i = allowedPorts->begin() ; i != allowedPorts->end() ; ++i ) {
83  // /* Compare name with stored name, which may have wildcards */
84  // if ( checkPort(i->c_str(), x) ) {
85  // found = true;
86  // break;
87  // }
88  // }
89  // }
90  // return found;
91  // }
92 
93  // bool checkPort(const std::string& name) const
94  // {
95  // const char *x = name.c_str();
96  // bool found = false;
97  // if ( nullptr != allowedPorts ) {
98  // for ( std::vector<std::string>::const_iterator i = allowedPorts->begin() ; i != allowedPorts->end() ; ++i ) {
99  // /* Compare name with stored name, which may have wildcards */
100  // if ( checkPort(i->c_str(), x) ) {
101  // found = true;
102  // break;
103  // }
104  // }
105  // }
106 
107  // if ( !found ) { // Check self ports
108  // for ( std::vector<std::string>::const_iterator i = selfPorts.begin() ; i != selfPorts.end() ; ++i ) {
109  // /* Compare name with stored name, which may have wildcards */
110  // // if ( checkPort(i->c_str(), x) ) {
111  // if ( name == *i ) {
112  // found = true;
113  // break;
114  // }
115  // }
116  // }
117 
118  // return found;
119  // }
120 
121 public:
122 #if !SST_BUILDING_CORE
123  LinkMap() /*: allowedPorts(nullptr)*/ __attribute__ ((deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12."))) {}
124 #else
125  LinkMap() /*: allowedPorts(nullptr)*/ {}
126 #endif
127 
128 #if !SST_BUILDING_CORE
129  ~LinkMap() __attribute__ ((deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12."))) {
130 #else
131  ~LinkMap() {
132 #endif
133  // Delete all the links in the map
134  for ( std::map<std::string,Link*>::iterator it = linkMap.begin(); it != linkMap.end(); ++it ) {
135  delete it->second;
136  }
137  linkMap.clear();
138  }
139 
140  // /**
141  // * Set the list of allowed port names from the ElementInfoPort
142  // */
143  // void setAllowedPorts(const std::vector<std::string> *p)
144  // {
145  // allowedPorts = p;
146  // }
147 
148 
149 
150  /**
151  * Add a port name to the list of allowed ports.
152  * Used by SelfLinks, as these are undocumented.
153  */
154 #if !SST_BUILDING_CORE
155  void addSelfPort(const std::string& name) __attribute__ ((deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
156 #else
157  void addSelfPort(const std::string& name)
158 #endif
159  {
160  selfPorts.push_back(name);
161  }
162 
163 #if !SST_BUILDING_CORE
164  bool isSelfPort(const std::string& name) const __attribute__ ((deprecated("LinkMap class was not intended to be used otuside of SST Core and will be removed in SST 12."))) {
165 #else
166  bool isSelfPort(const std::string& name) const {
167 #endif
168  for ( std::vector<std::string>::const_iterator i = selfPorts.begin() ; i != selfPorts.end() ; ++i ) {
169  /* Compare name with stored name, which may have wildcards */
170  // if ( checkPort(i->c_str(), x) ) {
171  if ( name == *i ) {
172  return true;
173  }
174  }
175  return false;
176  }
177 
178  /** Inserts a new pair of name and link into the map */
179 #if !SST_BUILDING_CORE
180  void insertLink(const std::string& name, Link* link) __attribute__ ((deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12."))) {
181 #else
182  void insertLink(const std::string& name, Link* link) {
183 #endif
184  linkMap.insert(std::pair<std::string,Link*>(name,link));
185  }
186 
187 #if !SST_BUILDING_CORE
188  void removeLink(const std::string& name) __attribute__ ((deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12."))) {
189 #else
190  void removeLink(const std::string& name) {
191 #endif
192  linkMap.erase(name);
193  }
194 
195  /** Returns a Link pointer for a given name */
196 #if !SST_BUILDING_CORE
197  Link* getLink(const std::string& name) __attribute__ ((deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12."))) {
198 #else
199  Link* getLink(const std::string& name) {
200 #endif
201 
202 // if ( !checkPort(name) ) {
203 // #ifdef USE_PARAM_WARNINGS
204 // std::cerr << "Warning: Using undocumented port '" << name << "'." << std::endl;
205 // #endif
206 // }
207  std::map<std::string,Link*>::iterator it = linkMap.find(name);
208  if ( it == linkMap.end() ) return nullptr;
209  else return it->second;
210  }
211 
212  /**
213  Checks to see if LinkMap is empty.
214  @return True if Link map is empty, false otherwise
215  */
216 #if !SST_BUILDING_CORE
217  bool empty() __attribute__ ((deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12."))) {
218 #else
219  bool empty() {
220 #endif
221 
222  return linkMap.empty();
223  }
224 
225  // FIXME: Kludge for now, fix later. Need to make LinkMap look
226  // like a regular map instead.
227  /** Return a reference to the internal map */
228 #if !SST_BUILDING_CORE
229  std::map<std::string,Link*>& getLinkMap() __attribute__ ((deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12."))) {
230 #else
231  std::map<std::string,Link*>& getLinkMap() {
232 #endif
233  return linkMap;
234  }
235 
236 };
237 
238 } // namespace SST
239 
240 #endif // SST_CORE_LINKMAP_H
Maps port names to the Links that are connected to it.
Definition: linkMap.h:28
void insertLink(const std::string &name, Link *link)
Inserts a new pair of name and link into the map.
Definition: linkMap.h:180
std::map< std::string, Link * > & getLinkMap()
Return a reference to the internal map.
Definition: linkMap.h:229
void addSelfPort(const std::string &name)
Set the list of allowed port names from the ElementInfoPort.
Definition: linkMap.h:155
bool empty()
Checks to see if LinkMap is empty.
Definition: linkMap.h:217
Link * getLink(const std::string &name)
Returns a Link pointer for a given name.
Definition: linkMap.h:197