1 /* Copyright (c) 2007-2023. 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 "smpi_comm.hpp"
8 #include "simgrid/Exception.hpp"
10 namespace simgrid::smpi {
12 Info::Info(const Info* orig)
24 void Info::unref(Info* info){
26 if(info->refcount_==0){
27 F2C::free_f(info->f2c_id());
32 int Info::get(const char* key, int valuelen, char* value, int* flag) const
35 if (auto val = map_.find(key); val != map_.end()) {
36 std::string tmpvalue = val->second;
38 memset(value, 0, valuelen);
39 memcpy(value, tmpvalue.c_str(),
40 (tmpvalue.length() + 1 < static_cast<size_t>(valuelen)) ? tmpvalue.length() + 1 : valuelen);
46 int Info::remove(const char *key){
47 if (map_.erase(key) == 0)
48 return MPI_ERR_INFO_NOKEY;
53 int Info::get_nkeys(int* nkeys) const
59 int Info::get_nthkey(int n, char* key) const
62 for (auto const& [elm, _] : map_) {
64 strncpy(key, elm.c_str(), elm.length() + 1);
72 int Info::get_valuelen(const char* key, int* valuelen, int* flag) const
75 if (auto val = map_.find(key); val != map_.end()) {
76 *valuelen = val->second.length();
82 Info* Info::f2c(int id){
83 return static_cast<Info*>(F2C::f2c(id));
86 } // namespace simgrid::smpi