2 /******************************************************************************
4 * DESCRIPTION: Abstract patches
5 * COPYRIGHT : (C) 2009 Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
14 #include "modification.hpp"
16 #define PATCH_MODIFICATION 0
17 #define PATCH_COMPOUND 1
18 #define PATCH_BRANCH 2
20 #define PATCH_AUTHOR 4
22 /******************************************************************************
24 ******************************************************************************/
27 class patch_rep
: public abstract_struct
{
29 inline patch_rep () {}
30 inline virtual ~patch_rep () {}
31 virtual int get_type () = 0;
32 inline virtual int get_arity () {
34 inline virtual patch
get_child (int i
);
35 inline virtual modification
get_modification () {
36 FAILED ("not a modification"); return mod_assign (path (), ""); }
37 inline virtual modification
get_inverse () {
38 FAILED ("not a modification"); return mod_assign (path (), ""); }
39 inline virtual bool get_birth () {
40 FAILED ("not a birth"); return false; }
41 inline virtual double get_author () {
46 ABSTRACT_NULL (patch
);
47 patch (modification mod
, modification inv
);
48 patch (array
<patch
> a
);
49 patch (bool par
, array
<patch
> a
);
50 patch (patch p1
, patch p2
);
51 patch (double author
, bool create
);
52 patch (double author
, patch p
);
53 inline patch
operator [] (int i
) {
54 return rep
->get_child (i
); }
56 ABSTRACT_NULL_CODE (patch
);
58 inline patch
patch_rep::get_child (int i
) {
59 FAILED ("not a composite patch"); (void) i
; return patch (); }
61 /******************************************************************************
63 ******************************************************************************/
65 int nr_children (patch p
);
66 patch
child (patch p
, int i
);
67 array
<patch
> children (patch p
);
68 array
<patch
> children (patch p
, int i
, int j
);
69 int nr_branches (patch p
);
70 patch
branch (patch p
, int i
);
71 array
<patch
> branches (patch p
);
72 array
<patch
> branches (patch p
, int i
, int j
);
76 void set_author (double author
);
79 tm_ostream
& operator << (tm_ostream
& out
, patch p
);
81 patch
compactify (patch p
);
82 path
cursor_hint (patch p
, tree t
);
84 inline int get_type (patch p
) {
85 return p
->get_type (); }
86 inline int N (patch p
) {
87 return p
->get_arity (); }
88 inline modification
get_modification (patch p
) {
89 return p
->get_modification (); }
90 inline modification
get_inverse (patch p
) {
91 return p
->get_inverse (); }
92 inline bool get_birth (patch p
) {
93 return p
->get_birth (); }
94 inline double get_author (patch p
) {
95 return p
->get_author (); }
97 bool is_applicable (patch p
, tree t
);
98 tree
clean_apply (patch p
, tree t
);
99 void apply (patch p
, tree
& t
);
101 modification
invert (modification m
, tree t
);
102 bool commute (modification m1
, modification m2
);
103 bool swap (modification
& m1
, modification
& m2
);
104 bool join (modification
& m1
, modification m2
, tree t
);
105 patch
invert (patch p
, tree t
);
106 bool commute (patch p1
, patch p2
);
107 bool swap (patch
& p1
, patch
& p2
);
108 bool join (patch
& p1
, patch p2
, tree t
);
110 #endif // defined PATCH_H