aboutsummaryrefslogtreecommitdiff
path: root/common/container/change-tracking/test.hxx
blob: 6ffa3701d06870dc1afdbb3fd42123cabe2886fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// file      : common/container/change-tracking/test.hxx
// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef TEST_HXX
#define TEST_HXX

#include <common/config.hxx> // HAVE_CXX11

#include <string>
#include <memory>
#include <vector>

#ifdef HAVE_CXX11
#  include <utility> // std::move
#endif

#include <odb/core.hxx>
#include <odb/vector.hxx>

#ifdef HAVE_CXX11
#pragma db object pointer(std::unique_ptr)
#else
#pragma db object pointer(std::auto_ptr)
#endif
struct object
{
  object () {}
  object (const std::string& id): id_ (id) {}

#ifdef HAVE_CXX11
  object (const object& x): id_ (x.id_), i (x.i), s (x.s) {}
  object (object&& x): id_ (std::move (x.id_)), i (x.i), s (std::move (x.s)) {}
#endif

  #pragma db id
  std::string id_;

  unsigned int i;

  odb::vector<std::string> s;

  inline bool
  operator== (const object& o) {return id_ == o.id_ && i == o.i && s == o.s;}
};

// Test mixing "smart" and "dumb" container (specifically, erase(obj)).
//
#pragma db object
struct mix_object
{
  mix_object () {}
  mix_object (unsigned long id): id_ (id) {}

  #pragma db id
  unsigned long id_;

  odb::vector<int> ov;
  std::vector<int> sv;
};

// Test using change tracking container as inverse member.
//
struct inv_object2;

#pragma db object session
struct inv_object1
{
  #pragma db id auto
  unsigned long id_;

  inv_object2* o2;
};

#pragma db object session
struct inv_object2
{
  #pragma db id auto
  unsigned long id_;

  #pragma db inverse(o2)
  odb::vector<inv_object1*> o1;
};

// Test read-only values (we still need to include them in the UPDATE
// statement).
//
#pragma db value
struct ro_value
{
  ro_value (int i_ = 0, int j_ = 0): i (i_), j (j_) {}

  #pragma db readonly
  int i;

  #pragma db readonly
  int j;
};

inline bool
operator== (const ro_value& x, const ro_value& y)
{
  return x.i == y.i && x.j == y.j;
}

#pragma db object
struct ro_object
{
  ro_object () {}
  ro_object (unsigned long id): id_ (id) {}

  #pragma db id
  unsigned long id_;

  odb::vector<ro_value> v;
};

#endif // TEST_HXX