1 /* Copyright (c) 2007-2015. 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. */
14 MPI_Info Info::null_id_=MPI_INFO_NULL;
16 Info::Info():refcount_(1){
17 dict_= xbt_dict_new_homogeneous(xbt_free_f);
20 Info::Info(Info* info):refcount_(1){
21 dict_= xbt_dict_new_homogeneous(xbt_free_f);
22 xbt_dict_cursor_t cursor = nullptr;
25 xbt_dict_foreach(info->dict_,cursor,key,data){
26 xbt_dict_set(dict_, key, xbt_strdup(static_cast<char*>(data)), nullptr);
31 xbt_dict_free(&dict_);
34 void Info::ref(Info* info){
38 void Info::unref(Info* info){
40 if(info->refcount_==0){
45 void Info::set(char *key, char *value){
46 xbt_dict_set(dict_, key, xbt_strdup(value), nullptr);
51 int Info::get(char *key, int valuelen, char *value, int *flag){
53 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(dict_, key));
55 memset(value, 0, valuelen);
56 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
63 int Info::remove(char *key){
65 xbt_dict_remove(dict_, key);
68 return MPI_ERR_INFO_NOKEY;
73 int Info::get_nkeys(int *nkeys){
74 *nkeys=xbt_dict_size(dict_);
78 int Info::get_nthkey(int n, char *key){
79 xbt_dict_cursor_t cursor = nullptr;
83 xbt_dict_foreach(dict_,cursor,keyn,data){
85 strncpy(key,keyn,strlen(keyn)+1);
86 xbt_dict_cursor_free(&cursor);
94 int Info::get_valuelen(char *key, int *valuelen, int *flag){
96 char* tmpvalue=(char*)xbt_dict_get_or_null(dict_, key);
98 *valuelen=strlen(tmpvalue);