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