System::printSystems();
}
+std::string
+System::stripSystemName(const std::string& master_name) const
+{
+ if (startswith(master_name, name())) {
+ return master_name.substr(name().size());
+ } else {
+ return master_name;
+ }
+}
+
+MasterID
+System::lookupMasterId(const SimObject* obj) const
+{
+ MasterID id = Request::invldMasterId;
+
+ // number of occurrences of the SimObject pointer
+ // in the master list.
+ auto obj_number = 0;
+
+ for (int i = 0; i < masters.size(); i++) {
+ if (masters[i].obj == obj) {
+ id = i;
+ obj_number++;
+ }
+ }
+
+ fatal_if(obj_number > 1,
+ "Cannot lookup MasterID by SimObject pointer: "
+ "More than one master is sharing the same SimObject\n");
+
+ return id;
+}
+
+MasterID
+System::lookupMasterId(const std::string& master_name) const
+{
+ std::string name = stripSystemName(master_name);
+
+ for (int i = 0; i < masters.size(); i++) {
+ if (masters[i].masterName == name) {
+ return i;
+ }
+ }
+
+ return Request::invldMasterId;
+}
+
MasterID
-System::getGlobalMasterId(std::string master_name)
+System::getGlobalMasterId(const std::string& master_name)
{
return _getMasterId(nullptr, master_name);
}
}
MasterID
-System::_getMasterId(const SimObject* master, std::string master_name)
+System::_getMasterId(const SimObject* master, const std::string& master_name)
{
- if (startswith(master_name, name()))
- master_name = master_name.erase(0, name().size() + 1);
+ std::string name = stripSystemName(master_name);
// CPUs in switch_cpus ask for ids again after switching
for (int i = 0; i < masters.size(); i++) {
- if (masters[i].masterName == master_name) {
+ if (masters[i].masterName == name) {
return i;
}
}
MasterID master_id = masters.size();
// Append the new Master metadata to the group of system Masters.
- masters.emplace_back(master, master_name, master_id);
+ masters.emplace_back(master, name, master_id);
return masters.back().masterId;
}
ThermalModel * thermalModel;
+ protected:
+ /**
+ * Strips off the system name from a master name
+ */
+ std::string stripSystemName(const std::string& master_name) const;
+
public:
/**
* @param masterName full name of the master
* @return the master's ID.
*/
- MasterID getGlobalMasterId(std::string master_name);
+ MasterID getGlobalMasterId(const std::string& master_name);
/**
* Get the name of an object for a given request id.
*/
std::string getMasterName(MasterID master_id);
+ /**
+ * Looks up the MasterID for a given SimObject
+ * returns an invalid MasterID (invldMasterId) if not found.
+ */
+ MasterID lookupMasterId(const SimObject* obj) const;
+
+ /**
+ * Looks up the MasterID for a given object name string
+ * returns an invalid MasterID (invldMasterId) if not found.
+ */
+ MasterID lookupMasterId(const std::string& name) const;
+
/** Get the number of masters registered in the system */
MasterID maxMasters() { return masters.size(); }
protected:
/** helper function for getMasterId */
- MasterID _getMasterId(const SimObject* master, std::string master_name);
+ MasterID _getMasterId(const SimObject* master,
+ const std::string& master_name);
/**
* Helper function for constructing the full (sub)master name