aboutsummaryrefslogtreecommitdiff
path: root/common/inheritance/reuse/test.hxx
blob: 48f474fb8216c9cd4d0b7f783e4c893cd1fedafe (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// file      : common/inheritance/reuse/test.hxx
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef TEST_HXX
#define TEST_HXX

#include <string>
#include <vector>

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

#pragma db value
struct comp_base
{
  std::vector<unsigned char> bools;
  odb::vector<unsigned char> obools;

  bool
  operator== (const comp_base& y) const
  {
    return bools == y.bools && obools == y.obools;
  }
};

#pragma db value
struct comp: comp_base
{
  unsigned int num;
  std::string str;

  std::vector<unsigned int> nums;
  odb::vector<unsigned int> onums;

  bool
  operator== (const comp& y) const
  {
    return
      static_cast<const comp_base&> (*this) == y &&
      num == y.num &&
      str == y.str &&
      nums == y.nums &&
      onums == y.onums;
  }
};

#pragma db object abstract
struct abstract_base
{
  comp comp_;

  unsigned int num_;
  std::string str_;

  std::vector<std::string> strs_;
  odb::vector<std::string> ostrs_;

  bool
  operator== (const abstract_base& y) const
  {
    return
      comp_ == y.comp_ &&
      num_ == y.num_ &&
      str_ == y.str_ &&
      strs_ == y.strs_ &&
      ostrs_ == y.ostrs_;
  }
};

#pragma db object
struct base: abstract_base
{
  #pragma db id auto
  unsigned long id_;

  bool
  operator== (const base& y) const
  {
    return id_ == y.id_ && static_cast<const abstract_base&> (*this) == y;
  }
};

#pragma db object
struct object1: base
{
  unsigned int num1_;

  bool
  operator== (const object1& y) const
  {
    return static_cast<const base&> (*this) == y && num1_ == y.num1_;
  }
};

#pragma db object
struct object2: base
{
  #pragma db column("derived_str")
  std::string str_;

  bool
  operator== (const object2& y) const
  {
    return static_cast<const base&> (*this) == y && str_ == y.str_;
  }
};

// Reference to derived object.
//
#pragma db object
struct reference
{
  #pragma db id auto
  unsigned long id_;

  object1* o1_;
};

// Multiple inheritance.
//
#pragma db object abstract
struct id_base
{
  #pragma db id auto
  unsigned long id_;

  bool
  operator== (const id_base& y) const
  {
    return id_ == y.id_;
  }
};

#pragma db object
struct object3: abstract_base, id_base
{
  bool
  operator== (const object3& y) const
  {
    return
      static_cast<const abstract_base&> (*this) == y &&
      static_cast<const id_base&> (*this) == y;
  }
};

// Empty derived object.
//
#pragma db object
struct empty_object: base
{
};

// View based on the derived object.
//
#pragma db view object(object2)
struct object2_view
{
  unsigned int num; // from abstract_base
  unsigned long id; // from base
  std::string str;  // from object2, hides one from abstract_base
};

#endif // TEST_HXX