From: Martin Quinson Date: Mon, 24 Jul 2017 19:57:48 +0000 (+0200) Subject: Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid X-Git-Tag: v3_17~322^2~6 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2ed355817f460966034abc6a78428bdca52fcbb4?hp=94830499b62007a733ec98986edb77432299682d Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid --- diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 2b4a84d6aa..148680148e 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -260,16 +260,20 @@ bool NetZoneImpl::getBypassRoute(routing::NetPoint* src, routing::NetPoint* dst, for (int i = 0; i < max; i++) { if (i <= max_index_src && max <= max_index_dst) { key = {path_src.at(i)->netpoint_, path_dst.at(max)->netpoint_}; - if (bypassRoutes_.find(key) != bypassRoutes_.end()) { + try { bypassedRoute = bypassRoutes_.at(key); break; + } catch (std::out_of_range& unfound) { + // Do nothing } } if (max <= max_index_src && i <= max_index_dst) { key = {path_src.at(max)->netpoint_, path_dst.at(i)->netpoint_}; - if (bypassRoutes_.find(key) != bypassRoutes_.end()) { + try { bypassedRoute = bypassRoutes_.at(key); break; + } catch (std::out_of_range& unfound) { + // Do nothing } } } @@ -279,9 +283,11 @@ bool NetZoneImpl::getBypassRoute(routing::NetPoint* src, routing::NetPoint* dst, if (max <= max_index_src && max <= max_index_dst) { key = {path_src.at(max)->netpoint_, path_dst.at(max)->netpoint_}; - if (bypassRoutes_.find(key) != bypassRoutes_.end()) { + try { bypassedRoute = bypassRoutes_.at(key); break; + } catch (std::out_of_range& unfound) { + // Do nothing } } } diff --git a/src/kernel/routing/VivaldiZone.cpp b/src/kernel/routing/VivaldiZone.cpp index ddc4b6d788..97849e0db1 100644 --- a/src/kernel/routing/VivaldiZone.cpp +++ b/src/kernel/routing/VivaldiZone.cpp @@ -20,7 +20,7 @@ namespace routing { namespace vivaldi { simgrid::xbt::Extension Coords::EXTENSION_ID; -Coords::Coords(NetPoint* netpoint, const char* coordStr) +Coords::Coords(NetPoint* netpoint, std::string coordStr) { if (not Coords::EXTENSION_ID.valid()) Coords::EXTENSION_ID = NetPoint::extension_create(); @@ -30,13 +30,16 @@ Coords::Coords(NetPoint* netpoint, const char* coordStr) xbt_assert(string_values.size() == 3, "Coordinates of %s must have 3 dimensions", netpoint->cname()); for (auto str : string_values) - coords.push_back(xbt_str_parse_double(str.c_str(), "Invalid coordinate: %s")); + try { + coords.push_back(std::stod(str)); + } catch (std::invalid_argument const& ia) { + throw std::invalid_argument(std::string("Invalid coordinate: ") + ia.what()); + } coords.shrink_to_fit(); netpoint->extension_set(this); - XBT_DEBUG("Coords of %s %p: %s", netpoint->cname(), netpoint, coordStr); + XBT_DEBUG("Coords of %s %p: %s", netpoint->cname(), netpoint, coordStr.c_str()); } -Coords::~Coords() = default; }; // namespace vivaldi static inline double euclidean_dist_comp(int index, std::vector* src, std::vector* dst) @@ -58,7 +61,7 @@ VivaldiZone::VivaldiZone(NetZone* father, const char* name) : ClusterZone(father { } -void VivaldiZone::setPeerLink(NetPoint* netpoint, double bw_in, double bw_out, const char* coord) +void VivaldiZone::setPeerLink(NetPoint* netpoint, double bw_in, double bw_out, std::string coord) { xbt_assert(netpoint->netzone() == this, "Cannot add a peer link to a netpoint that is not in this netzone"); @@ -83,21 +86,26 @@ void VivaldiZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cba } /* Retrieve the private links */ - if (privateLinks_.find(src->id()) != privateLinks_.end()) { + try { std::pair info = privateLinks_.at(src->id()); if (info.first) { route->link_list->push_back(info.first); if (lat) *lat += info.first->latency(); } + } catch (std::out_of_range& unfound) { + XBT_DEBUG("Source of private link (%u) doesn't exist", src->id()); } - if (privateLinks_.find(dst->id()) != privateLinks_.end()) { + + try { std::pair info = privateLinks_.at(dst->id()); if (info.second) { route->link_list->push_back(info.second); if (lat) *lat += info.second->latency(); } + } catch (std::out_of_range& unfound) { + XBT_DEBUG("Destination of private link (%u) doesn't exist", dst->id()); } /* Compute the extra latency due to the euclidean distance if needed */ diff --git a/src/kernel/routing/VivaldiZone.hpp b/src/kernel/routing/VivaldiZone.hpp index 9b7c9ffb00..83fc6b24e1 100644 --- a/src/kernel/routing/VivaldiZone.hpp +++ b/src/kernel/routing/VivaldiZone.hpp @@ -47,7 +47,7 @@ class XBT_PRIVATE VivaldiZone : public ClusterZone { public: explicit VivaldiZone(NetZone* father, const char* name); - void setPeerLink(NetPoint* netpoint, double bw_in, double bw_out, const char* coord); + void setPeerLink(NetPoint* netpoint, double bw_in, double bw_out, std::string coord); void getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t into, double* latency) override; }; @@ -55,8 +55,8 @@ namespace vivaldi { class XBT_PRIVATE Coords { public: static simgrid::xbt::Extension EXTENSION_ID; - explicit Coords(NetPoint* host, const char* str); - virtual ~Coords(); + explicit Coords(NetPoint* host, std::string str); + virtual ~Coords() = default; std::vector coords; }; diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index 0e983e8ffe..8df13cd410 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -128,9 +128,11 @@ NetZone* Engine::getNetzoneByNameOrNull(const char* name) /** @brief Retrieve the netpoint of the given name (or nullptr if not found) */ simgrid::kernel::routing::NetPoint* Engine::getNetpointByNameOrNull(const char* name) { - if (pimpl->netpoints_.find(name) == pimpl->netpoints_.end()) + try { + return pimpl->netpoints_.at(name); + } catch (std::out_of_range& unfound) { return nullptr; - return pimpl->netpoints_.at(name); + } } /** @brief Fill the provided vector with all existing netpoints */ void Engine::getNetpointList(std::vector* list) diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index a1520f952b..f39b2a2969 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -87,9 +87,11 @@ Host* Host::by_name_or_null(const char* name) } Host* Host::by_name_or_null(std::string name) { - if (host_list.find(name) == host_list.end()) + try { + return host_list.at(name); + } catch (std::out_of_range& unfound) { return nullptr; - return host_list.at(name); + } } Host *Host::current(){ diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 25902cea16..d9b877d4ad 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -823,9 +823,11 @@ xbt_dynar_t SIMIX_process_get_runnable() /** @brief Returns the process from PID. */ smx_actor_t SIMIX_process_from_PID(aid_t PID) { - if (simix_global->process_list.find(PID) == simix_global->process_list.end()) + try { + return simix_global->process_list.at(PID); + } catch (std::out_of_range& unfound) { return nullptr; - return simix_global->process_list.at(PID); + } } /** @brief returns a dynar containing all currently existing processes */ diff --git a/src/smpi/mpi/smpi_group.cpp b/src/smpi/mpi/smpi_group.cpp index 89abd06941..bce418b066 100644 --- a/src/smpi/mpi/smpi_group.cpp +++ b/src/smpi/mpi/smpi_group.cpp @@ -73,10 +73,11 @@ int Group::rank(int index) { if (this == MPI_GROUP_EMPTY) return MPI_UNDEFINED; - if (index_to_rank_map_.find(index) == index_to_rank_map_.end()) - return MPI_UNDEFINED; - else + try { return index_to_rank_map_.at(index); + } catch (std::out_of_range& unfound) { + return MPI_UNDEFINED; + } } void Group::ref() diff --git a/src/surf/FileImpl.cpp b/src/surf/FileImpl.cpp index 53548500a5..e454c3a073 100644 --- a/src/surf/FileImpl.cpp +++ b/src/surf/FileImpl.cpp @@ -17,9 +17,9 @@ FileImpl::FileImpl(sg_storage_t st, std::string path, std::string mount) : path_ location_ = st->getImpl(); std::map* content = location_->getContent(); // if file does not exist create an empty file - if (content->find(path) != content->end()) + try { size_ = content->at(path); - else { + } catch (std::out_of_range& unfound) { size_ = 0; content->insert({path, size_}); XBT_DEBUG("File '%s' was not found, file created.", path.c_str()); @@ -96,13 +96,13 @@ void FileImpl::move(const char* fullpath) /* Check if the new full path is on the same mount point */ if (not strncmp(mount_point_.c_str(), fullpath, mount_point_.size())) { std::map* content = location_->getContent(); - if (content->find(path_) != content->end()) { // src file exists + try { // src file exists sg_size_t new_size = content->at(path_); content->erase(path_); std::string path = std::string(fullpath).substr(mount_point_.size(), strlen(fullpath)); content->insert({path.c_str(), new_size}); XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath, new_size); - } else { + } catch (std::out_of_range& unfound) { XBT_WARN("File %s doesn't exist", path_.c_str()); } } else { diff --git a/src/surf/StorageImpl.cpp b/src/surf/StorageImpl.cpp index 03e1f87329..b162a6e2e9 100644 --- a/src/surf/StorageImpl.cpp +++ b/src/surf/StorageImpl.cpp @@ -58,9 +58,9 @@ StorageModel::~StorageModel() * Resource * ************/ -StorageImpl::StorageImpl(Model* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite, - const char* type_id, const char* content_name, sg_size_t size, const char* attach) - : Resource(model, name, lmm_constraint_new(maxminSystem, this, MAX(bread, bwrite))) +StorageImpl::StorageImpl(Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite, + std::string type_id, std::string content_name, sg_size_t size, std::string attach) + : Resource(model, name.c_str(), lmm_constraint_new(maxminSystem, this, MAX(bread, bwrite))) , piface_(this) , typeId_(type_id) , size_(size) @@ -81,15 +81,15 @@ StorageImpl::~StorageImpl() delete content_; } -std::map* StorageImpl::parseContent(const char* filename) +std::map* StorageImpl::parseContent(std::string filename) { usedSize_ = 0; - if ((not filename) || (strcmp(filename, "") == 0)) + if (filename.empty()) return nullptr; std::map* parse_content = new std::map(); - std::ifstream* fs = surf_ifsopen(filename); + std::ifstream* fs = surf_ifsopen(filename.c_str()); std::string line; std::vector tokens; @@ -98,7 +98,7 @@ std::map* StorageImpl::parseContent(const char* filename boost::trim(line); if (line.length() > 0) { boost::split(tokens, line, boost::is_any_of(" \t"), boost::token_compress_on); - xbt_assert(tokens.size() == 2, "Parse error in %s: %s", filename, line.c_str()); + xbt_assert(tokens.size() == 2, "Parse error in %s: %s", filename.c_str(), line.c_str()); sg_size_t size = std::stoull(tokens.at(1)); usedSize_ += size; diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index 186fd7c160..9f410d35cf 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -68,8 +68,8 @@ public: StorageModel(); ~StorageModel(); - virtual StorageImpl* createStorage(const char* id, const char* type_id, const char* content_name, - const char* attach) = 0; + virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name, + std::string attach) = 0; std::vector p_storageList; }; @@ -84,8 +84,8 @@ public: class StorageImpl : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder { public: /** @brief Storage constructor */ - StorageImpl(Model* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite, - const char* type_id, const char* content_name, sg_size_t size, const char* attach); + StorageImpl(Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite, + std::string type_id, std::string content_name, sg_size_t size, std::string attach); ~StorageImpl() override; @@ -140,7 +140,7 @@ public: virtual sg_size_t getSize() { return size_; } virtual std::string getHost() { return attach_; } - std::map* parseContent(const char* filename); + std::map* parseContent(std::string filename); static std::unordered_map* storagesMap() { return StorageImpl::storages; } lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/ diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 81c55be208..fdb99fcd11 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -22,9 +22,11 @@ namespace simgrid { LinkImpl* LinkImpl::byName(const char* name) { - if (links->find(name) == links->end()) + try { + return links->at(name); + } catch (std::out_of_range& unfound) { return nullptr; - return links->at(name); + } } /** @brief Returns the amount of links in the platform */ int LinkImpl::linksCount() diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index e3760856f0..236c577704 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -359,29 +359,33 @@ void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet) delete cabinet->radicals; } -void sg_platf_new_storage(sg_platf_storage_cbarg_t storage) +void sg_platf_new_storage(StorageCreationArgs* storage) { xbt_assert(std::find(known_storages.begin(), known_storages.end(), storage->id) == known_storages.end(), - "Refusing to add a second storage named \"%s\"", storage->id); + "Refusing to add a second storage named \"%s\"", storage->id.c_str()); - xbt_assert(storage_types.find(storage->type_id) != storage_types.end(), "No storage type '%s'", storage->type_id); - storage_type_t stype = storage_types.at(storage->type_id); + storage_type_t stype; + try { + stype = storage_types.at(storage->type_id); + } catch (std::out_of_range& unfound) { + xbt_die("No storage type '%s'", storage->type_id.c_str()); + } - XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'", storage->id, storage->type_id, - storage->content); + XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'", storage->id.c_str(), + storage->type_id.c_str(), storage->content.c_str()); known_storages.push_back(storage->id); // if storage content is not specified use the content of storage_type if any - if (not strcmp(storage->content, "") && strcmp(stype->content, "")) { - storage->content = stype->content; - XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s)", storage->id, stype->type_id); + if (storage->content.empty() && strcmp(stype->content, "")) { + storage->content = std::string(stype->content); + XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s)", storage->id.c_str(), stype->type_id); } XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' " "\n\t\tmodel '%s' \n\t\tcontent '%s' " "\n\t\tproperties '%p''\n", - storage->id, stype->model, stype->type_id, storage->content, storage->properties); + storage->id.c_str(), stype->model, stype->type_id, storage->content.c_str(), storage->properties); auto s = surf_storage_model->createStorage(storage->id, stype->type_id, storage->content, storage->attach); @@ -408,21 +412,22 @@ void sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type) stype->size = storage_type->size; stype->model_properties = storage_type->model_properties; - XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', content '%s'", stype->type_id, stype->model, + XBT_DEBUG("Create a storage type id '%s' with model '%s', content '%s'", stype->type_id, stype->model, storage_type->content); storage_types.insert({std::string(stype->type_id), stype}); } -void sg_platf_new_mount(sg_platf_mount_cbarg_t mount){ +void sg_platf_new_mount(MountCreationArgs* mount) +{ xbt_assert(std::find(known_storages.begin(), known_storages.end(), mount->storageId) != known_storages.end(), - "Cannot mount non-existent disk \"%s\"", mount->storageId); + "Cannot mount non-existent disk \"%s\"", mount->storageId.c_str()); - XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name); + XBT_DEBUG("Mount '%s' on '%s'", mount->storageId.c_str(), mount->name.c_str()); if (mount_list.empty()) XBT_DEBUG("Create a Mount list for %s", A_surfxml_host_id); - mount_list.insert({std::string(mount->name), simgrid::surf::StorageImpl::byName(mount->storageId)}); + mount_list.insert({mount->name, simgrid::surf::StorageImpl::byName(mount->storageId.c_str())}); } void sg_platf_new_route(sg_platf_route_cbarg_t route) @@ -513,14 +518,14 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) current_property_set = nullptr; } -void sg_platf_new_peer(sg_platf_peer_cbarg_t peer) +void sg_platf_new_peer(PeerCreationArgs* peer) { simgrid::kernel::routing::VivaldiZone* as = dynamic_cast(current_routing); xbt_assert(as, " tag can only be used in Vivaldi netzones."); std::vector speedPerPstate; speedPerPstate.push_back(peer->speed); - simgrid::s4u::Host* host = as->createHost(peer->id, &speedPerPstate, 1, nullptr); + simgrid::s4u::Host* host = as->createHost(peer->id.c_str(), &speedPerPstate, 1, nullptr); as->setPeerLink(host->pimpl_netpoint, peer->bw_in, peer->bw_out, peer->coord); diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index dd44583307..5131db9a76 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -46,21 +46,22 @@ void surf_storage_model_init_default() namespace simgrid { namespace surf { -StorageImpl* StorageN11Model::createStorage(const char* id, const char* type_id, const char* content_name, - const char* attach) +StorageImpl* StorageN11Model::createStorage(std::string id, std::string type_id, std::string content_name, + std::string attach) { storage_type_t storage_type = storage_types.at(type_id); - double Bread = - surf_parse_get_bandwidth(storage_type->model_properties->at("Bread").c_str(), "property Bread, storage", type_id); + double Bread = surf_parse_get_bandwidth(storage_type->model_properties->at("Bread").c_str(), + "property Bread, storage", type_id.c_str()); double Bwrite = surf_parse_get_bandwidth(storage_type->model_properties->at("Bwrite").c_str(), - "property Bwrite, storage", type_id); + "property Bwrite, storage", type_id.c_str()); - StorageImpl* storage = new StorageN11(this, id, maxminSystem_, Bread, Bwrite, type_id, (char*)content_name, - storage_type->size, (char*)attach); + StorageImpl* storage = + new StorageN11(this, id, maxminSystem_, Bread, Bwrite, type_id, content_name, storage_type->size, attach); storageCreatedCallbacks(storage); - XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tBread '%f'\n", id, type_id, Bread); + XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tBread '%f'\n", id.c_str(), type_id.c_str(), + Bread); p_storageList.push_back(storage); @@ -111,8 +112,8 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) * Resource * ************/ -StorageN11::StorageN11(StorageModel* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite, - const char* type_id, char* content_name, sg_size_t size, char* attach) +StorageN11::StorageN11(StorageModel* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite, + std::string type_id, std::string content_name, sg_size_t size, std::string attach) : StorageImpl(model, name, maxminSystem, bread, bwrite, type_id, content_name, size, attach) { XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size); diff --git a/src/surf/storage_n11.hpp b/src/surf/storage_n11.hpp index 42793eb325..5e3ff38b4e 100644 --- a/src/surf/storage_n11.hpp +++ b/src/surf/storage_n11.hpp @@ -29,8 +29,8 @@ class XBT_PRIVATE StorageN11Action; class StorageN11Model : public StorageModel { public: - StorageImpl* createStorage(const char* id, const char* type_id, const char* content_name, - const char* attach) override; + StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name, + std::string attach) override; double nextOccuringEvent(double now) override; void updateActionsState(double now, double delta) override; }; @@ -41,8 +41,8 @@ public: class StorageN11 : public StorageImpl { public: - StorageN11(StorageModel* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite, - const char* type_id, char* content_name, sg_size_t size, char* attach); + StorageN11(StorageModel* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite, + std::string type_id, std::string content_name, sg_size_t size, std::string attach); virtual ~StorageN11() = default; StorageAction* read(sg_size_t size); StorageAction* write(sg_size_t size); diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index d6b4dd88d0..1989a471a9 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -72,16 +72,16 @@ public: xbt_dict_t properties = nullptr; }; -typedef struct s_sg_platf_peer_cbarg *sg_platf_peer_cbarg_t; -typedef struct s_sg_platf_peer_cbarg { - const char* id; +class PeerCreationArgs { +public: + std::string id; double speed; double bw_in; double bw_out; - const char* coord; + std::string coord; tmgr_trace_t speed_trace; tmgr_trace_t state_trace; -} s_sg_platf_peer_cbarg_t; +}; typedef struct s_sg_platf_route_cbarg *sg_platf_route_cbarg_t; typedef struct s_sg_platf_route_cbarg { @@ -127,14 +127,14 @@ typedef struct s_sg_platf_cabinet_cbarg { double lat; } s_sg_platf_cabinet_cbarg_t; -typedef struct s_sg_platf_storage_cbarg* sg_platf_storage_cbarg_t; -typedef struct s_sg_platf_storage_cbarg { - const char* id; - const char* type_id; - const char* content; +class StorageCreationArgs { +public: + std::string id; + std::string type_id; + std::string content; xbt_dict_t properties; - const char* attach; -} s_sg_platf_storage_cbarg_t; + std::string attach; +}; typedef struct s_sg_platf_storage_type_cbarg* sg_platf_storage_type_cbarg_t; typedef struct s_sg_platf_storage_type_cbarg { @@ -146,11 +146,11 @@ typedef struct s_sg_platf_storage_type_cbarg { sg_size_t size; } s_sg_platf_storage_type_cbarg_t; -typedef struct s_sg_platf_mount_cbarg* sg_platf_mount_cbarg_t; -typedef struct s_sg_platf_mount_cbarg { - const char* storageId; - const char* name; -} s_sg_platf_mount_cbarg_t; +class MountCreationArgs { +public: + std::string storageId; + std::string name; +}; typedef struct s_sg_platf_prop_cbarg *sg_platf_prop_cbarg_t; typedef struct s_sg_platf_prop_cbarg { @@ -208,7 +208,7 @@ XBT_PUBLIC(void) sg_platf_new_hostlink(sg_platf_host_link_cbarg_t h); // Add an XBT_PUBLIC(simgrid::kernel::routing::NetPoint*) sg_platf_new_router(const char* name, const char* coords); // Add a router to the currently described AS XBT_PUBLIC(void) sg_platf_new_link(LinkCreationArgs* link); // Add a link to the currently described AS -XBT_PUBLIC(void) sg_platf_new_peer (sg_platf_peer_cbarg_t peer); // Add a peer to the currently described AS +XBT_PUBLIC(void) sg_platf_new_peer(PeerCreationArgs* peer); // Add a peer to the currently described AS XBT_PUBLIC(void) sg_platf_new_cluster(sg_platf_cluster_cbarg_t clust); // Add a cluster to the currently described AS XBT_PUBLIC(void) sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet); // Add a cabinet to the currently described AS @@ -217,9 +217,9 @@ XBT_PUBLIC(void) sg_platf_new_bypassRoute (sg_platf_route_cbarg_t bypassroute); XBT_PUBLIC(void) sg_platf_new_trace(sg_platf_trace_cbarg_t trace); -XBT_PUBLIC(void) sg_platf_new_storage(sg_platf_storage_cbarg_t storage); // Add a storage to the currently described AS +XBT_PUBLIC(void) sg_platf_new_storage(StorageCreationArgs* storage); // Add a storage to the currently described AS XBT_PUBLIC(void) sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type); -XBT_PUBLIC(void) sg_platf_new_mount(sg_platf_mount_cbarg_t mount); +XBT_PUBLIC(void) sg_platf_new_mount(MountCreationArgs* mount); XBT_PUBLIC(void) sg_platf_new_process(sg_platf_process_cbarg_t process); XBT_PRIVATE void sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index b82863ae0d..c348cd5346 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -329,19 +329,17 @@ xbt_dict_t random_data_list = nullptr; YY_BUFFER_STATE surf_input_buffer; FILE *surf_file_to_parse = nullptr; -/* - * Stuff relative to storage - */ +/* Stuff relative to storage */ void STag_surfxml_storage() { ZONE_TAG = 0; XBT_DEBUG("STag_surfxml_storage"); xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)"); } + void ETag_surfxml_storage() { - s_sg_platf_storage_cbarg_t storage; - memset(&storage,0,sizeof(storage)); + StorageCreationArgs storage; storage.properties = current_property_set; current_property_set = nullptr; @@ -349,8 +347,8 @@ void ETag_surfxml_storage() storage.id = A_surfxml_storage_id; storage.type_id = A_surfxml_storage_typeId; storage.content = A_surfxml_storage_content; - storage.attach = A_surfxml_storage_attach; + sg_platf_new_storage(&storage); } void STag_surfxml_storage___type() @@ -378,14 +376,15 @@ void ETag_surfxml_storage___type() "size of storage type", storage_type.id); sg_platf_new_storage_type(&storage_type); } + void STag_surfxml_mount() { XBT_DEBUG("STag_surfxml_mount"); } + void ETag_surfxml_mount() { - s_sg_platf_mount_cbarg_t mount; - memset(&mount,0,sizeof(mount)); + MountCreationArgs mount; mount.name = A_surfxml_mount_name; mount.storageId = A_surfxml_mount_storageId; @@ -666,12 +665,12 @@ void STag_surfxml_cabinet(){ void STag_surfxml_peer(){ parse_after_config(); - s_sg_platf_peer_cbarg_t peer; - memset(&peer,0,sizeof(peer)); - peer.id = A_surfxml_peer_id; - peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id); - peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id); - peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id); + PeerCreationArgs peer; + + peer.id = std::string(A_surfxml_peer_id); + peer.speed = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str()); + peer.bw_in = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str()); + peer.bw_out = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str()); peer.coord = A_surfxml_peer_coordinates; peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr; peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr; diff --git a/src/xbt/xbt_replay.cpp b/src/xbt/xbt_replay.cpp index b9b6612af1..74bc5a3f71 100644 --- a/src/xbt/xbt_replay.cpp +++ b/src/xbt/xbt_replay.cpp @@ -78,9 +78,9 @@ static ReplayAction* get_action(char* name) } else { // Else, I have to store it for the relevant colleague std::queue* otherqueue = nullptr; - if (action_queues.find(evtname) != action_queues.end()) + try { otherqueue = action_queues.at(evtname); - else { // Damn. Create the queue of that guy + } catch (std::out_of_range& unfound) { // Damn. Create the queue of that guy otherqueue = new std::queue(); action_queues.insert({evtname, otherqueue}); }