if (not dimensions.empty()) {
/* We are in a torus cluster
- * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and safe it in a vector.
+ * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and save them into a vector.
* Additionally, we need to know how many ranks we have in total
*/
- for (auto group : dimensions) {
- dimensions_.push_back(surf_parse_get_int(group.c_str()));
- }
+ for (auto group : dimensions)
+ dimensions_.push_back(surf_parse_get_int(group));
linkCountPerNode_ = dimensions_.size();
}
unsigned int current_node = src->id();
unsigned int next_node = 0;
/*
- * Arrays that hold the coordinates of the current node and
- * the target; comparing the values at the i-th position of
- * both arrays, we can easily assess whether we need to route
- * into this dimension or not.
+ * Arrays that hold the coordinates of the current node andthe target; comparing the values at the i-th position of
+ * both arrays, we can easily assess whether we need to route into this dimension or not.
*/
unsigned int myCoords[4];
rankId_to_coords(src->id(), dimensions_, &myCoords);
unsigned int targetCoords[4];
rankId_to_coords(dst->id(), dimensions_, &targetCoords);
/*
- * linkOffset describes the offset where the link
- * we want to use is stored
- * (+1 is added because each node has a link from itself to itself,
- * which can only be the case if src->m_id == dst->m_id -- see above
- * for this special case)
+ * linkOffset describes the offset where the link we want to use is stored(+1 is added because each node has a link
+ * from itself to itself, which can only be the case if src->m_id == dst->m_id -- see above for this special case)
*/
int nodeOffset = (dimensions_.size() + 1) * src->id();
/* 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. */
-#ifndef SURF_SURFXML_PARSE_H
-#define SURF_SURFXML_PARSE_H
+#ifndef SURF_SURFXML_PARSE_HPP
+#define SURF_SURFXML_PARSE_HPP
-#include <xbt/function_types.h>
-#include <xbt/misc.h>
#include <xbt/signal.hpp>
SG_BEGIN_DECL()
XBT_PUBLIC(void) surf_parse_close();
XBT_PUBLIC(void) surf_parse_assert(bool cond, std::string msg);
XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(std::string msg);
-XBT_PUBLIC(void) surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post);
-XBT_PUBLIC(void) surf_parse_warn(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
+XBT_PUBLIC(void) surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post);
+XBT_PUBLIC(void) surf_parse_warn(std::string msg);
-XBT_PUBLIC(double) surf_parse_get_double(const char *string);
-XBT_PUBLIC(int) surf_parse_get_int(const char *string);
+XBT_PUBLIC(double) surf_parse_get_double(std::string s);
+XBT_PUBLIC(int) surf_parse_get_int(std::string s);
XBT_PUBLIC(double) surf_parse_get_time(const char *string, const char *entity_kind, const char *name);
XBT_PUBLIC(double) surf_parse_get_size(const char *string, const char *entity_kind, const char *name);
XBT_PUBLIC(double) surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name);
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);
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 */}