1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "smpi_info.hpp"
7 #include "simgrid/Exception.hpp"
12 Info::Info(Info* info) : map_(info->map_)
20 void Info::unref(Info* info){
22 if(info->refcount_==0){
27 void Info::set(char *key, char *value){
31 int Info::get(char *key, int valuelen, char *value, int *flag){
33 auto val = map_.find(key);
34 if (val != map_.end()) {
35 std::string tmpvalue = val->second;
37 memset(value, 0, valuelen);
38 memcpy(value, tmpvalue.c_str(),
39 (tmpvalue.length() + 1 < static_cast<size_t>(valuelen)) ? tmpvalue.length() + 1 : valuelen);
43 return MPI_ERR_INFO_KEY;
47 int Info::remove(char *key){
48 if (map_.erase(key) == 0)
49 return MPI_ERR_INFO_NOKEY;
54 int Info::get_nkeys(int *nkeys){
59 int Info::get_nthkey(int n, char *key){
61 for (auto const& elm : map_) {
63 strncpy(key, elm.first.c_str(), elm.first.length() + 1);
71 int Info::get_valuelen(char *key, int *valuelen, int *flag){
73 auto val = map_.find(key);
74 if (val != map_.end()) {
75 *valuelen = val->second.length();
79 return MPI_ERR_INFO_KEY;
83 Info* Info::f2c(int id){
84 return static_cast<Info*>(F2C::f2c(id));