aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/common.txx
blob: 893e16cf6b355d469e441f17119cb1e2810c07a1 (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
// file      : odb/relational/common.txx
// copyright : Copyright (c) 2009-2015 Code Synthesis Tools CC
// license   : GNU GPL v3; see accompanying LICENSE file

namespace relational
{
  //
  // member_base_impl
  //

  template <typename T>
  void member_base_impl<T>::
  traverse (semantics::data_member& m)
  {
    if (transient (m))
      return;

    string var;

    if (!var_override_.empty ())
      var = var_override_;
    else
    {
      string const& name (m.name ());
      var = name + (name[name.size () - 1] == '_' ? "" : "_");
    }

    bool cq (type_override_ != 0 ? false : const_member (m));
    const custom_cxx_type* ct (0);
    semantics::type& t (type_override_ != 0
                        ? *type_override_
                        : utype (m, &ct));

    semantics::type* cont;
    if (semantics::class_* c = object_pointer (t))
    {
      // A pointer in view might point to an object without id.
      //
      semantics::data_member* idm (id_member (*c));
      semantics::type& t (utype (idm != 0 ? *idm : m, &ct));
      semantics::class_* comp (idm != 0 ? composite_wrapper (t) : 0);

      member_info mi (m,
                      (comp != 0 ? *comp : t),
                      ct,
                      (comp != 0 && wrapper (t) ? &t : 0),
                      cq,
                      var,
                      fq_type_override_); // Pointer type.

      mi.ptr = c;

      // Pointer in views aren't really a "column".
      //
      if (!view_member (m) && comp == 0)
        mi.st = &member_sql_type (m);

      if (pre (mi))
      {
        traverse_pointer (mi);
        post (mi);
      }
    }
    else if (semantics::class_* c = composite_wrapper (t))
    {
      // If t is a wrapper, pass the wrapped type. Also pass the
      // original, wrapper type.
      //
      member_info mi (m,
                      *c,
                      ct,
                      (wrapper (t) ? &t : 0),
                      cq,
                      var,
                      fq_type_override_);
      if (pre (mi))
      {
        traverse_composite (mi);
        post (mi);
      }
    }
    // This cannot be a container if we have a type override.
    //
    else if (type_override_ == 0 && (cont = context::container (m)))
    {
      // The same unwrapping logic as for composite values.
      //
      member_info mi (m,
                      *cont,
                      0, // Cannot be mapped.
                      (wrapper (t) ? &t : 0),
                      cq,
                      var,
                      fq_type_override_);
      if (pre (mi))
      {
        traverse_container (mi);
        post (mi);
      }
    }
    else
    {
      member_info mi (m, t, ct, 0, cq, var, fq_type_override_);
      mi.st = &member_sql_type (m);

      if (pre (mi))
      {
        traverse_simple (mi);
        post (mi);
      }
    }
  }

  template <typename T>
  void member_base_impl<T>::
  traverse_pointer (member_info& mi)
  {
    if (!view_member (mi.m)) // Not really "as if" pointed-to id member.
    {
      if (composite (mi.t)) // Already unwrapped.
        traverse_composite (mi);
      else
        traverse_simple (mi);
    }
  }
}