From: Frederic Suter Date: Mon, 24 Apr 2017 13:17:06 +0000 (+0200) Subject: xbt_strbuff to std::string in cpp files X-Git-Tag: v3.16~315 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/bfd98a2964b17caa9ed2f331432cbf9a641c2d2a xbt_strbuff to std::string in cpp files --- diff --git a/src/surf/maxmin.cpp b/src/surf/maxmin.cpp index dc0280b8ba..0ab8b4d257 100644 --- a/src/surf/maxmin.cpp +++ b/src/surf/maxmin.cpp @@ -624,26 +624,27 @@ static inline void saturated_variable_set_update(s_lmm_constraint_light_t *cnst_ void lmm_print(lmm_system_t sys) { - void *_cnst, *_elem, *_var; + void* _cnst; + void* _elem; + void* _var; lmm_constraint_t cnst = nullptr; - lmm_element_t elem = nullptr; - lmm_variable_t var = nullptr; - xbt_swag_t cnst_list = nullptr; - xbt_swag_t var_list = nullptr; - xbt_swag_t elem_list = nullptr; - xbt_strbuff_t buf = xbt_strbuff_new(); + lmm_element_t elem = nullptr; + lmm_variable_t var = nullptr; + xbt_swag_t cnst_list = nullptr; + xbt_swag_t var_list = nullptr; + xbt_swag_t elem_list = nullptr; + std::string buf = std::string("MAX-MIN ( "); double sum = 0.0; /* Printing Objective */ var_list = &(sys->variable_set); - xbt_strbuff_append(buf, "MAX-MIN ( "); xbt_swag_foreach(_var, var_list) { var = (lmm_variable_t)_var; - xbt_strbuff_printf(buf, "'%d'(%f) ", var->id_int, var->weight); + buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->weight) + ") "; } - xbt_strbuff_append(buf, ")"); - XBT_DEBUG("%20s", buf->data); - xbt_strbuff_clear(buf); + buf += ")"; + XBT_DEBUG("%20s", buf.c_str()); + buf.clear(); XBT_DEBUG("Constraints"); /* Printing Constraints */ @@ -653,12 +654,12 @@ void lmm_print(lmm_system_t sys) sum = 0.0; //Show the enabled variables elem_list = &(cnst->enabled_element_set); - xbt_strbuff_append(buf, "\t"); - xbt_strbuff_printf(buf, "%s(", (cnst->sharing_policy)?"":"max"); + buf += "\t"; + buf += ((cnst->sharing_policy) ? "(" : "max("); xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; - xbt_strbuff_printf(buf, "%f.'%d'(%f) %s ", elem->value, - elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":","); + buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" + + std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , "); if(cnst->sharing_policy) sum += elem->value * elem->variable->value; else @@ -668,21 +669,21 @@ void lmm_print(lmm_system_t sys) elem_list = &(cnst->disabled_element_set); xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; - xbt_strbuff_printf(buf, "%f.'%d'(%f) %s ", elem->value, - elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":","); + buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" + + std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , "); if(cnst->sharing_policy) sum += elem->value * elem->variable->value; else sum = MAX(sum,elem->value * elem->variable->value); } - xbt_strbuff_printf(buf, "0) <= %f ('%d')", cnst->bound, cnst->id_int); + buf = buf + "0) <= " + std::to_string(cnst->bound) + " ('" + std::to_string(cnst->id_int) + "')"; if (!cnst->sharing_policy) { - xbt_strbuff_printf(buf, " [MAX-Constraint]"); + buf += " [MAX-Constraint]"; } - XBT_DEBUG("%s", buf->data); - xbt_strbuff_clear(buf); + XBT_DEBUG("%s", buf.c_str()); + buf.clear(); xbt_assert(!double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision), "Incorrect value (%f is not smaller than %f): %g", sum, cnst->bound, sum - cnst->bound); //if(double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision)) @@ -701,8 +702,6 @@ void lmm_print(lmm_system_t sys) XBT_DEBUG("'%d'(%f) : %f", var->id_int, var->weight, var->value); } } - - xbt_strbuff_free(buf); } void lmm_solve(lmm_system_t sys) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index b939c622c2..ef4864e0ae 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -38,6 +38,13 @@ simgrid::xbt::signal on_cluster; } } +// FIXME: The following duplicates the content of s4u::Host +namespace simgrid { +namespace s4u { +extern std::map host_list; +} +} + static int surf_parse_models_setup_already_called = 0; /** The current AS in the parsing */ @@ -450,26 +457,19 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) sg_host_t host = sg_host_by_name(process->host); if (!host) { // The requested host does not exist. Do a nice message to the user - char* tmp = bprintf("Cannot create process '%s': host '%s' does not exist\nExisting hosts: '", process->function, - process->host); - xbt_strbuff_t msg = xbt_strbuff_new_from(tmp); - free(tmp); - xbt_dynar_t all_hosts = xbt_dynar_sort_strings(sg_hosts_as_dynar()); - simgrid::s4u::Host* host; - unsigned int cursor; - xbt_dynar_foreach(all_hosts,cursor, host) { - xbt_strbuff_append(msg, host->cname()); - xbt_strbuff_append(msg,"', '"); - if (msg->used > 1024) { - msg->data[msg->used-3]='\0'; - msg->used -= 3; - - xbt_strbuff_append(msg," ...(list truncated)......");// That will be shortened by 3 chars when existing the loop + std::string msg = std::string("Cannot create process '") + process->function + "': host '" + process->host + + "' does not exist\nExisting hosts: '"; + for (auto kv : simgrid::s4u::host_list) { + simgrid::s4u::Host* host = kv.second; + msg += host->name(); + msg += "', '"; + if (msg.length() > 1024) { + msg.pop_back(); // remove trailing quote + msg += "...(list truncated)......"; break; } } - msg->data[msg->used-3]='\0'; - xbt_die("%s", msg->data); + xbt_die("%s", msg.c_str()); } simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(process->function); xbt_assert(factory, "Function '%s' unknown", process->function);