PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/TeXmacs-1.0.7.11-src/src/Kernel/Abstractions/observer.hpp

#
C++ Header | 169 lines | 127 code | 24 blank | 18 comment | 4 complexity | 2f7dab42765373ccbfd988c6a2ccd8c9 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /******************************************************************************
  2. * MODULE : observer.hpp
  3. * DESCRIPTION: Observers of trees
  4. * COPYRIGHT : (C) 2004 Joris van der Hoeven
  5. *******************************************************************************
  6. * This software falls under the GNU general public license version 3 or later.
  7. * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
  8. * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
  9. ******************************************************************************/
  10. #ifndef OBSERVER_H
  11. #define OBSERVER_H
  12. #include "string.hpp"
  13. enum tree_label;
  14. class tree;
  15. class hard_link_rep;
  16. class observer;
  17. class modification;
  18. template<class T> class list;
  19. template<class T> class array;
  20. typedef hard_link_rep* weak_link;
  21. typedef list<int> path;
  22. #define OBSERVER_UNKNOWN 0
  23. #define OBSERVER_LIST 1
  24. #define OBSERVER_IP 2
  25. #define OBSERVER_POINTER 3
  26. #define OBSERVER_POSITION 4
  27. #define OBSERVER_EDIT 5
  28. #define OBSERVER_UNDO 6
  29. #define OBSERVER_HIGHLIGHT 7
  30. /******************************************************************************
  31. * The observer class
  32. ******************************************************************************/
  33. extern int observer_count;
  34. class observer_rep: public abstract_struct {
  35. public:
  36. inline observer_rep () { TM_DEBUG(observer_count++); }
  37. inline virtual ~observer_rep () { TM_DEBUG(observer_count--); }
  38. inline virtual int get_type () { return OBSERVER_UNKNOWN; }
  39. inline virtual tm_ostream& print (tm_ostream& out) { return out; }
  40. // Announcing modifications in subtrees
  41. virtual void announce (tree& ref, modification mod);
  42. virtual void announce_assign (tree& ref, path p, tree t);
  43. virtual void announce_insert (tree& ref, path p, tree ins);
  44. virtual void announce_remove (tree& ref, path p, int nr);
  45. virtual void announce_split (tree& ref, path p);
  46. virtual void announce_join (tree& ref, path p);
  47. virtual void announce_assign_node (tree& ref, path p, tree_label op);
  48. virtual void announce_insert_node (tree& ref, path p, tree ins);
  49. virtual void announce_remove_node (tree& ref, path p);
  50. virtual void announce_set_cursor (tree& ref, path p, tree data);
  51. virtual void done (tree& ref, modification mod);
  52. virtual void touched (tree& ref, path p);
  53. // Call back routines for tree modifications
  54. virtual void notify_assign (tree& ref, tree t);
  55. virtual void notify_insert (tree& ref, int pos, int nr);
  56. virtual void notify_remove (tree& ref, int pos, int nr);
  57. virtual void notify_split (tree& ref, int pos, tree prev);
  58. virtual void notify_var_split (tree& ref, tree t1, tree t2);
  59. virtual void notify_join (tree& ref, int pos, tree next);
  60. virtual void notify_var_join (tree& ref, tree t, int offset);
  61. virtual void notify_assign_node (tree& ref, tree_label op);
  62. virtual void notify_insert_node (tree& ref, int pos);
  63. virtual void notify_remove_node (tree& ref, int pos);
  64. virtual void notify_set_cursor (tree& ref, int pos, tree data);
  65. virtual void notify_detach (tree& ref, tree closest, bool right);
  66. // Extra routines for particular types of observers
  67. virtual bool get_ip (path& ip);
  68. virtual bool set_ip (path ip);
  69. virtual bool get_position (tree& t, int& index);
  70. virtual bool set_position (tree t, int index);
  71. virtual observer& get_child (int which);
  72. virtual list<observer> get_tree_pointers ();
  73. virtual bool get_tree (tree& t);
  74. virtual bool set_highlight (int lan, int col, int start, int end);
  75. virtual bool get_highlight (int lan, array<int>& cols);
  76. };
  77. class observer {
  78. public:
  79. ABSTRACT_NULL(observer);
  80. inline friend bool operator == (observer o1, observer o2) {
  81. return o1.rep == o2.rep; }
  82. inline friend bool operator != (observer o1, observer o2) {
  83. return o1.rep != o2.rep; }
  84. inline friend int hash (observer o1) {
  85. return hash ((pointer) o1.rep); }
  86. };
  87. ABSTRACT_NULL_CODE(observer);
  88. tm_ostream& operator << (tm_ostream& out, observer o);
  89. class editor_rep;
  90. class archiver_rep;
  91. extern observer nil_observer;
  92. observer ip_observer (path ip);
  93. observer list_observer (observer o1, observer o2);
  94. observer tree_pointer (tree t, bool flag= false);
  95. observer tree_position (tree t, int index);
  96. observer edit_observer (editor_rep* ed);
  97. observer undo_observer (archiver_rep* arch);
  98. observer highlight_observer (int lan, array<int> cols);
  99. /******************************************************************************
  100. * Modification routines for trees and other observer-related facilities
  101. ******************************************************************************/
  102. extern bool versioning_busy;
  103. bool busy_tree (tree& ref);
  104. void assign (tree& ref, tree t);
  105. void insert (tree& ref, int pos, tree t);
  106. void remove (tree& ref, int pos, int nr);
  107. void split (tree& ref, int pos, int at);
  108. void join (tree& ref, int pos);
  109. void assign_node (tree& ref, tree_label op);
  110. void insert_node (tree& ref, int pos, tree t);
  111. void remove_node (tree& ref, int pos);
  112. void set_cursor (tree& ref, int pos, tree data);
  113. void touch (tree& ref);
  114. void assign (path p, tree t);
  115. void insert (path p, tree ins);
  116. void remove (path p, int nr);
  117. void split (path p);
  118. void join (path p);
  119. void assign_node (path p, tree_label op);
  120. void insert_node (path p, tree ins);
  121. void remove_node (path p);
  122. void set_cursor (path p, tree data);
  123. void touch (path p);
  124. void insert_observer (observer& o, observer what);
  125. void remove_observer (observer& o, observer what);
  126. void attach_observer (tree& ref, observer o);
  127. void detach_observer (tree& ref, observer o);
  128. void clean_observers (tree& ref);
  129. path obtain_ip (tree& ref);
  130. void attach_ip (tree& ref, path ip);
  131. void detach_ip (tree& ref);
  132. bool ip_attached (path ip);
  133. tree obtain_tree (observer o);
  134. observer tree_pointer_new (tree t);
  135. void tree_pointer_delete (observer o);
  136. path obtain_position (observer o);
  137. observer search_observer (tree& ref, int type);
  138. bool admits_edit_observer (tree t);
  139. void attach_highlight (tree& ref, int lan);
  140. void attach_highlight (tree& ref, int lan, int col, int start, int end);
  141. bool has_highlight (tree& ref, int lan);
  142. array<int> obtain_highlight (tree& ref, int lan);
  143. void detach_highlight (tree& ref, int lan);
  144. void stretched_print (tree t, bool ips= false, int indent= 0);
  145. #endif // defined OBSERVER_H