bpp-core3  3.0.0
MapTools.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_UTILS_MAPTOOLS_H
6 #define BPP_UTILS_MAPTOOLS_H
7 
8 #include <map>
9 #include <vector>
10 
11 
12 namespace bpp
13 {
17 class MapTools
18 {
19 public:
26  template<class Key, class T, class Cmp >
27  static std::vector<Key> getKeys(const std::map<Key, T, Cmp>& myMap)
28  {
29  std::vector<Key> keys;
30  for (typename std::map<Key, T>::const_iterator i = myMap.begin(); i != myMap.end(); i++)
31  {
32  keys.push_back(i->first);
33  }
34  return keys;
35  }
36 
43  template<class Key, class T >
44  static std::vector<Key> getKeys(const std::map<Key, T>& myMap)
45  {
46  std::vector<Key> keys;
47  for (typename std::map<Key, T>::const_iterator i = myMap.begin(); i != myMap.end(); i++)
48  {
49  keys.push_back(i->first);
50  }
51  return keys;
52  }
53 
60  template<class Key, class T, class Cmp >
61  static std::vector<T> getValues(const std::map<Key, T, Cmp>& myMap)
62  {
63  std::vector<T> values;
64  for (typename std::map<Key, T>::const_iterator i = myMap.begin(); i != myMap.end(); i++)
65  {
66  values.push_back(i->second);
67  }
68  return values;
69  }
70 
77  template<class Key, class T >
78  static std::vector<T> getValues(const std::map<Key, T>& myMap)
79  {
80  std::vector<T> values;
81  for (typename std::map<Key, T>::const_iterator i = myMap.begin(); i != myMap.end(); i++)
82  {
83  values.push_back(i->second);
84  }
85  return values;
86  }
87 };
88 } // end of namespace bpp.
89 #endif // BPP_UTILS_MAPTOOLS_H
static std::vector< T > getValues(const std::map< Key, T > &myMap)
Get a vector of all values in a map.
Definition: MapTools.h:78
static std::vector< T > getValues(const std::map< Key, T, Cmp > &myMap)
Get a vector of all values in a map.
Definition: MapTools.h:61
static std::vector< Key > getKeys(const std::map< Key, T, Cmp > &myMap)
Get a vector of all keys in a map.
Definition: MapTools.h:27
static std::vector< Key > getKeys(const std::map< Key, T > &myMap)
Get a vector of all keys in a map.
Definition: MapTools.h:44
A fiew tools working on map objects.
Definition: MapTools.h:17