1 /* Copyright (c) 2007-2017. 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():refcount_(1){
15 dict_= xbt_dict_new_homogeneous(xbt_free_f);
18 Info::Info(Info* info):refcount_(1){
19 dict_= xbt_dict_new_homogeneous(xbt_free_f);
20 xbt_dict_cursor_t cursor = nullptr;
23 xbt_dict_foreach(info->dict_,cursor,key,data){
24 xbt_dict_set(dict_, key, xbt_strdup(static_cast<char*>(data)), nullptr);
29 xbt_dict_free(&dict_);
36 void Info::unref(Info* info){
38 if(info->refcount_==0){
43 void Info::set(char *key, char *value){
44 xbt_dict_set(dict_, key, xbt_strdup(value), nullptr);
47 int Info::get(char *key, int valuelen, char *value, int *flag){
49 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(dict_, key));
51 memset(value, 0, valuelen);
52 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
59 int Info::remove(char *key){
61 xbt_dict_remove(dict_, key);
64 return MPI_ERR_INFO_NOKEY;
69 int Info::get_nkeys(int *nkeys){
70 *nkeys=xbt_dict_size(dict_);
74 int Info::get_nthkey(int n, char *key){
75 xbt_dict_cursor_t cursor = nullptr;
79 xbt_dict_foreach(dict_,cursor,keyn,data){
81 strncpy(key,keyn,strlen(keyn)+1);
82 xbt_dict_cursor_free(&cursor);
90 int Info::get_valuelen(char *key, int *valuelen, int *flag){
92 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(dict_, key));
94 *valuelen=strlen(tmpvalue);
100 Info* Info::f2c(int id){
101 return static_cast<Info*>(F2C::f2c(id));