"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Data/Observers/tree_addendum.cpp" between
TeXmacs-1.99.4-src.tar.gz and TeXmacs-1.99.5-src.tar.gz

About: GNU TeXmacs is a what-you-see-is-what-you-get scientific text editor, which was both inspired by TeX and GNU Emacs.

tree_addendum.cpp  (TeXmacs-1.99.4-src):tree_addendum.cpp  (TeXmacs-1.99.5-src)
skipping to change at line 16 skipping to change at line 16
******************************************************************************* *******************************************************************************
* An inverse path observer maintains the inverse path of the position * An inverse path observer maintains the inverse path of the position
* of the corresponding tree with respect to the global meta-tree. * of the corresponding tree with respect to the global meta-tree.
******************************************************************************* *******************************************************************************
* This software falls under the GNU general public license version 3 or later. * This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/ ******************************************************************************/
#include "tree.hpp" #include "tree.hpp"
#include "list.hpp"
#include "blackbox.hpp" #include "blackbox.hpp"
/****************************************************************************** /******************************************************************************
* Definition of the tree_pointer_rep class * Definition of the tree_pointer_rep class
******************************************************************************/ ******************************************************************************/
class tree_addendum_rep: public observer_rep { class tree_addendum_rep: public observer_rep {
private: private:
tree_rep* ptr; tree_rep* ptr;
int kind; int kind;
blackbox contents; blackbox contents;
bool keep;
public: public:
tree_addendum_rep (tree ref, int kind2, blackbox contents2): tree_addendum_rep (tree ref, int kind2, blackbox contents2, bool keep2):
ptr (ref.rep), kind (kind2), contents (contents2) {} ptr (ref.rep), kind (kind2), contents (contents2), keep (keep2) {}
int get_type () { return OBSERVER_ADDENDUM; } int get_type () { return OBSERVER_ADDENDUM; }
tm_ostream& print (tm_ostream& out) { tm_ostream& print (tm_ostream& out) {
return out << " addendum (" << kind << ", " << contents << ")"; } return out << " addendum (" << kind << ", " << contents << ")"; }
void notify_assign (tree& ref, tree t); void notify_assign (tree& ref, tree t);
void notify_insert (tree& ref, int pos, int nr); void notify_insert (tree& ref, int pos, int nr);
void notify_remove (tree& ref, int pos, int nr); void notify_remove (tree& ref, int pos, int nr);
void notify_split (tree& ref, int pos, tree prev); void notify_split (tree& ref, int pos, tree prev);
void notify_var_split (tree& ref, tree t1, tree t2); void notify_var_split (tree& ref, tree t1, tree t2);
void notify_join (tree& ref, int pos, tree next); void notify_join (tree& ref, int pos, tree next);
skipping to change at line 74 skipping to change at line 76
tree_addendum_rep::get_tree (tree& t) { tree_addendum_rep::get_tree (tree& t) {
t= tree (ptr); t= tree (ptr);
return true; return true;
} }
bool bool
tree_addendum_rep::set_tree (tree t) { tree_addendum_rep::set_tree (tree t) {
if (ptr != t.rep) { if (ptr != t.rep) {
tree ref (ptr); tree ref (ptr);
remove_observer (ref->obs, observer (this)); remove_observer (ref->obs, observer (this));
ptr= t.rep; if (keep) {
insert_observer (t->obs, observer (this)); ptr= t.rep;
insert_observer (t->obs, observer (this));
}
// FIXME: if !keep, then is it safe to not reinsert the observer?
} }
return true; return true;
} }
/****************************************************************************** /******************************************************************************
* Call back routines for modifications * Call back routines for modifications
******************************************************************************/ ******************************************************************************/
void void
tree_addendum_rep::notify_assign (tree& ref, tree t) { tree_addendum_rep::notify_assign (tree& ref, tree t) {
skipping to change at line 141 skipping to change at line 146
void void
tree_addendum_rep::notify_assign_node (tree& ref, tree_label op) { tree_addendum_rep::notify_assign_node (tree& ref, tree_label op) {
// cout << "Notify assign node " << ref << ", " << as_string (op) << "\n"; // cout << "Notify assign node " << ref << ", " << as_string (op) << "\n";
(void) ref; (void) op; (void) ref; (void) op;
// cout << "position -> " << obtain_position (observer (this)) << "\n"; // cout << "position -> " << obtain_position (observer (this)) << "\n";
} }
void void
tree_addendum_rep::notify_insert_node (tree& ref, int pos) { tree_addendum_rep::notify_insert_node (tree& ref, int pos) {
//cout << "Notify insert node " << ref << ", " << pos << "\n"; //cout << "Notify insert node " << ref << ", " << pos << "\n";
// NOTE: we might want to remove these lines; see tree_pointer.cpp // NOTE: should we remove the 'false'? see also tree_pointer.cpp
remove_observer (ref[pos]->obs, observer (this)); if (keep && false) {
ptr= ref.rep; remove_observer (ref[pos]->obs, observer (this));
insert_observer (ref->obs, observer (this)); ptr= ref.rep;
insert_observer (ref->obs, observer (this));
}
//cout << "position -> " << obtain_position (observer (this)) << "\n"; //cout << "position -> " << obtain_position (observer (this)) << "\n";
} }
void void
tree_addendum_rep::notify_remove_node (tree& ref, int pos) { tree_addendum_rep::notify_remove_node (tree& ref, int pos) {
// cout << "Notify remove node " << ref << ", " << pos << "\n"; // cout << "Notify remove node " << ref << ", " << pos << "\n";
(void) set_tree (ref[pos]); (void) set_tree (ref[pos]);
// cout << "position -> " << obtain_position (observer (this)) << "\n"; // cout << "position -> " << obtain_position (observer (this)) << "\n";
} }
skipping to change at line 168 skipping to change at line 175
(void) right; (void) ref; (void) right; (void) ref;
(void) set_tree (closest); (void) set_tree (closest);
// cout << "position -> " << obtain_position (observer (this)) << "\n"; // cout << "position -> " << obtain_position (observer (this)) << "\n";
} }
/****************************************************************************** /******************************************************************************
* Public interface * Public interface
******************************************************************************/ ******************************************************************************/
observer observer
tree_addendum (tree ref, int kind, blackbox contents) { tree_addendum (tree ref, int kind, blackbox contents, bool keep) {
return tm_new<tree_addendum_rep> (ref, kind, contents); return tm_new<tree_addendum_rep> (ref, kind, contents, keep);
} }
observer observer
tree_addendum_new (tree ref, int kind, blackbox contents) { tree_addendum_new (tree ref, int kind, blackbox contents, bool keep) {
observer obs= tree_addendum (ref, kind, contents); observer obs= tree_addendum (ref, kind, contents, keep);
attach_observer (ref, obs); attach_observer (ref, obs);
return obs; return obs;
} }
void void
tree_addendum_delete (observer obs) { tree_addendum_delete (observer obs) {
tree ref= obtain_tree (obs); tree ref= obtain_tree (obs);
detach_observer (ref, obs); detach_observer (ref, obs);
} }
bool
tree_addendum_delete (observer o, int type) {
if (is_nil (o)) return false;
if (o->get_type () == OBSERVER_ADDENDUM) {
blackbox bb;
bool ok= o->get_contents (type, bb);
if (!ok) return false;
tree_addendum_delete (o);
return true;
}
if (o->get_type () == OBSERVER_LIST)
return
tree_addendum_delete (o->get_child (0), type) ||
tree_addendum_delete (o->get_child (1), type);
return false;
}
void
tree_addendum_delete (tree t, int type) {
observer o= t->obs;
bool deleted= tree_addendum_delete (o, type);
if (deleted) tree_addendum_delete (t, type);
}
 End of changes. 8 change blocks. 
12 lines changed or deleted 19 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS