Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
prefix all macro defined in public simgrid_config.h with 'SIMGRID_'
[simgrid.git] / src / surf / xml / surfxml_parseplatf.cpp
index 14ebf6d..24892fd 100644 (file)
@@ -4,17 +4,18 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "xbt/misc.h"
-#include "xbt/log.h"
-#include "xbt/str.h"
-#include "xbt/dict.h"
+#include "src/instr/instr_private.h" // TRACE_start(). FIXME: remove by subscribing tracing to the surf signals
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
-#include "src/instr/instr_private.h" // TRACE_start(). FIXME: remove by subscribing tracing to the surf signals
+#include "xbt/dict.h"
+#include "xbt/log.h"
+#include "xbt/misc.h"
+#include "xbt/str.h"
+#include <vector>
 
 #include "src/surf/xml/platf_private.hpp"
 
-#if HAVE_LUA
+#if SIMGRID_HAVE_LUA
 extern "C" {
 #include "src/bindings/lua/simgrid_lua.h"
 
@@ -26,13 +27,15 @@ extern "C" {
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 
+SG_BEGIN_DECL()
+
 /*
  *  Allow the cluster tag to mess with the parsing buffer.
  * (this will probably become obsolete once the cluster tag do not mess with the parsing callbacks directly)
  */
 
 /* This buffer is used to store the original buffer before substituting it by out own buffer. Useful for the cluster tag */
-static xbt_dynar_t surfxml_bufferstack_stack = nullptr;
+static std::vector<char*> surfxml_bufferstack_stack;
 int surfxml_bufferstack_size = 2048;
 
 static char *old_buff = nullptr;
@@ -45,7 +48,7 @@ void surfxml_bufferstack_push(int new_one)
   if (!new_one)
     old_buff = surfxml_bufferstack;
   else {
-    xbt_dynar_push(surfxml_bufferstack_stack, &surfxml_bufferstack);
+    surfxml_bufferstack_stack.push_back(surfxml_bufferstack);
     surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
   }
 }
@@ -56,7 +59,8 @@ void surfxml_bufferstack_pop(int new_one)
     surfxml_bufferstack = old_buff;
   else {
     free(surfxml_bufferstack);
-    xbt_dynar_pop(surfxml_bufferstack_stack, &surfxml_bufferstack);
+    surfxml_bufferstack = surfxml_bufferstack_stack.back();
+    surfxml_bufferstack_stack.pop_back();
   }
 }
 
@@ -127,14 +131,14 @@ void parse_after_config() {
 /* This function acts as a main in the parsing area. */
 void parse_platform_file(const char *file)
 {
-#if HAVE_LUA
+#if SIMGRID_HAVE_LUA
   int len    = (file == nullptr ? 0 : strlen(file));
   int is_lua = (file != nullptr && len > 3 && file[len - 3] == 'l' && file[len - 2] == 'u' && file[len - 1] == 'a');
 #endif
 
   sg_platf_init();
 
-#if HAVE_LUA
+#if SIMGRID_HAVE_LUA
   /* Check if file extension is "lua". If so, we will use
    * the lua bindings to parse the platform file (since it is
    * written in lua). If not, we will use the (old?) XML parser
@@ -171,10 +175,6 @@ void parse_platform_file(const char *file)
     trace_connect_list_link_bw = xbt_dict_new_homogeneous(free);
     trace_connect_list_link_lat = xbt_dict_new_homogeneous(free);
 
-    /* Init my data */
-    if (!surfxml_bufferstack_stack)
-      surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), nullptr);
-
     /* Do the actual parsing */
     parse_status = surf_parse();
 
@@ -205,7 +205,7 @@ void parse_platform_file(const char *file)
     xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
       tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
       xbt_assert(trace, "Trace %s undefined", trace_name);
-      Link *link = Link::byName(elm);
+      sg_link_t link = simgrid::s4u::Link::byName(elm);
       xbt_assert(link, "Link %s undefined", elm);
       link->setStateTrace(trace);
     }
@@ -213,7 +213,7 @@ void parse_platform_file(const char *file)
     xbt_dict_foreach(trace_connect_list_link_bw, cursor, trace_name, elm) {
       tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
       xbt_assert(trace, "Trace %s undefined", trace_name);
-      Link *link = Link::byName(elm);
+      sg_link_t link = simgrid::s4u::Link::byName(elm);
       xbt_assert(link, "Link %s undefined", elm);
       link->setBandwidthTrace(trace);
     }
@@ -221,7 +221,7 @@ void parse_platform_file(const char *file)
     xbt_dict_foreach(trace_connect_list_link_lat, cursor, trace_name, elm) {
       tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
       xbt_assert(trace, "Trace %s undefined", trace_name);
-      Link *link = Link::byName(elm);
+      sg_link_t link = simgrid::s4u::Link::byName(elm);
       xbt_assert(link, "Link %s undefined", elm);
       link->setLatencyTrace(trace);
     }
@@ -233,14 +233,12 @@ void parse_platform_file(const char *file)
     xbt_dict_free(&trace_connect_list_link_bw);
     xbt_dict_free(&trace_connect_list_link_lat);
     xbt_dict_free(&traces_set_list);
-    xbt_dynar_free(&surfxml_bufferstack_stack);
 
     surf_parse_close();
 
     if (parse_status)
       surf_parse_error("Parse error in %s", file);
-
   }
-
-
 }
+
+SG_END_DECL()