SST 16.0.0
Structural Simulation Toolkit
linkMap.h
1// Copyright 2009-2026 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-2026, 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#include <utility>
22#include <vector>
23
24namespace SST {
25
26/**
27 * Maps port names to the Links that are connected to it
28 */
29class LinkMap
30{
31 std::map<std::string, Link*> linkMap;
32 // const std::vector<std::string> * allowedPorts;
33 std::vector<std::string> selfPorts;
34
35public:
36 void serialize_order(SST::Core::Serialization::serializer& ser)
37 {
38 SST_SER(linkMap);
39 SST_SER(selfPorts);
40 }
41
42
43 // bool checkPort(const char *def, const char *offered) const
44 // {
45 // const char * x = def;
46 // const char * y = offered;
47
48 // /* Special case. Name of '*' matches everything */
49 // if ( *x == '*' && *(x+1) == '\0' ) return true;
50
51 // do {
52 // if ( *x == '%' && (*(x+1) == '(' || *(x+1) == 'd') ) {
53 // // We have a %d or %(var)d to eat
54 // x++;
55 // if ( *x == '(' ) {
56 // while ( *x && (*x != ')') ) x++;
57 // x++; /* *x should now == 'd' */
58 // }
59 // if ( *x != 'd') /* Malformed string. Fail all the things */
60 // return false;
61 // x++; /* Finish eating the variable */
62 // /* Now, eat the corresponding digits of y */
63 // while ( *y && isdigit(*y) ) y++;
64 // }
65 // if ( *x != *y ) return false;
66 // if ( *x == '\0' ) return true;
67 // x++;
68 // y++;
69 // } while ( *x && *y );
70 // if ( *x != *y ) return false; // aka, both nullptr
71 // return true;
72 // }
73
74 // bool checkPort(const std::string& name) const
75 // {
76 // // First check to see if this is a self port
77 // for ( std::vector<std::string>::const_iterator i = selfPorts.begin() ; i != selfPorts.end() ; ++i ) {
78 // /* Compare name with stored name, which may have wildcards */
79 // // if ( checkPort(i->c_str(), x) ) {
80 // if ( name == *i ) {
81 // return true;
82 // }
83 // }
84
85 // // If no a self port, check against info in library manifest
86 // Component::isValidPortForComponent(
87 // const char *x = name.c_str();
88 // bool found = false;
89 // if ( nullptr != allowedPorts ) {
90 // for ( std::vector<std::string>::const_iterator i = allowedPorts->begin() ; i != allowedPorts->end() ; ++i
91 // ) {
92 // /* Compare name with stored name, which may have wildcards */
93 // if ( checkPort(i->c_str(), x) ) {
94 // found = true;
95 // break;
96 // }
97 // }
98 // }
99 // return found;
100 // }
101
102 // bool checkPort(const std::string& name) const
103 // {
104 // const char *x = name.c_str();
105 // bool found = false;
106 // if ( nullptr != allowedPorts ) {
107 // for ( std::vector<std::string>::const_iterator i = allowedPorts->begin() ; i != allowedPorts->end() ; ++i
108 // ) {
109 // /* Compare name with stored name, which may have wildcards */
110 // if ( checkPort(i->c_str(), x) ) {
111 // found = true;
112 // break;
113 // }
114 // }
115 // }
116
117 // if ( !found ) { // Check self ports
118 // for ( std::vector<std::string>::const_iterator i = selfPorts.begin() ; i != selfPorts.end() ; ++i ) {
119 // /* Compare name with stored name, which may have wildcards */
120 // // if ( checkPort(i->c_str(), x) ) {
121 // if ( name == *i ) {
122 // found = true;
123 // break;
124 // }
125 // }
126 // }
127
128 // return found;
129 // }
130
131 LinkMap() /*: allowedPorts(nullptr)*/ {}
132
133 ~LinkMap()
134 {
135 // Delete all the links in the map
136 for ( auto& [name, link] : linkMap )
137 delete link;
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 * Add a port name to the list of allowed ports.
150 * Used by SelfLinks, as these are undocumented.
151 */
152 void addSelfPort(const std::string& name) { selfPorts.push_back(name); }
153
154 bool isSelfPort(const std::string& name) const
155 {
156 for ( std::vector<std::string>::const_iterator i = selfPorts.begin(); i != selfPorts.end(); ++i ) {
157 /* Compare name with stored name, which may have wildcards */
158 // if ( checkPort(i->c_str(), x) ) {
159 if ( name == *i ) {
160 return true;
161 }
162 }
163 return false;
164 }
165
166 /** Inserts a new pair of name and link into the map */
167 void insertLink(const std::string& name, Link* link) { linkMap.insert(std::pair<std::string, Link*>(name, link)); }
168
169 void removeLink(const std::string& name) { linkMap.erase(name); }
170
171 /** Returns a Link pointer for a given name */
172 Link* getLink(const std::string& name)
173 {
174
175 // if ( !checkPort(name) ) {
176 // #ifdef USE_PARAM_WARNINGS
177 // std::cerr << "Warning: Using undocumented port '" << name << "'." << std::endl;
178 // #endif
179 // }
180 std::map<std::string, Link*>::iterator it = linkMap.find(name);
181 if ( it == linkMap.end() )
182 return nullptr;
183 else
184 return it->second;
185 }
186
187 /**
188 Checks to see if LinkMap is empty.
189 @return True if Link map is empty, false otherwise
190 */
191 bool empty() { return linkMap.empty(); }
192
193 // FIXME: Kludge for now, fix later. Need to make LinkMap look
194 // like a regular map instead.
195 /** Return a reference to the internal map */
196 std::map<std::string, Link*>& getLinkMap() { return linkMap; }
197};
198
199} // namespace SST
200
201#endif // SST_CORE_LINKMAP_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
void addSelfPort(const std::string &name)
Set the list of allowed port names from the ElementInfoPort.
Definition linkMap.h:152
std::map< std::string, Link * > & getLinkMap()
Return a reference to the internal map.
Definition linkMap.h:196
Link * getLink(const std::string &name)
Returns a Link pointer for a given name.
Definition linkMap.h:172
void insertLink(const std::string &name, Link *link)
Inserts a new pair of name and link into the map.
Definition linkMap.h:167
bool empty()
Checks to see if LinkMap is empty.
Definition linkMap.h:191