Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add MPI_Bsend, MPI_Ibsend, MPI_Bsend_init, MPI_Buffer_attach, MPI_Buffer_detach.
[simgrid.git] / src / smpi / mpi / smpi_info.cpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "smpi_info.hpp"
7 #include "simgrid/Exception.hpp"
8
9 namespace simgrid {
10 namespace smpi {
11
12 void Info::ref()
13 {
14   refcount_++;
15 }
16
17 void Info::unref(Info* info){
18   info->refcount_--;
19   if(info->refcount_==0){
20     delete info;
21   }
22 }
23
24 int Info::get(const char *key, int valuelen, char *value, int *flag){
25   *flag=false;
26   auto val = map_.find(key);
27   if (val != map_.end()) {
28     std::string tmpvalue = val->second;
29
30     memset(value, 0, valuelen);
31     memcpy(value, tmpvalue.c_str(),
32            (tmpvalue.length() + 1 < static_cast<size_t>(valuelen)) ? tmpvalue.length() + 1 : valuelen);
33     *flag=true;
34   }
35   return MPI_SUCCESS;
36 }
37
38 int Info::remove(const char *key){
39   if (map_.erase(key) == 0)
40     return MPI_ERR_INFO_NOKEY;
41   else
42     return MPI_SUCCESS;
43 }
44
45 int Info::get_nkeys(int *nkeys){
46   *nkeys = map_.size();
47   return MPI_SUCCESS;
48 }
49
50 int Info::get_nthkey(int n, char *key){
51   int num=0;
52   for (auto const& elm : map_) {
53     if (num == n) {
54       strncpy(key, elm.first.c_str(), elm.first.length() + 1);
55       return MPI_SUCCESS;
56     }
57     num++;
58   }
59   return MPI_ERR_ARG;
60 }
61
62 int Info::get_valuelen(const char *key, int *valuelen, int *flag){
63   *flag=false;
64   auto val = map_.find(key);
65   if (val != map_.end()) {
66     *valuelen = val->second.length();
67     *flag=true;
68   }
69   return MPI_SUCCESS;
70 }
71
72 Info* Info::f2c(int id){
73   return static_cast<Info*>(F2C::f2c(id));
74 }
75
76 }
77 }