X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/43f7ca1cac5ab1858e318fdd6239d0a0c3b3d893..ea74f5d95928a521a588737e81f1de94eef25d19:/src/smpi/mpi/smpi_info.cpp?ds=sidebyside diff --git a/src/smpi/mpi/smpi_info.cpp b/src/smpi/mpi/smpi_info.cpp index 093da595f1..9dbfa70f2a 100644 --- a/src/smpi/mpi/smpi_info.cpp +++ b/src/smpi/mpi/smpi_info.cpp @@ -1,85 +1,69 @@ -/* Copyright (c) 2007-2017. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2022. 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 "xbt/ex.hpp" -#include "xbt/sysdep.h" +#include "smpi_comm.hpp" +#include "simgrid/Exception.hpp" -namespace simgrid{ -namespace smpi{ +namespace simgrid { +namespace smpi { -Info::Info():refcount_(1){ - dict_= xbt_dict_new_homogeneous(xbt_free_f); +Info::Info(const Info* orig) +{ + if (orig != nullptr) + map_ = orig->map_; + this->add_f(); } -Info::Info(Info* info):refcount_(1){ - dict_= xbt_dict_new_homogeneous(xbt_free_f); - xbt_dict_cursor_t cursor = nullptr; - char* key; - void* data; - xbt_dict_foreach(info->dict_,cursor,key,data){ - xbt_dict_set(dict_, key, xbt_strdup(static_cast(data)), nullptr); - } -} - -Info::~Info(){ - xbt_dict_free(&dict_); -} - -void Info::ref(){ +void Info::ref() +{ refcount_++; } void Info::unref(Info* info){ info->refcount_--; if(info->refcount_==0){ + F2C::free_f(info->f2c_id()); delete info; } } -void Info::set(char *key, char *value){ - xbt_dict_set(dict_, key, xbt_strdup(value), nullptr); -} - -int Info::get(char *key, int valuelen, char *value, int *flag){ +int Info::get(const char* key, int valuelen, char* value, int* flag) const +{ *flag=false; - char* tmpvalue=static_cast(xbt_dict_get_or_null(dict_, key)); - if(tmpvalue){ + auto val = map_.find(key); + if (val != map_.end()) { + std::string tmpvalue = val->second; + memset(value, 0, valuelen); - memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast(valuelen)) ? strlen(tmpvalue) + 1 : valuelen); + memcpy(value, tmpvalue.c_str(), + (tmpvalue.length() + 1 < static_cast(valuelen)) ? tmpvalue.length() + 1 : valuelen); *flag=true; } return MPI_SUCCESS; } - -int Info::remove(char *key){ - try { - xbt_dict_remove(dict_, key); - } - catch(xbt_ex& e){ +int Info::remove(const char *key){ + if (map_.erase(key) == 0) return MPI_ERR_INFO_NOKEY; - } - return MPI_SUCCESS; + else + return MPI_SUCCESS; } -int Info::get_nkeys(int *nkeys){ - *nkeys=xbt_dict_size(dict_); +int Info::get_nkeys(int* nkeys) const +{ + *nkeys = map_.size(); return MPI_SUCCESS; } -int Info::get_nthkey(int n, char *key){ - xbt_dict_cursor_t cursor = nullptr; - char *keyn; - void* data; +int Info::get_nthkey(int n, char* key) const +{ int num=0; - xbt_dict_foreach(dict_,cursor,keyn,data){ - if(num==n){ - strncpy(key,keyn,strlen(keyn)+1); - xbt_dict_cursor_free(&cursor); + for (auto const& elm : map_) { + if (num == n) { + strncpy(key, elm.first.c_str(), elm.first.length() + 1); return MPI_SUCCESS; } num++; @@ -87,11 +71,12 @@ int Info::get_nthkey(int n, char *key){ return MPI_ERR_ARG; } -int Info::get_valuelen(char *key, int *valuelen, int *flag){ +int Info::get_valuelen(const char* key, int* valuelen, int* flag) const +{ *flag=false; - char* tmpvalue=static_cast(xbt_dict_get_or_null(dict_, key)); - if(tmpvalue){ - *valuelen=strlen(tmpvalue); + auto val = map_.find(key); + if (val != map_.end()) { + *valuelen = val->second.length(); *flag=true; } return MPI_SUCCESS; @@ -103,4 +88,3 @@ Info* Info::f2c(int id){ } } -