xbt_die("Exiting now");
}
}
+
void surf_parse_error(std::string msg)
{
int lineno = surf_parse_lineno;
xbt_die("Exiting now");
}
-void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post)
+void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
{
- if (sg_netpoint_by_name_or_null(hostname) != nullptr) // found
+ if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
return;
- std::string msg = std::string(pre);
- msg += hostname;
- msg += post;
- msg += " Existing netpoints: \n";
+ std::string msg = pre + hostname + post + " Existing netpoints: \n";
std::vector<simgrid::kernel::routing::NetPoint*> list;
simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
surf_parse_error(msg);
}
-void surf_parse_warn(const char *fmt, ...) {
- va_list va;
- va_start(va,fmt);
- char *msg = bvprintf(fmt,va);
- va_end(va);
- XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
- free(msg);
+void surf_parse_warn(std::string msg)
+{
+ XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg.c_str());
}
-double surf_parse_get_double(const char *string) {
- double res;
- int ret = sscanf(string, "%lg", &res);
- if (ret != 1)
- surf_parse_error(std::string(string) + " is not a double");
- return res;
+double surf_parse_get_double(std::string s)
+{
+ try {
+ return std::stod(s);
+ } catch (std::invalid_argument& ia) {
+ surf_parse_error(s + " is not a double");
+ return -1;
+ }
}
-int surf_parse_get_int(const char *string) {
- int res;
- int ret = sscanf(string, "%d", &res);
- if (ret != 1)
- surf_parse_error(std::string(string) + " is not an integer");
- return res;
+int surf_parse_get_int(std::string s)
+{
+ try {
+ return std::stoi(s);
+ } catch (std::invalid_argument& ia) {
+ surf_parse_error(s + " is not a double");
+ return -1;
+ }
}
/* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
-static std::vector<int>* explodesRadical(const char* radicals)
+static std::vector<int>* explodesRadical(std::string radicals)
{
std::vector<int>* exploded = new std::vector<int>();
for (auto group : radical_elements) {
std::vector<std::string> radical_ends;
boost::split(radical_ends, group, boost::is_any_of("-"));
- int start = surf_parse_get_int((radical_ends.front()).c_str());
- int end = 0;
+ int start = surf_parse_get_int(radical_ends.front());
+ int end = 0;
switch (radical_ends.size()) {
case 1:
end = start;
break;
case 2:
- end = surf_parse_get_int((radical_ends.back()).c_str());
+ end = surf_parse_get_int(radical_ends.back());
break;
default:
surf_parse_error(std::string("Malformed radical: ") + group);
};
/* Note: field `unit' for the last element of parameter `units' should be nullptr. */
-static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units,
- const char *entity_kind, const char *name, const char *error_msg, const char *default_unit)
+static double surf_parse_get_value_with_unit(const char* string, const struct unit_scale* units,
+ const char* entity_kind, std::string name, const char* error_msg,
+ const char* default_unit)
{
char* ptr;
int i;
if (res == 0)
return res; // Ok, 0 can be unit-less
- XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg);
+ XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
ptr = (char*)default_unit;
}
for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
return res;
}
-double surf_parse_get_time(const char *string, const char *entity_kind, const char *name)
+double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
{
const struct unit_scale units[] = {
{ "w", 7 * 24 * 60 * 60 },
"Append 's' to your time to get seconds", "s");
}
-double surf_parse_get_size(const char *string, const char *entity_kind, const char *name)
+double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
{
const struct unit_scale units[] = {
{ "EiB", pow(1024, 6) },
"Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
}
-double surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name)
+double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
{
const struct unit_scale units[] = {
{ "EiBps", pow(1024, 6) },
"Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
}
-double surf_parse_get_speed(const char *string, const char *entity_kind, const char *name)
+double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
{
const struct unit_scale units[] = {
{ "yottaflops", 1e24 },
"Append 'f' or 'flops' to your speed to get flop per second", "f");
}
-static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, const char* id){
+static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
+{
std::vector<double> speed_per_pstate;
void STag_surfxml_host___link(){
XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
- s_sg_platf_host_link_cbarg_t host_link;
- memset(&host_link,0,sizeof(host_link));
+ HostLinkCreationArgs host_link;
host_link.id = A_surfxml_host___link_id;
host_link.link_up = A_surfxml_host___link_up;
}
void ETag_surfxml_cluster(){
- s_sg_platf_cluster_cbarg_t cluster;
- memset(&cluster,0,sizeof(cluster));
- cluster.properties = current_property_set;
+ ClusterCreationArgs cluster;
+ cluster.properties = current_property_set;
current_property_set = nullptr;
cluster.id = A_surfxml_cluster_id;
{
parse_after_config();
TraceConnectCreationArgs trace_connect;
- memset(&trace_connect,0,sizeof(trace_connect));
trace_connect.element = A_surfxml_trace___connect_element;
trace_connect.trace = A_surfxml_trace___connect_trace;
void STag_surfxml_config()
{
ZONE_TAG = 0;
- xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
+ xbt_assert(current_property_set == nullptr,
+ "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
if (_sg_cfg_init_status == 2) {
surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
AX_surfxml_actor_function = AX_surfxml_process_function;
STag_surfxml_actor();
}
+
void STag_surfxml_actor()
{
ZONE_TAG = 0;
AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
ETag_surfxml_actor();
}
+
void ETag_surfxml_actor()
{
s_sg_platf_process_cbarg_t actor;
if (not current_model_property_set)
current_model_property_set = new std::map<std::string, std::string>();
- current_model_property_set->insert(
- {std::string(A_surfxml_model___prop_id), std::string(A_surfxml_model___prop_value)});
+ current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
}
void ETag_surfxml_prop(){/* Nothing to do */}