From: Frederic Suter Date: Mon, 22 May 2017 19:38:18 +0000 (+0200) Subject: a vector of keyval structs is a map X-Git-Tag: v3.16~271 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4f423a58620da6a25058aa753c98a25f56ee05c9?hp=9a8e2f5bce8c6758d4367d21a66466a497d136fe;ds=sidebyside a vector of keyval structs is a map --- diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 85a859b018..785942d6b8 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -106,28 +106,13 @@ HostImpl::HostImpl(s4u::Host* host) : piface_(host) piface_->pimpl_ = this; } -/** @brief use destroy() instead of this destructor */ -HostImpl::~HostImpl() -{ - for (auto mnt : storage_) - xbt_free(mnt.name); -} - simgrid::surf::Storage* HostImpl::findStorageOnMountList(const char* mount) { - simgrid::surf::Storage* st = nullptr; - XBT_DEBUG("Search for storage name '%s' on '%s'", mount, piface_->cname()); - for (auto mnt : storage_) { - XBT_DEBUG("See '%s'", mnt.name); - if (!strcmp(mount, mnt.name)) { - st = static_cast(mnt.storage); - break; - } - } - if (!st) + if (storage_.find(mount) == storage_.end()) xbt_die("Can't find mount '%s' for '%s'", mount, piface_->cname()); - return st; + + return storage_.at(mount); } xbt_dict_t HostImpl::getMountedStorageList() @@ -136,8 +121,8 @@ xbt_dict_t HostImpl::getMountedStorageList() char* storage_name = nullptr; for (auto mnt : storage_) { - storage_name = (char*)static_cast(mnt.storage)->cname(); - xbt_dict_set(storage_list, mnt.name, storage_name, nullptr); + storage_name = (char*)mnt.second->cname(); + xbt_dict_set(storage_list, mnt.first.c_str(), storage_name, nullptr); } return storage_list; } @@ -168,14 +153,13 @@ Action* HostImpl::open(const char* fullpath) XBT_DEBUG("Search for storage name for '%s' on '%s'", fullpath, piface_->cname()); for (auto mnt : storage_) { - XBT_DEBUG("See '%s'", mnt.name); - std::string file_mount_name = std::string(fullpath).substr(0, strlen(mnt.name)); - - if (!strcmp(file_mount_name.c_str(), mnt.name) && - strlen(mnt.name) > longest_prefix_length) { /* The current mount name is found in the full path and is - bigger than the previous*/ - longest_prefix_length = strlen(mnt.name); - st = static_cast(mnt.storage); + XBT_DEBUG("See '%s'", mnt.first.c_str()); + std::string file_mount_name = std::string(fullpath).substr(0, mnt.first.size()); + + if (file_mount_name == mnt.first && mnt.first.length() > longest_prefix_length) { + /* The current mount name is found in the full path and is bigger than the previous*/ + longest_prefix_length = mnt.first.length(); + st = mnt.second; } } if (longest_prefix_length > 0) { /* Mount point found, split fullpath into mount_name and path+filename*/ diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 6180248601..12287e32f0 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -64,7 +64,7 @@ class HostImpl : public simgrid::surf::PropertyHolder { public: explicit HostImpl(s4u::Host* host); - virtual ~HostImpl(); + virtual ~HostImpl() = default; /** @brief Return the storage of corresponding mount point */ virtual simgrid::surf::Storage* findStorageOnMountList(const char* storage); @@ -173,7 +173,7 @@ public: */ virtual int fileMove(surf_file_t fd, const char* fullpath); - std::vector storage_; + std::map storage_; simgrid::s4u::Host* piface_ = nullptr; simgrid::s4u::Host* getHost() { return piface_; } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 6c0cbf4461..b40d4abe43 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -28,7 +28,7 @@ #include XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); -XBT_PRIVATE std::vector mount_list; +XBT_PRIVATE std::map mount_list; namespace simgrid { namespace surf { @@ -427,13 +427,10 @@ void sg_platf_new_mount(sg_platf_mount_cbarg_t mount){ XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name); - s_mount_t mnt; - mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId)); - mnt.name = xbt_strdup(mount->name); - if (mount_list.empty()) XBT_DEBUG("Create a Mount list for %s", A_surfxml_host_id); - mount_list.push_back(mnt); + mount_list.insert( + {std::string(mount->name), surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId))}); } void sg_platf_new_route(sg_platf_route_cbarg_t route) diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index 31c6dc8c72..32fa00ffc6 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -233,12 +233,6 @@ typedef struct s_storage_type { } s_storage_type_t; typedef s_storage_type_t* storage_type_t; -typedef struct s_mount { - void *storage; - char *name; -} s_mount_t; -typedef s_mount_t* mount_t; - typedef struct surf_file { char *name; char *mount;