Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use vector of strings for args.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 8 Oct 2020 14:25:58 +0000 (16:25 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 8 Oct 2020 14:26:49 +0000 (16:26 +0200)
examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp
examples/s4u/io-file-remote/s4u-io-file-remote.cpp
examples/s4u/platform-failures/s4u-platform-failures.cpp

index 60362b8..dd3acdd 100644 (file)
@@ -17,22 +17,22 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(kademlia, "Messages specific for this example");
   * @param the ID of the person I know in the system (or not)
   * @param Time before I leave the system because I'm bored
   */
-static void node(int argc, char* argv[])
+static void node(std::vector<std::string> args)
 {
   bool join_success = true;
   double deadline;
-  xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments");
+  xbt_assert(args.size() == 3 || args.size() == 4, "Wrong number of arguments");
   /* Node initialization */
-  auto node_id = static_cast<unsigned int>(strtoul(argv[1], nullptr, 0));
+  auto node_id = static_cast<unsigned int>(std::stoul(args[1], 0, 0));
   kademlia::Node node(node_id);
 
-  if (argc == 4) {
+  if (args.size() == 4) {
     XBT_INFO("Hi, I'm going to join the network with id %u", node.getId());
-    auto known_id = static_cast<unsigned int>(strtoul(argv[2], nullptr, 0));
+    auto known_id = static_cast<unsigned int>(std::stoul(args[2], 0, 0));
     join_success  = node.join(known_id);
-    deadline      = std::stod(argv[3]);
+    deadline      = std::stod(args[3]);
   } else {
-    deadline = std::stod(argv[2]);
+    deadline = std::stod(args[2]);
     XBT_INFO("Hi, I'm going to create the network with id %u", node.getId());
     node.routingTableUpdate(node.getId());
   }
index a3b2fd9..f27a60c 100644 (file)
@@ -11,9 +11,9 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example");
 
-static void host(int argc, char* argv[])
+static void host(std::vector<std::string> args)
 {
-  simgrid::s4u::File file(argv[1], nullptr);
+  simgrid::s4u::File file(args[1], nullptr);
   const char* filename = file.get_path();
   XBT_INFO("Opened file '%s'", filename);
   file.dump();
@@ -21,15 +21,15 @@ static void host(int argc, char* argv[])
   sg_size_t write = file.write(file.size() * 1024);
   XBT_INFO("Have written %llu MiB to '%s'.", write / (1024 * 1024), filename);
 
-  if (argc > 4) {
-    if (std::stoi(argv[4]) != 0) {
+  if (args.size() > 4) {
+    if (std::stoi(args[4]) != 0) {
       XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file.size(),
-               simgrid::s4u::Host::current()->get_cname(), argv[2]);
-      file.remote_move(simgrid::s4u::Host::by_name(argv[2]), argv[3]);
+               simgrid::s4u::Host::current()->get_cname(), args[2].c_str());
+      file.remote_move(simgrid::s4u::Host::by_name(args[2]), args[3]);
     } else {
       XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file.size(),
-               simgrid::s4u::Host::current()->get_cname(), argv[2]);
-      file.remote_copy(simgrid::s4u::Host::by_name(argv[2]), argv[3]);
+               simgrid::s4u::Host::current()->get_cname(), args[2].c_str());
+      file.remote_copy(simgrid::s4u::Host::by_name(args[2]), args[3]);
     }
   }
 }
index 0d4006e..84c7643 100644 (file)
  */
 
 #include "simgrid/s4u.hpp"
-#include "xbt/str.h"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
 
-static void master(int argc, char* argv[])
+static void master(std::vector<std::string> args)
 {
-  xbt_assert(argc == 5, "Expecting one parameter");
+  xbt_assert(args.size() == 5, "Expecting one parameter");
 
   simgrid::s4u::Mailbox* mailbox;
-  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
-  double comp_size     = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
-  long comm_size       = xbt_str_parse_int(argv[3], "Invalid communication size: %s");
-  long workers_count   = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s");
+  long number_of_tasks = std::stol(args[1]);
+  double comp_size     = std::stod(args[2]);
+  long comm_size       = std::stol(args[3]);
+  long workers_count   = std::stol(args[4]);
 
   XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks);
 
@@ -69,10 +68,10 @@ static void master(int argc, char* argv[])
   XBT_INFO("Goodbye now!");
 }
 
-static void worker(int argc, char* argv[])
+static void worker(std::vector<std::string> args)
 {
-  xbt_assert(argc == 2, "Expecting one parameter");
-  long id                          = xbt_str_parse_int(argv[1], "Invalid argument %s");
+  xbt_assert(args.size() == 2, "Expecting one parameter");
+  long id                          = std::stol(args[1]);
   simgrid::s4u::Mailbox* mailbox   = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(id));
   while (true) {
     try {