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

#ifndef ODB_SEMANTICS_RELATIONAL_CHANGESET_HXX
#define ODB_SEMANTICS_RELATIONAL_CHANGESET_HXX

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

namespace semantics
{
  namespace relational
  {
    class model;
    class changeset;

    class alters_model: public edge
    {
    public:
      typedef relational::model model_type;
      typedef relational::changeset changeset_type;

      model_type&
      model () const {return *model_;}

      changeset_type&
      changeset () const {return *changeset_;}

    public:
      alters_model () : model_ (0), changeset_ (0) {}

      void
      set_left_node (changeset_type& c)
      {
        assert (changeset_ == 0);
        changeset_ = &c;
      }

      void
      set_right_node (model_type& m)
      {
        assert (model_ == 0);
        model_ = &m;
      }

    protected:
      model_type* model_;
      changeset_type* changeset_;
    };

    class changeset: public qscope
    {
    public:
      typedef relational::version version_type;

      version_type
      version () const {return version_;}

      // Returns model to which this changeset applies (as opposed to the
      // ultimate base model). Note that it may not be set.
      //
      model&
      base_model () const {return alters_model_->model ();}

    public:
      changeset (version_type v): version_ (v), alters_model_ (0) {}
      changeset (changeset const&, qscope& base, graph&);
      changeset (xml::parser&, qscope& base, graph&);

      virtual string
      kind () const {return "changeset";}

      virtual void
      serialize (xml::serializer&) const;

    public:
      virtual void
      add_edge_left (alters_model& am)
      {
        assert (alters_model_ == 0);
        alters_model_ = &am;
      }

      using qscope::add_edge_left;
      using qscope::add_edge_right;

    private:
      version_type version_;
      alters_model* alters_model_;
    };
  }
}

#endif // ODB_SEMANTICS_RELATIONAL_CHANGESET_HXX