Back to index

texmacs  1.0.7.15
patch.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : patch.hpp
00004 * DESCRIPTION: Abstract patches
00005 * COPYRIGHT  : (C) 2009  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef PATCH_H
00013 #define PATCH_H
00014 #include "modification.hpp"
00015 
00016 #define PATCH_MODIFICATION 0
00017 #define PATCH_COMPOUND     1
00018 #define PATCH_BRANCH       2
00019 #define PATCH_BIRTH        3
00020 #define PATCH_AUTHOR       4
00021 
00022 /******************************************************************************
00023 * Abstract patches
00024 ******************************************************************************/
00025 
00026 class patch;
00027 class patch_rep: public abstract_struct {
00028 public:
00029   inline patch_rep () {}
00030   inline virtual ~patch_rep () {}
00031   virtual int get_type () = 0;
00032   inline virtual int get_arity () {
00033     return 0; }
00034   inline virtual patch get_child (int i);
00035   inline virtual modification get_modification () {
00036     FAILED ("not a modification"); return mod_assign (path (), ""); }
00037   inline virtual modification get_inverse () {
00038     FAILED ("not a modification"); return mod_assign (path (), ""); }
00039   inline virtual bool get_birth () {
00040     FAILED ("not a birth"); return false; }
00041   inline virtual double get_author () {
00042     return -1; }
00043 };
00044 
00045 class patch {
00046 ABSTRACT_NULL (patch);
00047   patch (modification mod, modification inv);
00048   patch (array<patch> a);
00049   patch (bool par, array<patch> a);
00050   patch (patch p1, patch p2);
00051   patch (double author, bool create);
00052   patch (double author, patch p);
00053   inline patch operator [] (int i) {
00054     return rep->get_child (i); }
00055 };
00056 ABSTRACT_NULL_CODE (patch);
00057 
00058 inline patch patch_rep::get_child (int i) {
00059   FAILED ("not a composite patch"); (void) i; return patch (); }
00060 
00061 /******************************************************************************
00062 * Routines on patches
00063 ******************************************************************************/
00064 
00065 int nr_children (patch p);
00066 patch child (patch p, int i);
00067 array<patch> children (patch p);
00068 array<patch> children (patch p, int i, int j);
00069 int nr_branches (patch p);
00070 patch branch (patch p, int i);
00071 array<patch> branches (patch p);
00072 array<patch> branches (patch p, int i, int j);
00073 
00074 double new_author ();
00075 double new_marker ();
00076 void set_author (double author);
00077 double get_author ();
00078 
00079 tm_ostream& operator << (tm_ostream& out, patch p);
00080 patch copy (patch p);
00081 patch compactify (patch p);
00082 path cursor_hint (patch p, tree t);
00083 
00084 inline int get_type (patch p) {
00085   return p->get_type (); }
00086 inline int N (patch p) {
00087   return p->get_arity (); }
00088 inline modification get_modification (patch p) {
00089   return p->get_modification (); }
00090 inline modification get_inverse (patch p) {
00091   return p->get_inverse (); }
00092 inline bool get_birth (patch p) {
00093   return p->get_birth (); }
00094 inline double get_author (patch p) {
00095   return p->get_author (); }
00096 
00097 bool is_applicable (patch p, tree t);
00098 tree clean_apply (patch p, tree t);
00099 void apply (patch p, tree& t);
00100 
00101 modification invert (modification m, tree t);
00102 bool commute (modification m1, modification m2);
00103 bool swap (modification& m1, modification& m2);
00104 bool join (modification& m1, modification m2, tree t);
00105 patch invert (patch p, tree t);
00106 bool commute (patch p1, patch p2);
00107 bool swap (patch& p1, patch& p2);
00108 bool join (patch& p1, patch p2, tree t);
00109 patch remove_set_cursor (patch p);
00110 bool does_modify (patch p);
00111 
00112 #endif // defined PATCH_H