X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/84402e8e2ee2a2d0bef25fdceb0a263ed8b471f6..b2852b7c61948f495d7437ffaa7fd9aced12849c:/src/smpi/mpi/smpi_info.cpp diff --git a/src/smpi/mpi/smpi_info.cpp b/src/smpi/mpi/smpi_info.cpp index 564b22f4b5..0d696f4796 100644 --- a/src/smpi/mpi/smpi_info.cpp +++ b/src/smpi/mpi/smpi_info.cpp @@ -1,13 +1,20 @@ -/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */ /* 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. */ #include "smpi_info.hpp" +#include "smpi_comm.hpp" #include "simgrid/Exception.hpp" -namespace simgrid { -namespace smpi { +namespace simgrid::smpi { + +Info::Info(const Info* orig) +{ + if (orig != nullptr) + map_ = orig->map_; + this->add_f(); +} void Info::ref() { @@ -17,14 +24,15 @@ void Info::ref() void Info::unref(Info* info){ info->refcount_--; if(info->refcount_==0){ + F2C::free_f(info->f2c_id()); delete info; } } -int Info::get(const char *key, int valuelen, char *value, int *flag){ +int Info::get(const char* key, int valuelen, char* value, int* flag) const +{ *flag=false; - auto val = map_.find(key); - if (val != map_.end()) { + if (auto val = map_.find(key); val != map_.end()) { std::string tmpvalue = val->second; memset(value, 0, valuelen); @@ -42,16 +50,18 @@ int Info::remove(const char *key){ return MPI_SUCCESS; } -int Info::get_nkeys(int *nkeys){ +int Info::get_nkeys(int* nkeys) const +{ *nkeys = map_.size(); return MPI_SUCCESS; } -int Info::get_nthkey(int n, char *key){ +int Info::get_nthkey(int n, char* key) const +{ int num=0; - for (auto const& elm : map_) { + for (auto const& [elm, _] : map_) { if (num == n) { - strncpy(key, elm.first.c_str(), elm.first.length() + 1); + strncpy(key, elm.c_str(), elm.length() + 1); return MPI_SUCCESS; } num++; @@ -59,10 +69,10 @@ int Info::get_nthkey(int n, char *key){ return MPI_ERR_ARG; } -int Info::get_valuelen(const char *key, int *valuelen, int *flag){ +int Info::get_valuelen(const char* key, int* valuelen, int* flag) const +{ *flag=false; - auto val = map_.find(key); - if (val != map_.end()) { + if (auto val = map_.find(key); val != map_.end()) { *valuelen = val->second.length(); *flag=true; } @@ -73,5 +83,4 @@ Info* Info::f2c(int id){ return static_cast(F2C::f2c(id)); } -} -} +} // namespace simgrid::smpi