Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes | Protected Attributes
bridge_docrange_rep Class Reference
Inheritance diagram for bridge_docrange_rep:
Inheritance graph
[legend]
Collaboration diagram for bridge_docrange_rep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 bridge_docrange_rep (typesetter ttt, tree st, path ip, array< bridge > &brs, int begin, int end, bool divide)
void rebalance ()
void notify_assign (path p, tree u)
void notify_insert (path p, tree u)
void notify_remove (path p, int nr)
bool notify_macro (int type, string var, int l, path p, tree u)
void notify_change ()
void my_exec_until (path p)
bool my_typeset_will_be_complete ()
void my_typeset (int desired_status)
virtual void notify_split (path p)
virtual void notify_join (path p)
virtual void my_clean_links ()
virtual void exec_until (path p, bool skip_flag=false)
void typeset (int desired_status)

Public Attributes

typesetter ttt
edit_envenv
tree st
path ip
int status
hashmap< string, treechanges
array< page_iteml
stack_border sb
link_repository link_env
int ref_count

Protected Attributes

array< bridgeacc
array< bridge > & brs
array< int > mid
int begin
int end
bool divide

Detailed Description

Definition at line 28 of file bridge_docrange.cpp.


Constructor & Destructor Documentation

bridge_docrange_rep::bridge_docrange_rep ( typesetter  ttt,
tree  st,
path  ip,
array< bridge > &  brs,
int  begin,
int  end,
bool  divide 
)

Definition at line 60 of file bridge_docrange.cpp.

                                     :
    bridge_rep (ttt, st, ip), brs (brs2),
    begin (begin2), end (end2), divide (divide2)
{
  if (divide) {
    int i, n= ((end - begin - 1) / ACC_THRESHOLD) + 1;
    acc= array<bridge> (n);
    mid= array<int> (n+1);
    for (i=0; i<n; i++) {
      mid[i]  = begin + i * ACC_THRESHOLD;
      mid[i+1]= min (mid[i] + ACC_THRESHOLD, end);
      acc[i]  = bridge_docrange (ttt, st, ip, brs, mid[i], mid[i+1]);
    }
  }
}

Here is the call graph for this function:


Member Function Documentation

void bridge_rep::exec_until ( path  p,
bool  skip_flag = false 
) [virtual, inherited]

Reimplemented in bridge_auto_rep.

Definition at line 254 of file bridge.cpp.

                                              {
  // This virtual routine is redefined in bridge_auto in order to
  // treat cursor positions on the border in a special way depending
  // on skip_flag

  (void) skip_flag;
  // cout << "Exec until " << p << " in " << st << "\n";
  if ((status & VALID_MASK) != PROCESSED) {
    // cout << "  Re-execute until\n";
    env->exec_until (st, p);
  }
  else if (p == path (right_index (st))) {
    // cout << "  Patch env\n";
    env->patch_env (changes);
  }
  else if (p != path (0)) {
    // cout << "  My execute until\n";
    my_exec_until (p);
  }
  // cout << "  Done\n";
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bridge_rep::my_clean_links ( ) [virtual, inherited]

Reimplemented in bridge_surround_rep.

Definition at line 231 of file bridge.cpp.

                            {
  link_env= link_repository (true);
}

Here is the caller graph for this function:

Reimplemented from bridge_rep.

Definition at line 222 of file bridge_docrange.cpp.

                                          {
  if (p->item < begin);
  else if ((p->item >= end) && ((status & VALID_MASK) == PROCESSED))
    env->patch_env (changes);
  else if (divide) {
    int i, n= N(acc);
    for (i=0; i<n; i++)
      acc[i]->my_exec_until (p);
  }
  else {
    int i;
    for (i=begin; i<p->item; i++)
      brs[i]->exec_until (path (right_index (brs[i]->st)), true);
    if (p->item < end) brs[i]->exec_until (p->next);
  }
}

Here is the call graph for this function:

void bridge_docrange_rep::my_typeset ( int  desired_status) [virtual]

Reimplemented from bridge_rep.

Definition at line 254 of file bridge_docrange.cpp.

                                                   {
  int i, n= N(acc);
  array<line_item> a= ttt->a;
  array<line_item> b= ttt->b;
  if (divide) {
    for (i=0; i<n; i++) {
      int wanted= (i==n-1? desired_status & WANTED_MASK: WANTED_PARAGRAPH);
      ttt->a= (i==0  ? a: array<line_item> ());
      ttt->b= (i==n-1? b: array<line_item> ());
      acc[i]->typeset (PROCESSED+ wanted);
    }
  }
  else {
    //bool show= top_level;
    //bool old_top_level= top_level;
    //top_level= false;
    //if (show) cout << "Typeset range: " << begin << " -- " << end << "\n  ";
    for (i=begin; i<end; i++) {
      int wanted= (i==end-1? desired_status & WANTED_MASK: WANTED_PARAGRAPH);
      ttt->a= (i==0    ? a: array<line_item> ());
      ttt->b= (i==end-1? b: array<line_item> ());
      //if (show) cout << (brs[i]->status == PROCESSED + wanted);
      //if (show) cout.flush ();
      brs[i]->typeset (PROCESSED+ wanted);
    }
    //if (show) cout << "\n";
    //top_level= old_top_level;
  }
}

Here is the call graph for this function:

Reimplemented from bridge_rep.

Definition at line 240 of file bridge_docrange.cpp.

                                                  {
  int i, n= N(acc);
  if (divide)
    for (i=0; i<n; i++)
      if (!acc[i]->my_typeset_will_be_complete ()) return false;
  else
    for (i=begin; i<end; i++)
      if (!brs[i]->my_typeset_will_be_complete ()) return false;
  return true;
}

Here is the call graph for this function:

void bridge_docrange_rep::notify_assign ( path  p,
tree  u 
) [virtual]

Implements bridge_rep.

Definition at line 130 of file bridge_docrange.cpp.

                                                  {
  ASSERT (!is_nil (p), "erroneous nil path");
  if (divide) {
    int i, n= N(acc);
    for (i=0; i<n; i++)
      if ((p->item >= mid[i]) && (p->item < mid[i+1]))
       acc[i]->notify_assign (p, u);
  }
  status= CORRUPTED;
}

Here is the call graph for this function:

Implements bridge_rep.

Definition at line 209 of file bridge_docrange.cpp.

                                    {
  status= CORRUPTED;
  if (divide) {
    acc[0]->notify_change ();
    if (N(acc)>1) acc[N(acc)-1]->notify_change ();
  }
}

Here is the call graph for this function:

void bridge_docrange_rep::notify_insert ( path  p,
tree  u 
) [virtual]

Reimplemented from bridge_rep.

Definition at line 142 of file bridge_docrange.cpp.

                                                  {
  // cout << "Notify insert " << p << ", " << N(u)
  //      << " [ " << begin << "--" << end << " ]\n";
  ASSERT (!is_nil (p), "erroneous nil path");
  if (p->item > end) {
    cerr << "\nNotify insert " << u << " at " << p << "\n";
    FAILED ("out of range");
  }
  if (p->item >= begin) status= CORRUPTED;
  else begin += N(u);
  end += N(u);

  if (divide) {
    int i, n= N(acc);
    for (i=0; i<n; i++)
      if (p->item < mid[i+1])
       break;
    if (i==n) i--;
    for (; i<n; i++) {
      acc[i]->notify_insert (p, u);
      mid[i+1] += N(u);
    }
    // cout << "mid[ins,0]= " << mid << "\n";
    rebalance ();
    // cout << "mid[ins,1]= " << mid << "\n";
  }
}

Here is the call graph for this function:

void bridge_rep::notify_join ( path  p) [virtual, inherited]

Definition at line 208 of file bridge.cpp.

                               {
  // cout << "Join " << p << " in " << st << "\n";
  path q  = path_up (p);
  int  pos= last_item (p);
  tree t  = subtree (st, q);

  if (is_atomic (t[pos]) && is_atomic (t[pos+1])) {
    string j= t[pos]->label * t[pos+1]->label;
    notify_remove (q * pos, 1);
    notify_assign (q * pos, j);
  }
  else {
    tree j= t[pos] * t[pos+1];
    notify_remove (q * pos, 1);
    notify_assign (q * pos, j);
  }
}

Here is the call graph for this function:

bool bridge_docrange_rep::notify_macro ( int  type,
string  var,
int  l,
path  p,
tree  u 
) [virtual]

Implements bridge_rep.

Definition at line 202 of file bridge_docrange.cpp.

                                                                            {
  (void) type; (void) v; (void) l; (void) p; (void) u;
  FAILED ("method should never be called");
  return false;
}
void bridge_docrange_rep::notify_remove ( path  p,
int  nr 
) [virtual]

Reimplemented from bridge_rep.

Definition at line 171 of file bridge_docrange.cpp.

                                                  {
  // cout << "Notify insert " << p << ", " << nr
  //      << " [ " << begin << "--" << end << " ]\n";
  ASSERT (!is_nil (p), "erroneous nil path");
  ASSERT (p->item < end, "out of range");
  if (p->item + nr > begin) {
    status= CORRUPTED;
    begin= min (begin , p->item);
    end  = max (end-nr, p->item);
  }
  else {
    begin -= nr;
    end   -= nr;
  }

  if (divide) {
    int i, n= N(acc);
    for (i=0; i<n; i++)
      if (p->item < mid[i+1])
       break;
    for (; i<n; i++) {
      acc[i]->notify_remove (p, nr);
      mid[i+1]= max (mid[i+1]-nr, p->item);
    }
    // cout << "mid[rem,0]= " << mid << "\n";
    rebalance ();
    // cout << "mid[rem,1]= " << mid << "\n";
  }
}

Here is the call graph for this function:

void bridge_rep::notify_split ( path  p) [virtual, inherited]

Definition at line 188 of file bridge.cpp.

                                {
  // cout << "Split " << p << " in " << st << "\n";
  path q  = path_up (p, 2);
  int  pos= last_item (path_up (p));
  int  l  = last_item (p);
  tree t  = subtree (st, q);

  if (is_atomic (t[pos])) {
    string s1= t[pos]->label (0, l), s2= t[pos]->label (l, N (t[pos]->label));
    notify_insert (q * pos, tree (L(t), s1));
    notify_assign (q * (pos+1), s2);
  }
  else {
    tree t1= t[pos] (0, l), t2= t[pos] (l, N(t[pos]));
    notify_insert (q * pos, tree (L(t), t1));
    notify_assign (q * (pos+1), t2);
  }
}

Here is the call graph for this function:

Definition at line 79 of file bridge_docrange.cpp.

                                {
  int i, n= N(acc);
  array<bridge> acc2;
  array<int>    mid2;

  for (i=0; i<n; i++) {
    // Compactify?
    if ((i < n-1) && ((mid[i+2] == mid[i+1]) ||
                    (mid[i+2] - mid[i] <= ACC_THRESHOLD)))
      {
       int start= i;
       while ((i < n-1) && ((mid[i+2] == mid[start+1]) ||
                          (mid[i+2] - mid[start] <= ACC_THRESHOLD))) i++;
       // cout << "  Compactify " << i-start << " at " << start << ", ";
       // if (mid[i+1] == mid[start+1]) cout << "suppress\n";
       // else cout << "compress\n";
       if (mid[i+1] == mid[start+1]) acc2 << acc[start];
       else acc2 << bridge_docrange (ttt, st, ip, brs, mid[start], mid[i+1]);
       mid2 << mid[start];
      }
    
    // Expand?
    else if (mid[i+1] - mid[i] > (7 * ACC_THRESHOLD / 4)) {
      int j, k= (mid[i+1] - mid[i] - 1) / ACC_THRESHOLD + 1;
      // cout << "  Expand " << k << " at " << i << "\n";
      for (j=0; j<k; j++) {
       int b= mid[i] + j * ACC_THRESHOLD;
       int e= min (b + ACC_THRESHOLD, mid[i+1]);
       acc2 << bridge_docrange (ttt, st, ip, brs, b, e);
       mid2 << b;
      }
    }
    
    // OK
    else {
      acc2 << acc[i];
      mid2 << mid[i];
    }
  }

  mid2 << end;
  // if (mid2 != mid) cout << mid << " -> " << mid2 << "\n";
  acc= acc2;
  mid= mid2;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bridge_rep::typeset ( int  desired_status) [inherited]

Definition at line 279 of file bridge.cpp.

                                       {
  // FIXME: this dirty hack ensures a perfect coherence between
  // the bridge and the edit tree at the typesetting stage.
  // This should not be necessary, but we use because the ip_observers
  // may become wrong otherwise.
  if (is_accessible (ip))
    st= subtree (the_et, reverse (ip));
  if (!is_accessible (ip)) {
    path ip2= obtain_ip (st);
    if (ip2 != path (DETACHED))
      ip= ip2;
  }

  //cout << "Typesetting " << st << ", " << desired_status << LF << INDENT;
  if ((status==desired_status) && (N(ttt->old_patch)==0)) {
    //cout << "cached" << LF;
    env->monitored_patch_env (changes);
    // cout << "changes       = " << changes << LF;
  }
  else {
    // cout << "Typesetting " << st << ", " << desired_status << LF << INDENT;
    //cout << "recomputing" << LF;
    hashmap<string,tree> prev_back (UNINIT);
    my_clean_links ();
    link_repository old_link_env= env->link_env;
    env->link_env= link_env;
    ttt->local_start (l, sb);
    env->local_start (prev_back);
    if (env->hl_lan != 0) env->lan->highlight (st);
    my_typeset (desired_status);
    env->local_update (ttt->old_patch, changes);
    env->local_end (prev_back);
    ttt->local_end (l, sb);
    env->link_env= old_link_env;
    status= desired_status;
    // cout << "old_patch     = " << ttt->old_patch << LF;
    // cout << "changes       = " << changes << LF;
    // cout << UNINDENT << "Typesetted " << st << ", " << desired_status << LF;
  }
  //cout << UNINDENT << "Typesetted " << st << ", " << desired_status << LF;

  // ttt->insert_stack (l, sb);
  //if (N(l) == 0); else
  if (ttt->paper || (N(l) <= 1)) ttt->insert_stack (l, sb);
  else {
    bool flag= false;
    int i, n= N(l);
    for (i=0; i<n; i++)
      flag= flag || (N (l[i]->fl) != 0) || (l[i]->nr_cols > 1);
    if (flag) ttt->insert_stack (l, sb);
    else {
      int first=-1, last=-1;
      array<box> bs;
      array<SI>  spc;
      for (i=0; i<n; i++)
       if (l[i]->type != PAGE_CONTROL_ITEM) {
         if (first == -1 && l[i]->type == PAGE_LINE_ITEM) first= N(bs);
         bs  << l[i]->b;
         spc << l[i]->spc->def;
         last= i;
       }
      box lb= stack_box (path (ip), bs, spc);
      if (first != -1) lb= move_box (path (ip), lb, 0, bs[first]->y2);
      array<page_item> new_l (1);
      new_l[0]= page_item (lb);
      new_l[0]->spc= l[last]->spc;
      ttt->insert_stack (new_l, sb);
    }
  }

  //cout << "l   = " << l << LF;
  //cout << "sb  = " << sb << LF;
  //cout << "l   = " << ttt->l << LF;
  //cout << "a   = " << ttt->a << LF;
  //cout << "b   = " << ttt->b << LF;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 30 of file bridge_docrange.cpp.

int bridge_docrange_rep::begin [protected]

Definition at line 33 of file bridge_docrange.cpp.

Definition at line 31 of file bridge_docrange.cpp.

Definition at line 42 of file bridge.hpp.

bool bridge_docrange_rep::divide [protected]

Definition at line 34 of file bridge_docrange.cpp.

int bridge_docrange_rep::end [protected]

Definition at line 33 of file bridge_docrange.cpp.

edit_env& bridge_rep::env [inherited]

Definition at line 38 of file bridge.hpp.

path bridge_rep::ip [inherited]

Definition at line 40 of file bridge.hpp.

Definition at line 44 of file bridge.hpp.

Definition at line 46 of file bridge.hpp.

array<int> bridge_docrange_rep::mid [protected]

Definition at line 32 of file bridge_docrange.cpp.

int abstract_struct::ref_count [inherited]

Definition at line 142 of file basic.hpp.

Definition at line 45 of file bridge.hpp.

tree bridge_rep::st [inherited]

Definition at line 39 of file bridge.hpp.

int bridge_rep::status [inherited]

Definition at line 41 of file bridge.hpp.

Definition at line 37 of file bridge.hpp.


The documentation for this class was generated from the following file: