Back to index

texmacs  1.0.7.15
bridge_default.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : bridge_default.cpp
00004 * DESCRIPTION: Bridge between logical and physically typesetted fragments
00005 * COPYRIGHT  : (C) 1999  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 #include "bridge.hpp"
00013 
00014 class bridge_default_rep: public bridge_rep {
00015 public:
00016   bridge_default_rep (typesetter ttt, tree st, path ip);
00017 
00018   void notify_assign (path p, tree u);
00019   bool notify_macro  (int type, string var, int l, path p, tree u);
00020   void notify_change ();
00021 };
00022 
00023 bridge_default_rep::bridge_default_rep (typesetter ttt, tree st, path ip):
00024   bridge_rep (ttt, st, ip) {}
00025 
00026 bridge
00027 bridge_default (typesetter ttt, tree st, path ip) {
00028   return tm_new<bridge_default_rep> (ttt, st, ip);
00029 }
00030 
00031 /******************************************************************************
00032 * Subroutines for event notification
00033 ******************************************************************************/
00034 
00035 tree
00036 substitute (tree t, path p, tree u) {
00037   if (is_nil (p)) return u;
00038   int i, n= N(t);
00039   tree t2 (t, n);
00040   for (i=0; i<n; i++) {
00041     if (i == p->item) t2[i]= substitute (t[i], p->next, u);
00042     else t2[i]= t[i];
00043   }
00044   return t2;
00045 }
00046 
00047 tree
00048 insert_at (tree t, path p, tree u) {
00049   if (is_atom (p)) {
00050     if (is_atomic (t)) {
00051       ASSERT (is_atomic (u), "two atoms expected");
00052       return t->label (0, p->item) *u->label* t->label (p->item, N(t->label));
00053     }
00054     else return (t (0, p->item) * u) * t (p->item, N(t));
00055   }
00056   else return substitute (t, p->item, insert_at (t[p->item], p->next, u));
00057 }
00058 
00059 tree
00060 remove_at (tree t, path p, int nr) {
00061   if (is_atom (p)) {
00062     if (is_atomic (t))
00063       return t->label (0, p->item) * t->label (p->item+nr, N(t->label));
00064     else return t (0, p->item) * t (p->item+nr, N(t));
00065   }
00066   else return substitute (t, p->item, remove_at (t[p->item], p->next, nr));
00067 }
00068 
00069 /******************************************************************************
00070 * Event notification
00071 ******************************************************************************/
00072 
00073 void
00074 bridge_default_rep::notify_assign (path p, tree u) {
00075   // cout << "Assign " << p << ", " << u << " in " << st << "\n";
00076   status= CORRUPTED;
00077   st= substitute (st, p, u);
00078 }
00079 
00080 bool
00081 bridge_default_rep::notify_macro (int tp, string var, int l, path p, tree u) {
00082   (void) tp; (void) p; (void) u;
00083   bool flag= env->depends (st, var, l);
00084   if (flag) status= CORRUPTED;
00085   return flag;
00086 }
00087 
00088 void
00089 bridge_default_rep::notify_change () {
00090   status= CORRUPTED;
00091 }