X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2cbb80e4efe5bef8a6d6d8a14f7a35729421e21c..08027d3c5a9bf1d0bef122b2a9a1f0b037fde9b6:/src/smpi/mpi/smpi_info.cpp diff --git a/src/smpi/mpi/smpi_info.cpp b/src/smpi/mpi/smpi_info.cpp index ff3c8535d8..73a323e7b9 100644 --- a/src/smpi/mpi/smpi_info.cpp +++ b/src/smpi/mpi/smpi_info.cpp @@ -1,21 +1,16 @@ -/* Copyright (c) 2007-2017. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2019. 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 "simgrid/Exception.hpp" -namespace simgrid{ -namespace smpi{ +namespace simgrid { +namespace smpi { -Info::Info(Info* info) : map_(info->map_) +void Info::ref() { -} - -void Info::ref(){ refcount_++; } @@ -26,26 +21,23 @@ void Info::unref(Info* info){ } } -void Info::set(char *key, char *value){ - map_[key] = value; -} - -int Info::get(char *key, int valuelen, char *value, int *flag){ +int Info::get(const char *key, int valuelen, char *value, int *flag){ *flag=false; - try { - std::string tmpvalue = map_.at(key); + auto val = map_.find(key); + if (val != map_.end()) { + std::string tmpvalue = val->second; memset(value, 0, valuelen); memcpy(value, tmpvalue.c_str(), (tmpvalue.length() + 1 < static_cast(valuelen)) ? tmpvalue.length() + 1 : valuelen); *flag=true; return MPI_SUCCESS; - } catch (std::out_of_range& unfound) { + } else { return MPI_ERR_INFO_KEY; } } -int Info::remove(char *key){ +int Info::remove(const char *key){ if (map_.erase(key) == 0) return MPI_ERR_INFO_NOKEY; else @@ -59,7 +51,7 @@ int Info::get_nkeys(int *nkeys){ int Info::get_nthkey(int n, char *key){ int num=0; - for (auto elm : map_) { + for (auto const& elm : map_) { if (num == n) { strncpy(key, elm.first.c_str(), elm.first.length() + 1); return MPI_SUCCESS; @@ -69,13 +61,14 @@ 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){ *flag=false; - try { - *valuelen = map_.at(key).length(); + auto val = map_.find(key); + if (val != map_.end()) { + *valuelen = val->second.length(); *flag=true; return MPI_SUCCESS; - } catch (std::out_of_range& unfound) { + } else { return MPI_ERR_INFO_KEY; } }