aboutsummaryrefslogtreecommitdiff
path: root/odb/semantics/relational/key.hxx
blob: d049445704fe5956f9508a304cd8e57de2726c22 (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
// file      : odb/semantics/relational/key.hxx
// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
// license   : GNU GPL v3; see accompanying LICENSE file

#ifndef ODB_SEMANTICS_RELATIONAL_KEY_HXX
#define ODB_SEMANTICS_RELATIONAL_KEY_HXX

#include <odb/semantics/relational/elements.hxx>
#include <odb/semantics/relational/table.hxx>

namespace semantics
{
  namespace relational
  {
    class key;
    class column;

    class contains: public edge
    {
    public:
      typedef relational::key key_type;
      typedef relational::column column_type;

      key_type&
      key () const {return *key_;}

      column_type&
      column () const {return *column_;}

      string const&
      options () const {return options_;}

    public:
      contains (string const& o = string ()) : options_ (o) {}

      void
      set_left_node (key_type& n)
      {
        key_ = &n;
      }

      void
      set_right_node (column_type& n)
      {
        column_ = &n;
      }

    protected:
      key_type* key_;
      column_type* column_;
      string options_;
    };

    class key: public unameable
    {
      typedef std::vector<contains*> contains_list;

    public:
      typedef contains_list::size_type contains_size_type;

      typedef
      pointer_iterator<contains_list::const_iterator>
      contains_iterator;

      contains_iterator
      contains_begin () const {return contains_.begin ();}

      contains_iterator
      contains_end () const {return contains_.end ();}

      contains_size_type
      contains_size () const {return contains_.size ();}

      contains&
      contains_at (contains_size_type i) const {return *contains_[i];}

    public:
      typedef relational::table table_type;

      table_type&
      table () const {return dynamic_cast<table_type&> (scope ());}

    public:
      key (std::string const& id): unameable (id) {}

      void
      add_edge_left (contains& e)
      {
        contains_.push_back (&e);
      }

    protected:
      key (key const&, uscope&, graph&);
      key (xml::parser&, uscope&, graph&);

      void
      serialize_content (xml::serializer&) const;

    private:
      contains_list contains_;
    };
  }
}

#endif // ODB_SEMANTICS_RELATIONAL_KEY_HXX