Common ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
std-unordered-map-traits.hxx
Go to the documentation of this file.
1 // file : odb/std-unordered-map-traits.hxx
2 // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
3 // license : GNU GPL v2; see accompanying LICENSE file
4 
5 #ifndef ODB_STD_UNORDERED_MAP_TRAITS_HXX
6 #define ODB_STD_UNORDERED_MAP_TRAITS_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <utility> // std::move
11 #include <unordered_map>
12 
13 #include <odb/container-traits.hxx>
14 
15 namespace odb
16 {
17  template <typename K, typename V, typename H, typename P, typename A>
18  class access::container_traits<std::unordered_map<K, V, H, P, A>>
19  {
20  public:
21  static const container_kind kind = ck_map;
22  static const bool smart = false;
23 
24  typedef std::unordered_map<K, V, H, P, A> container_type;
25 
26  typedef K key_type;
27  typedef V value_type;
28  typedef typename container_type::value_type pair_type;
29 
31 
32  public:
33  static void
34  persist (const container_type& c, const functions& f)
35  {
36  for (typename container_type::const_iterator i (c.begin ()),
37  e (c.end ()); i != e; ++i)
38  f.insert (i->first, i->second);
39  }
40 
41  static void
42  load (container_type& c, bool more, const functions& f)
43  {
44  c.clear ();
45 
46  while (more)
47  {
48  key_type k;
49  value_type v;
50  more = f.select (k, v);
51  c.insert (pair_type (std::move (k), std::move (v)));
52  }
53  }
54 
55  static void
56  update (const container_type& c, const functions& f)
57  {
58  f.delete_ ();
59 
60  for (typename container_type::const_iterator i (c.begin ()),
61  e (c.end ()); i != e; ++i)
62  f.insert (i->first, i->second);
63  }
64 
65  static void
66  erase (const functions& f)
67  {
68  f.delete_ ();
69  }
70  };
71 
72  // @@ Does multimap preserve insertion order of equal elements? The
73  // current implementation in the generated code does not guarantee
74  // this.
75  //
76  template <typename K, typename V, typename H, typename P, typename A>
77  class access::container_traits<std::unordered_multimap<K, V, H, P, A>>
78  {
79  public:
80  static const container_kind kind = ck_multimap;
81  static const bool smart = false;
82 
83  typedef std::unordered_multimap<K, V, H, P, A> container_type;
84 
85  typedef K key_type;
86  typedef V value_type;
87  typedef typename container_type::value_type pair_type;
88 
90 
91  public:
92  static void
93  persist (const container_type& c, const functions& f)
94  {
95  for (typename container_type::const_iterator i (c.begin ()),
96  e (c.end ()); i != e; ++i)
97  f.insert (i->first, i->second);
98  }
99 
100  static void
101  load (container_type& c, bool more, const functions& f)
102  {
103  c.clear ();
104 
105  while (more)
106  {
107  key_type k;
108  value_type v;
109  more = f.select (k, v);
110  c.insert (pair_type (std::move (k), std::move (v)));
111  }
112  }
113 
114  static void
115  update (const container_type& c, const functions& f)
116  {
117  f.delete_ ();
118 
119  for (typename container_type::const_iterator i (c.begin ()),
120  e (c.end ()); i != e; ++i)
121  f.insert (i->first, i->second);
122  }
123 
124  static void
125  erase (const functions& f)
126  {
127  f.delete_ ();
128  }
129  };
130 }
131 
132 #include <odb/post.hxx>
133 
134 #endif // ODB_STD_UNORDERED_MAP_TRAITS_HXX
static void persist(const container_type &c, const functions &f)
Definition: std-unordered-map-traits.hxx:34
map_functions< key_type, value_type > functions
Definition: std-unordered-map-traits.hxx:30
void insert(const K &key, const V &value) const
Definition: container-traits.hxx:174
static void persist(const container_type &c, const functions &f)
Definition: std-unordered-map-traits.hxx:93
Definition: container-traits.hxx:168
static void update(const container_type &c, const functions &f)
Definition: std-unordered-map-traits.hxx:115
static void load(container_type &c, bool more, const functions &f)
Definition: std-unordered-map-traits.hxx:101
Definition: forward.hxx:119
static void update(const container_type &c, const functions &f)
Definition: std-unordered-map-traits.hxx:56
container_kind
Definition: container-traits.hxx:17
container_type::value_type pair_type
Definition: std-unordered-map-traits.hxx:28
static void erase(const functions &f)
Definition: std-unordered-map-traits.hxx:125
void delete_() const
Definition: container-traits.hxx:186
K key_type
Definition: std-unordered-map-traits.hxx:26
Definition: container-traits.hxx:23
static void load(container_type &c, bool more, const functions &f)
Definition: std-unordered-map-traits.hxx:42
map_functions< key_type, value_type > functions
Definition: std-unordered-map-traits.hxx:89
container_type::value_type pair_type
Definition: std-unordered-map-traits.hxx:87
std::unordered_map< K, V, H, P, A > container_type
Definition: std-unordered-map-traits.hxx:24
std::unordered_multimap< K, V, H, P, A > container_type
Definition: std-unordered-map-traits.hxx:83
static void erase(const functions &f)
Definition: std-unordered-map-traits.hxx:66
V value_type
Definition: std-unordered-map-traits.hxx:27
Definition: container-traits.hxx:22
bool select(K &next_key, V &next_value) const
Definition: container-traits.hxx:180