Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] Use std::string::compare instead of strncmp
[simgrid.git] / src / surf / xml / surfxml_sax_cb.cpp
index 186b559b94466835f71e76ba1842e8e21a0b1d9e..8d77fca7da5e9675c6127dd91b23e489d07416e5 100644 (file)
@@ -65,7 +65,7 @@ void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* pos
   msg += " Existing netpoints: \n";
 
   std::vector<simgrid::kernel::routing::NetPoint*> list;
-  simgrid::s4u::Engine::instance()->netpointList(&list);
+  simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
   std::sort(list.begin(), list.end(),
       [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
       return a->name() < b->name();
@@ -319,7 +319,7 @@ static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* e
 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
 
 /* The default current property receiver. Setup in the corresponding opening callbacks. */
-xbt_dict_t current_property_set = nullptr;
+std::map<std::string, std::string>* current_property_set       = nullptr;
 std::map<std::string, std::string>* current_model_property_set = nullptr;
 int ZONE_TAG                            = 0; // Whether we just opened a zone tag (to see what to do with the properties)
 
@@ -329,19 +329,17 @@ xbt_dict_t random_data_list = nullptr;
 YY_BUFFER_STATE surf_input_buffer;
 FILE *surf_file_to_parse = nullptr;
 
-/*
- * Stuff relative to storage
- */
+/* Stuff relative to storage */
 void STag_surfxml_storage()
 {
   ZONE_TAG = 0;
   XBT_DEBUG("STag_surfxml_storage");
   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
 }
+
 void ETag_surfxml_storage()
 {
-  s_sg_platf_storage_cbarg_t storage;
-  memset(&storage,0,sizeof(storage));
+  StorageCreationArgs storage;
 
   storage.properties   = current_property_set;
   current_property_set = nullptr;
@@ -349,8 +347,8 @@ void ETag_surfxml_storage()
   storage.id           = A_surfxml_storage_id;
   storage.type_id      = A_surfxml_storage_typeId;
   storage.content      = A_surfxml_storage_content;
-
   storage.attach       = A_surfxml_storage_attach;
+
   sg_platf_new_storage(&storage);
 }
 void STag_surfxml_storage___type()
@@ -362,8 +360,7 @@ void STag_surfxml_storage___type()
 }
 void ETag_surfxml_storage___type()
 {
-  s_sg_platf_storage_type_cbarg_t storage_type;
-  memset(&storage_type,0,sizeof(storage_type));
+  StorageTypeCreationArgs storage_type;
 
   storage_type.properties = current_property_set;
   current_property_set    = nullptr;
@@ -371,21 +368,22 @@ void ETag_surfxml_storage___type()
   storage_type.model_properties = current_model_property_set;
   current_model_property_set    = nullptr;
 
-  storage_type.content          = A_surfxml_storage___type_content;
-  storage_type.id               = A_surfxml_storage___type_id;
-  storage_type.model            = A_surfxml_storage___type_model;
-  storage_type.size             = surf_parse_get_size(A_surfxml_storage___type_size,
-        "size of storage type", storage_type.id);
+  storage_type.content = A_surfxml_storage___type_content;
+  storage_type.id      = A_surfxml_storage___type_id;
+  storage_type.model   = A_surfxml_storage___type_model;
+  storage_type.size =
+      surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
   sg_platf_new_storage_type(&storage_type);
 }
+
 void STag_surfxml_mount()
 {
   XBT_DEBUG("STag_surfxml_mount");
 }
+
 void ETag_surfxml_mount()
 {
-  s_sg_platf_mount_cbarg_t mount;
-  memset(&mount,0,sizeof(mount));
+  MountCreationArgs mount;
 
   mount.name      = A_surfxml_mount_name;
   mount.storageId = A_surfxml_mount_storageId;
@@ -519,14 +517,13 @@ void STag_surfxml_prop()
 {
   if (ZONE_TAG) { // We need to retrieve the most recently opened zone
     XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
-    simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_zone_id);
+    simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
 
     netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
-  }
-  else{
+  } else {
     if (not current_property_set)
-      current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
-    xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
+      current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
+    current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
     XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
               current_property_set);
   }
@@ -666,12 +663,12 @@ void STag_surfxml_cabinet(){
 
 void STag_surfxml_peer(){
   parse_after_config();
-  s_sg_platf_peer_cbarg_t peer;
-  memset(&peer,0,sizeof(peer));
-  peer.id          = A_surfxml_peer_id;
-  peer.speed       = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id);
-  peer.bw_in       = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id);
-  peer.bw_out      = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id);
+  PeerCreationArgs peer;
+
+  peer.id          = std::string(A_surfxml_peer_id);
+  peer.speed       = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
+  peer.bw_in       = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
+  peer.bw_out      = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
   peer.coord       = A_surfxml_peer_coordinates;
   peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
   peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
@@ -998,19 +995,16 @@ void STag_surfxml_config()
 
 void ETag_surfxml_config()
 {
-  xbt_dict_cursor_t cursor = nullptr;
-  char *key;
-  char *elem;
-  xbt_dict_foreach(current_property_set, cursor, key, elem) {
-    if (xbt_cfg_is_default_value(key)) {
-      std::string cfg = std::string(key) + ":" + elem;
+  for (auto elm : *current_property_set) {
+    if (xbt_cfg_is_default_value(elm.first.c_str())) {
+      std::string cfg = elm.first + ":" + elm.second;
       xbt_cfg_set_parse(cfg.c_str());
     } else
-      XBT_INFO("The custom configuration '%s' is already defined by user!",key);
+      XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
   }
   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
 
-  xbt_dict_free(&current_property_set);
+  delete current_property_set;
   current_property_set = nullptr;
 }
 
@@ -1115,7 +1109,8 @@ void surf_parse_open(const char *file)
   xbt_free(dir);
 
   surf_file_to_parse = surf_fopen(file, "r");
-  xbt_assert(surf_file_to_parse != nullptr, "Unable to open '%s'\n", file);
+  if (surf_file_to_parse == nullptr)
+    xbt_die("Unable to open '%s'\n", file);
   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
   surf_parse__switch_to_buffer(surf_input_buffer);
   surf_parse_lineno = 1;
@@ -1137,11 +1132,10 @@ void surf_parse_close()
   }
 }
 
-/* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
-static int _surf_parse() {
+/* Call the lexer to parse the currently opened file */
+int surf_parse()
+{
   return surf_parse_lex();
 }
 
-int_f_void_t surf_parse = &_surf_parse;
-
 SG_END_DECL()