Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
surf_fopen to ifsopen + no need to reimplement streambuffers
[simgrid.git] / src / surf / surf_interface.cpp
index e9b9cf2..9010a94 100644 (file)
@@ -16,6 +16,7 @@
 #include "src/simix/smx_host_private.h"
 #include "src/surf/HostImpl.hpp"
 #include "surf_private.h"
+#include <fstream>
 #include <vector>
 
 XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
@@ -41,9 +42,11 @@ simgrid::xbt::signal<void(void)> surfExitCallbacks;
 }
 
 #include <simgrid/plugins/energy.h> // FIXME: this plugin should not be linked to the core
+#include <simgrid/plugins/load.h>   // FIXME: this plugin should not be linked to the core
 
 s_surf_model_description_t surf_plugin_description[] = {
     {"Energy", "Cpu energy consumption.", &sg_host_energy_plugin_init},
+    {"Load", "Cpu load.", &sg_host_load_plugin_init},
     {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
 };
 
@@ -125,6 +128,27 @@ double surf_get_clock()
 # define FILE_DELIM "/"         /* FIXME: move to better location */
 #endif
 
+std::ifstream* surf_ifsopen(const char* name)
+{
+  std::ifstream* fs = new std::ifstream();
+  xbt_assert(name);
+  if (__surf_is_absolute_file_path(name)) { /* don't mess with absolute file names */
+    fs->open(name, std::ifstream::in);
+  }
+
+  /* search relative files in the path */
+  for (auto path_elm : surf_path) {
+    std::string buff = path_elm + FILE_DELIM + name;
+    fs->open(buff.c_str(), std::ifstream::in);
+
+    if (!fs->fail()) {
+      XBT_DEBUG("Found file at %s", buff.c_str());
+      return fs;
+    }
+  }
+
+  return fs;
+}
 FILE *surf_fopen(const char *name, const char *mode)
 {
   char *buff;