aboutsummaryrefslogtreecommitdiff
path: root/common/virtual/test.hxx
blob: 3c0b0f139b183041f52710a5e150e86b1c1d8490 (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
// file      : common/virtual/test.hxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef TEST_HXX
#define TEST_HXX

#include <string>
#include <vector>

#include <odb/core.hxx>

// Test basic virtual data member functionality.
//
#pragma db namespace table("t1_")
namespace test1
{
  #pragma db value
  struct comp
  {
    int i;

    #pragma db transient
    std::string s;
    #pragma db member(s_) virtual(std::string) access (s)

    bool operator== (const comp& v) const
    {
      return i == v.i && s == v.s;
    }
  };

  #pragma db object transient
  struct object
  {
    object (): p1 (0) {}
    ~object () {delete p1;}

    struct {unsigned long v;} id1;

    #pragma db id
    #pragma db member(id) get(id1.v) virtual(unsigned long) set(id1.v)
    #pragma db member(id) auto

    int i () const {return i1;}
    void i (int i) {i1 = i;}
    int i1;

    comp c1;
    #pragma db member(c) virtual(comp) access(c1)

    typedef std::vector<std::string> strings;
    strings v1;
    #pragma db member(v) virtual(strings) access(v1)

    typedef object* object_ptr;
    object_ptr p1;
    #pragma db member(p) virtual(object_ptr) access(p1)

    bool operator== (const object& o) const
    {
      return id1.v == o.id1.v &&
        i1 == o.i1 &&
        c1 == o.c1 &&
        v1 == o.v1 &&
        (p1 != 0 ? o.p1 != 0 && *p1 == *o.p1 : o.p1 == 0);
    }
  };

  #pragma db member(object::i) virtual(int)
}

#pragma db member(test1::object::id) column("oid")

// Test pragma resolution to virtual data member.
//
#pragma db namespace table("t2_")
namespace test2
{
  struct object1;
  struct object2;

  typedef object1* object1_ptr;
  typedef object2* object2_ptr;

  #pragma db object
  struct object2
  {
    object2 (unsigned long i = 0): id (i) {}

    #pragma db id
    unsigned long id;

    #pragma db inverse(o)
    object1_ptr o1;
  };

  #pragma db object
  struct object1
  {
    object1 (unsigned long i = 0): id (i), o2 (0) {}
    ~object1 () {delete o2;}

    #pragma db id
    unsigned long id;

    #pragma db transient
    object2_ptr o2;
    #pragma db member(o) virtual(object2_ptr) access(o2)

    #pragma db transient
    unsigned long n1;
    #pragma db member(n) virtual(unsigned long) access(n1)
    #pragma db index member(n)
  };

  #pragma db view object(object1) object(object2)
  struct view1
  {
    #pragma db column(object1::n)
    unsigned long i;
  };

  #pragma db view object(object1 = o1) object(object2 = o2: o1::n == o2::id)
  struct view2
  {
    #pragma db column(o1::n)
    unsigned long i;
  };

  #pragma db view object(object1: object1::n != 0)
  struct view3
  {
    #pragma db column(test2::object1::n)
    unsigned long i;
  };
}

#endif // TEST_HXX