Logo AND Algorithmique Numérique Distribuée

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