IMP logo
IMP Reference Guide  2.20.1
The Integrative Modeling Platform
set_map_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/set_map_macros.h
3  * \brief Macros to choose the best set or map for different purposes.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_SET_MAP_MACROS_H
10 #define IMPKERNEL_SET_MAP_MACROS_H
11 
12 #ifdef IMP_DOXYGEN
13 //! Macro to support platform independent declaration of a small ordered set
14 /** Declare a small, ordered set like IMP_KERNEL_SMALL_ORDERED_SET<item>. */
15 #define IMP_KERNEL_SMALL_ORDERED_SET boost::container::flat_set
16 //! Macro to support platform independent declaration of a small ordered map
17 /** Declare a small, ordered set like IMP_KERNEL_SMALL_ORDERED_MAP<key, value>. */
18 #define IMP_KERNEL_SMALL_ORDERED_MAP boost::container::flat_map
19 //! Macro to support platform independent declaration of a small unordered set
20 /** Declare a small, ordered set like IMP_KERNEL_SMALL_UNORDERED_SET<item>. */
21 #define IMP_KERNEL_SMALL_UNORDERED_SET boost::container::flat_set
22 //! Macro to support platform independent declaration of a small unordered map
23 /** Declare a small, ordered set like IMP_KERNEL_SMALL_UNORDERED_MAP<key, value>.
24  */
25 #define IMP_KERNEL_SMALL_UNORDERED_MAP boost::container::flat_map
26 //! Macro to support platform independent declaration of a large ordered set
27 /** Declare a small, ordered set like IMP_KERNEL_LARGE_ORDERED_SET<item>. */
28 #define IMP_KERNEL_LARGE_ORDERED_SET std::set
29 //! Macro to support platform independent declaration of a large ordered map
30 /** Declare a small, ordered set like IMP_KERNEL_LARGE_ORDERED_MAP<key, value>. */
31 #define IMP_KERNEL_LARGE_ORDERED_MAP std::map
32 //! Macro to support platform independent declaration of a large unordered set
33 /** Declare a small, ordered set like IMP_KERNEL_LARGE_UNORDERED_SET<item>. */
34 #define IMP_KERNEL_LARGE_UNORDERED_SET boost::unordered_set
35 //! Macro to support platform independent declaration of a large unordered map
36 /** Declare a small, ordered set like IMP_KERNEL_LARGE_UNORDERED_MAP<key, value>.
37  */
38 #define IMP_KERNEL_LARGE_UNORDERED_MAP boost::unordered_map
39 
40 #else
41 
42 #include <IMP/kernel_config.h>
43 #include <boost/version.hpp>
44 #include <boost/functional/hash/hash.hpp> // IWYU pragma: export
45 
46 #include <boost/functional/hash/hash.hpp> // IWYU pragma: export
47 #include <set> // IWYU pragma: export
48 #include <map> // IWYU pragma: export
49 #include <boost/unordered_set.hpp> // IWYU pragma: export
50 #include <boost/unordered_map.hpp> // IWYU pragma: export
51 
52 #define IMP_KERNEL_LARGE_ORDERED_SET std::set
53 #define IMP_KERNEL_LARGE_ORDERED_MAP std::map
54 #define IMP_KERNEL_LARGE_UNORDERED_SET boost::unordered_set
55 #define IMP_KERNEL_LARGE_UNORDERED_MAP boost::unordered_map
56 
57 #if defined(_MSC_VER) && _MSC_VER <= 1500
58 #include <set> // IWYU pragma: export
59 #include <map> // IWYU pragma: export
60 #include <boost/unordered_set.hpp> // IWYU pragma: export
61 #include <boost/unordered_map.hpp> // IWYU pragma: export
62 
63 #define IMP_KERNEL_SMALL_ORDERED_SET std::set
64 #define IMP_KERNEL_SMALL_ORDERED_MAP std::map
65 #define IMP_KERNEL_SMALL_UNORDERED_SET boost::unordered_set
66 #define IMP_KERNEL_SMALL_UNORDERED_MAP boost::unordered_map
67 #else
68 #include <boost/container/flat_set.hpp> // IWYU pragma: export
69 #include <boost/container/flat_map.hpp> // IWYU pragma: export
70 #include <cereal/access.hpp>
71 #define IMP_KERNEL_SMALL_ORDERED_SET boost::container::flat_set
72 #define IMP_KERNEL_SMALL_ORDERED_MAP boost::container::flat_map
73 #define IMP_KERNEL_SMALL_UNORDERED_SET boost::container::flat_set
74 #define IMP_KERNEL_SMALL_UNORDERED_MAP boost::container::flat_map
75 
76 // Allow serialization of boost::container::flat_set
77 namespace cereal {
78  template<class Archive, typename Key, typename Compare, typename Allocator>
79  inline void save(Archive &ar,
80  boost::container::flat_set<Key, Compare, Allocator> const &t) {
81  auto count = t.size();
82  ar(count);
83  typename boost::container::flat_set<
84  Key, Compare, Allocator>::const_iterator it = t.begin();
85  while(count-- > 0) {
86  ar(*it++);
87  }
88  }
89 
90  template<class Archive, typename Key, typename Compare, typename Allocator>
91  inline void load(Archive &ar,
92  boost::container::flat_set<Key, Compare, Allocator> &t) {
93  typedef typename boost::container::flat_set<Key, Compare, Allocator>::iterator iterator;
94  typedef typename boost::container::flat_set<Key, Compare, Allocator>::value_type value_type;
95  t.clear();
96  typename boost::container::flat_set<Key, Compare, Allocator>::size_type count;
97  ar(count);
98  iterator hint = t.begin();
99  while(count-- > 0) {
100  value_type key;
101  ar(key);
102  hint = t.insert(hint, key);
103  }
104  }
105 }
106 
107 #endif
108 #endif
109 
110 #endif /* IMPKERNEL_SET_MAP_MACROS_H */