SST  11.1.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/component.h"
16 #include "sst/core/link.h"
17 #include "sst/core/sst_types.h"
18 
19 #include <map>
20 #include <string>
21 
22 namespace SST {
23 
24 /**
25  * Maps port names to the Links that are connected to it
26  */
27 class LinkMap
28 {
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  // ) {
84  // /* Compare name with stored name, which may have wildcards */
85  // if ( checkPort(i->c_str(), x) ) {
86  // found = true;
87  // break;
88  // }
89  // }
90  // }
91  // return found;
92  // }
93 
94  // bool checkPort(const std::string& name) const
95  // {
96  // const char *x = name.c_str();
97  // bool found = false;
98  // if ( nullptr != allowedPorts ) {
99  // for ( std::vector<std::string>::const_iterator i = allowedPorts->begin() ; i != allowedPorts->end() ; ++i
100  // ) {
101  // /* Compare name with stored name, which may have wildcards */
102  // if ( checkPort(i->c_str(), x) ) {
103  // found = true;
104  // break;
105  // }
106  // }
107  // }
108 
109  // if ( !found ) { // Check self ports
110  // for ( std::vector<std::string>::const_iterator i = selfPorts.begin() ; i != selfPorts.end() ; ++i ) {
111  // /* Compare name with stored name, which may have wildcards */
112  // // if ( checkPort(i->c_str(), x) ) {
113  // if ( name == *i ) {
114  // found = true;
115  // break;
116  // }
117  // }
118  // }
119 
120  // return found;
121  // }
122 
123 public:
124 #if !SST_BUILDING_CORE
125  LinkMap() /*: allowedPorts(nullptr)*/ __attribute__((
126  deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
127 #else
128  LinkMap() /*: allowedPorts(nullptr)*/
129 #endif
130  {}
131 
132 #if !SST_BUILDING_CORE
133  ~LinkMap() __attribute__((
134  deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
135 #else
136  ~LinkMap()
137 #endif
138  {
139  // Delete all the links in the map
140  for ( std::map<std::string, Link*>::iterator it = linkMap.begin(); it != linkMap.end(); ++it ) {
141  delete it->second;
142  }
143  linkMap.clear();
144  }
145 
146  // /**
147  // * Set the list of allowed port names from the ElementInfoPort
148  // */
149  // void setAllowedPorts(const std::vector<std::string> *p)
150  // {
151  // allowedPorts = p;
152  // }
153 
154  /**
155  * Add a port name to the list of allowed ports.
156  * Used by SelfLinks, as these are undocumented.
157  */
158 #if !SST_BUILDING_CORE
159  void addSelfPort(const std::string& name) __attribute__((
160  deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
161 #else
162  void addSelfPort(const std::string& name)
163 #endif
164  {
165  selfPorts.push_back(name);
166  }
167 
168 #if !SST_BUILDING_CORE
169  bool isSelfPort(const std::string& name) const __attribute__((
170  deprecated("LinkMap class was not intended to be used otuside of SST Core and will be removed in SST 12.")))
171 #else
172  bool isSelfPort(const std::string& name) const
173 #endif
174  {
175  for ( std::vector<std::string>::const_iterator i = selfPorts.begin(); i != selfPorts.end(); ++i ) {
176  /* Compare name with stored name, which may have wildcards */
177  // if ( checkPort(i->c_str(), x) ) {
178  if ( name == *i ) { return true; }
179  }
180  return false;
181  }
182 
183  /** Inserts a new pair of name and link into the map */
184 #if !SST_BUILDING_CORE
185  void insertLink(const std::string& name, Link* link) __attribute__((
186  deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
187 #else
188  void insertLink(const std::string& name, Link* link)
189 #endif
190  {
191  linkMap.insert(std::pair<std::string, Link*>(name, link));
192  }
193 
194 #if !SST_BUILDING_CORE
195  void removeLink(const std::string& name) __attribute__((
196  deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
197 #else
198  void removeLink(const std::string& name)
199 #endif
200  {
201  linkMap.erase(name);
202  }
203 
204  /** Returns a Link pointer for a given name */
205 #if !SST_BUILDING_CORE
206  Link* getLink(const std::string& name) __attribute__((
207  deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
208 #else
209  Link* getLink(const std::string& name)
210 #endif
211  {
212 
213  // if ( !checkPort(name) ) {
214  // #ifdef USE_PARAM_WARNINGS
215  // std::cerr << "Warning: Using undocumented port '" << name << "'." << std::endl;
216  // #endif
217  // }
218  std::map<std::string, Link*>::iterator it = linkMap.find(name);
219  if ( it == linkMap.end() )
220  return nullptr;
221  else
222  return it->second;
223  }
224 
225  /**
226  Checks to see if LinkMap is empty.
227  @return True if Link map is empty, false otherwise
228  */
229 #if !SST_BUILDING_CORE
230  bool empty() __attribute__((
231  deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
232 #else
233  bool empty()
234 #endif
235  {
236  return linkMap.empty();
237  }
238 
239  // FIXME: Kludge for now, fix later. Need to make LinkMap look
240  // like a regular map instead.
241  /** Return a reference to the internal map */
242 #if !SST_BUILDING_CORE
243  std::map<std::string, Link*>& getLinkMap() __attribute__((
244  deprecated("LinkMap class was not intended to be used outside of SST Core and will be removed in SST 12.")))
245 #else
246  std::map<std::string, Link*>& getLinkMap()
247 #endif
248  {
249  return linkMap;
250  }
251 };
252 
253 } // namespace SST
254 
255 #endif // SST_CORE_LINKMAP_H
Maps port names to the Links that are connected to it.
Definition: linkMap.h:27
void insertLink(const std::string &name, Link *link)
Inserts a new pair of name and link into the map.
Definition: linkMap.h:185
void addSelfPort(const std::string &name)
Set the list of allowed port names from the ElementInfoPort.
Definition: linkMap.h:159
bool empty()
Checks to see if LinkMap is empty.
Definition: linkMap.h:230
Link * getLink(const std::string &name)
Returns a Link pointer for a given name.
Definition: linkMap.h:206
std::map< std::string, Link * > & getLinkMap()
Return a reference to the internal map.
Definition: linkMap.h:243