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