Common ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vector-traits.hxx
Go to the documentation of this file.
1 // file : odb/vector-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_VECTOR_TRAITS_HXX
6 #define ODB_VECTOR_TRAITS_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <odb/vector.hxx>
11 #include <odb/vector-impl.hxx>
12 #include <odb/container-traits.hxx>
13 #include <odb/transaction.hxx>
14 
15 namespace odb
16 {
17  template <typename V, typename A LIBODB_VECTOR_ARG_DECL>
19  {
20  public:
21  static const container_kind kind = ck_ordered;
22  static const bool smart = true;
23 
25 
26  typedef V value_type;
28 
31 
32  public:
33  static void
34  persist (const container_type& c, const functions& f)
35  {
36  for (index_type i (0), n (c.size ()); i < n; ++i)
37  f.insert (i, c[i]);
38 
39  // Now that this container is persistent, start tracking changes.
40  //
41  c._start ();
42  }
43 
44  static void
45  load (container_type& c, bool more, const functions& f)
46  {
47  // Stop tracking changes.
48  //
49  c._stop ();
50 
51  // Load.
52  //
53  c.clear ();
54  while (more)
55  {
56  index_type dummy;
57  c.push_back (value_type ());
58  more = f.select (dummy, c.modify_back ());
59  }
60 
61  // Start tracking changes.
62  //
63  c._start ();
64  }
65 
66  static bool
67  changed (const container_type&);
68 
69  static void
70  update (const container_type&, const functions&);
71 
72  static void
73  erase (const container_type* c, const functions& f)
74  {
75  f.delete_ (0);
76 
77  // Stop tracking changes.
78  //
79  if (c != 0)
80  c->_stop ();
81  }
82 
83  // Version of load() for dumb functions. Used to support
84  // inverse members of the container type. The implementation
85  // is identical to the smart one except we don't turn off/on
86  // change tracking.
87  //
88  static void
89  load (container_type& c, bool more, const dumb_functions& f)
90  {
91  c.clear ();
92 
93  while (more)
94  {
95  index_type dummy;
96  c.push_back (value_type ());
97  more = f.select (dummy, c.modify_back ());
98  }
99  }
100  };
101 }
102 
103 #include <odb/vector-traits.txx>
104 
105 #include <odb/post.hxx>
106 
107 #endif // ODB_VECTOR_TRAITS_HXX
ordered_functions< index_type, value_type > dumb_functions
Definition: vector-traits.hxx:30
void _start() const
Definition: vector.hxx:218
bool select(I &next_index, V &next_value) const
Definition: container-traits.hxx:93
base_vector_type::size_type size_type
Definition: vector.hxx:64
Definition: forward.hxx:119
bool select(I &next_index, V &next_value) const
Definition: container-traits.hxx:55
void insert(I index, const V &value) const
Definition: container-traits.hxx:87
void _stop() const
Definition: vector-impl.hxx:177
void push_back(const T &x)
container_kind
Definition: container-traits.hxx:17
#define LIBODB_VECTOR_ARG_USE
Definition: vector.hxx:37
size_type size() const
Definition: vector.hxx:137
void delete_(I start_index) const
Definition: container-traits.hxx:108
smart_ordered_functions< index_type, value_type > functions
Definition: vector-traits.hxx:29
static void persist(const container_type &c, const functions &f)
Definition: vector-traits.hxx:34
reference modify_back()
Definition: container-traits.hxx:81
Definition: container-traits.hxx:19
void clear()
static void erase(const container_type *c, const functions &f)
Definition: vector-traits.hxx:73
static void load(container_type &c, bool more, const dumb_functions &f)
Definition: vector-traits.hxx:89
container_type::size_type index_type
Definition: vector-traits.hxx:27
Definition: vector.hxx:51
Definition: container-traits.hxx:33
static void load(container_type &c, bool more, const functions &f)
Definition: vector-traits.hxx:45
vector< V, A > container_type
Definition: vector-traits.hxx:24