1 /* Copyright (c) 2007-2018. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "smpi_info.hpp"
9 #include "xbt/sysdep.h"
14 Info::Info(Info* info) : map_(info->map_)
22 void Info::unref(Info* info){
24 if(info->refcount_==0){
29 void Info::set(char *key, char *value){
33 int Info::get(char *key, int valuelen, char *value, int *flag){
35 auto val = map_.find(key);
36 if (val != map_.end()) {
37 std::string tmpvalue = val->second;
39 memset(value, 0, valuelen);
40 memcpy(value, tmpvalue.c_str(),
41 (tmpvalue.length() + 1 < static_cast<size_t>(valuelen)) ? tmpvalue.length() + 1 : valuelen);
45 return MPI_ERR_INFO_KEY;
49 int Info::remove(char *key){
50 if (map_.erase(key) == 0)
51 return MPI_ERR_INFO_NOKEY;
56 int Info::get_nkeys(int *nkeys){
61 int Info::get_nthkey(int n, char *key){
63 for (auto const& elm : map_) {
65 strncpy(key, elm.first.c_str(), elm.first.length() + 1);
73 int Info::get_valuelen(char *key, int *valuelen, int *flag){
75 auto val = map_.find(key);
76 if (val != map_.end()) {
77 *valuelen = val->second.length();
81 return MPI_ERR_INFO_KEY;
85 Info* Info::f2c(int id){
86 return static_cast<Info*>(F2C::f2c(id));