Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | Friends
archiver_rep Class Reference

#include <archiver.hpp>

Inheritance diagram for archiver_rep:
Inheritance graph
[legend]
Collaboration diagram for archiver_rep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 archiver_rep (double author, path rp)
 ~archiver_rep ()
void clear ()
void show_all ()
void add (modification m)
void start_slave (double a)
bool active ()
bool has_history ()
void cancel ()
void confirm ()
bool retract ()
bool forget ()
void forget_cursor ()
void simplify ()
int undo_possibilities ()
int redo_possibilities ()
path undo_one (int i)
path redo_one (int i)
path undo (int i=0)
path redo (int i=0)
void mark_start (double m)
bool mark_cancel (double m)
void mark_end (double m)
void require_save ()
void require_autosave ()
void notify_save ()
void notify_autosave ()
bool conform_save ()
bool conform_autosave ()

Public Attributes

int ref_count

Protected Member Functions

void apply (patch p)
void split (patch p1, patch p2, patch &re1, patch &re2)
patch make_future (patch p1, patch p2)
patch expose (patch archive)
void expose ()
void normalize ()
int corrected_depth ()

Private Attributes

patch archive
patch current
int depth
int last_save
int last_autosave
double the_author
double the_owner
path rp
observer undo_obs
bool versioning

Friends

void archive_announce (archiver_rep *arch, modification mod)
void global_clear_history ()
void global_confirm ()

Detailed Description

Definition at line 19 of file archiver.hpp.


Constructor & Destructor Documentation

archiver_rep::archiver_rep ( double  author,
path  rp 
)

Definition at line 28 of file archiver.cpp.

                                                  :
  archive (make_branches (0)),
  current (make_compound (0)),
  depth (0),
  last_save (0),
  last_autosave (0),
  the_author (author),
  the_owner (0),
  rp (rp2),
  undo_obs (undo_observer (this)),
  versioning (false)
{
  archs->insert ((pointer) this);
  attach_observer (subtree (the_et, rp), undo_obs);
  genuine_authors->insert (the_author);
}

Here is the call graph for this function:

Definition at line 45 of file archiver.cpp.

                             {
  genuine_authors->remove (the_author);
  detach_observer (subtree (the_et, rp), undo_obs);
  archs->remove ((pointer) this);
  pending_archs->remove ((pointer) this);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 290 of file archiver.cpp.

                      {
  return nr_children (current) != 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 264 of file archiver.cpp.

                                 {
  m= copy (m);
  if (the_owner != 0 && the_owner != get_author ()) {
    //cout << "Change " << the_owner << " -> " << get_author () << "\n";
    confirm ();
  }
  else the_owner= get_author ();
  modification i= invert (m, the_et);
  patch q (i, m);
  //cout << "Add [" << the_owner << "] " << q << "\n";
  current= patch (q, current);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void archiver_rep::apply ( patch  p) [protected]

Definition at line 172 of file archiver.cpp.

                            {
  // apply a patch, while disabling versioning during the modifications
  // cout << "Apply " << p << "\n";
  ASSERT (is_applicable (p, the_et), "invalid history");
  bool old= versioning;
  versioning= true;
  ::apply (p, the_et);
  versioning= old;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 300 of file archiver.cpp.

                      {
  if (active ()) {
    //cout << "Cancel " << current << "\n";
    apply (current);
    current= make_compound (0);
    the_owner= 0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 56 of file archiver.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 310 of file archiver.cpp.

                       {
  if (active ()) {
    current= patch (the_owner, compactify (current));
    if (nr_children (remove_set_cursor (current)) == 0)
      current= make_compound (0);
    if (active ()) {
      //cout << "Confirm " << current << "\n";
      archive= patch (current, archive);
      current= make_compound (0);
      the_owner= 0;
      depth++;
      if (depth <= last_save) last_save= -1;
      if (depth <= last_autosave) last_autosave= -1;
      normalize ();
      //show_all ();
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 617 of file archiver.cpp.

                                {
  return last_autosave == depth;
}

Definition at line 602 of file archiver.cpp.

                            {
  return last_save == corrected_depth ();
}

Here is the call graph for this function:

int archiver_rep::corrected_depth ( ) [protected]

Definition at line 581 of file archiver.cpp.

                               {
  // NOTE : fix depth due to presence of marker
  // FIXME: implement a more robust check for conformity with saved state
  if (nr_undo (archive) == 0) return depth;
  patch p= car (get_undo (archive));
  if (get_type (p) == PATCH_AUTHOR) p= p[0];
  if (get_type (p) == PATCH_BIRTH && get_birth (p) == false) return depth - 1;
  return depth;
}

Here is the call graph for this function:

Here is the caller graph for this function:

patch archiver_rep::expose ( patch  archive) [protected]

Definition at line 212 of file archiver.cpp.

                                   {
  if (nr_undo (archive) != 0 &&
      get_author (car (get_undo (archive))) != the_author &&
      nr_undo (cdr (get_undo (archive))) != 0)
    {
      patch nx1= expose (cdr (get_undo (archive)));
      if (get_author (car (get_undo (nx1))) != the_author) return archive;
      patch un1= car (get_undo (archive));
      patch un2= car (get_undo (nx1));
      patch re1= get_redo (archive);
      patch re2= get_redo (nx1);
      patch nx2= cdr (get_undo (nx1));
      patch fut= make_branches (0);
      if (nr_branches (re2) != 0) fut= make_future (un1, re2);
      if (!swap (un1, un2)) return archive;
      patch nx= make_history (patch (un2, nx2), make_branches (0));
      patch un= patch (un1, nx);
      patch re= append_branches (re1, fut);
      last_save= last_autosave= -1;
      return make_history (un, re);
    }
  else return archive;
}

Here is the call graph for this function:

void archiver_rep::expose ( ) [protected]

Definition at line 237 of file archiver.cpp.

Here is the caller graph for this function:

Definition at line 354 of file archiver.cpp.

                      {
  cancel ();
  bool r= retract ();
  if (r) cancel ();
  return r;
}

Here is the call graph for this function:

Definition at line 362 of file archiver.cpp.

Here is the call graph for this function:

Definition at line 295 of file archiver.cpp.

                           {
  return nr_undo (archive) == 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

patch archiver_rep::make_future ( patch  p1,
patch  p2 
) [protected]

Definition at line 202 of file archiver.cpp.

                                             {
  if (nr_branches (p2) == 0 || get_author (p1) == the_author)
    return patch (p1, p2);
  patch re1, re2;
  split (p1, p2, re1, re2);
  if (nr_branches (re1) != 0) re1= patch (p1, re1);
  return append_branches (re1, re2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool archiver_rep::mark_cancel ( double  m)

Definition at line 554 of file archiver.cpp.

                                   {
  //cout << "Mark cancel " << m << "\n";
  cancel ();
  while (nr_undo (archive) != 0) {
    expose ();
    if (is_marker (car (get_undo (archive)), m, false)) {
      archive= remove_marker (archive, m);
      depth--;
      simplify ();
      return true;
    }
    if (get_author (car (get_undo (archive))) != the_author) {
      archive= remove_marker (archive, m);
      depth--;
      return false;
    }
    retract ();
    cancel ();
  }
  return false;
}

Here is the call graph for this function:

void archiver_rep::mark_end ( double  m)

Definition at line 540 of file archiver.cpp.

                                {
  //cout << "Mark end " << m << "\n";
  if (active ()) {
    //if (does_modify (current))
    //  cout << "CONFIRM: " << current << "\n";
    confirm ();
  }
  archive= remove_marker (archive, m);
  depth--;
  simplify ();
  //show_all ();
}

Here is the call graph for this function:

void archiver_rep::mark_start ( double  m)

Definition at line 531 of file archiver.cpp.

                                  {
  //cout << "Mark start " << m << "\n";
  confirm ();
  start_slave (m);
  confirm ();
  //show_all ();
}

Here is the call graph for this function:

void archiver_rep::normalize ( ) [protected]

Definition at line 242 of file archiver.cpp.

                         {
  if (nr_undo (archive) != 0 && nr_redo (cdr (get_undo (archive))) != 0) {
    patch un1= get_undo (archive);
    patch re1= get_redo (archive);
    patch p1 = car (un1);
    patch nx1= cdr (un1);
    patch un2= get_undo (nx1);
    patch re2= get_redo (nx1);
    patch Re1, Re2;
    if (get_author (p1) == the_author) return;
    split (p1, re2, Re1, Re2);
    patch ar2= make_history (un2, Re1);
    archive= make_history (patch (p1, ar2), append_branches (re1, Re2));
    last_save= last_autosave= -1;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 612 of file archiver.cpp.

Definition at line 597 of file archiver.cpp.

Here is the call graph for this function:

path archiver_rep::redo ( int  i = 0)

Definition at line 483 of file archiver.cpp.

                         {
  if (active ()) return path ();
  path r;
  bool first= true;
  while (redo_possibilities () != 0) {
    ASSERT (i >= 0 && i < redo_possibilities (), "index out of range");
    patch re= branch (get_redo (archive), i);
    bool done= (get_author (car (re)) == the_author);
    r= redo_one (i);
    if (done && !first) break;
    if (nr_redo (archive) != 1) break;
    i= 0;
    first= false;
    re= branch (get_redo (archive), i);
    if (get_author (car (re)) == the_author) break;
    if (done && genuine_authors->contains (get_author (car (re)))) break;
  }
  return r;
}

Here is the call graph for this function:

Definition at line 437 of file archiver.cpp.

                             {
  if (active ()) return path ();
  int n= redo_possibilities ();
  if (n != 0) {
    ASSERT (i >= 0 && i < n, "index out of range");
    patch un= get_undo (archive);
    patch re= get_redo (archive);
    patch p= car (branch (re, i));
    //cout << "p= " << p << "\n";
    ASSERT (is_applicable (p, the_et), "future corrupted");
    patch q= invert (p, the_et);
    //cout << "q= " << q << "\n";
    apply (p);
    patch other= make_branches (append (branches (re, 0, i),
                                   branches (re, i+1, n)));
    //cout << "other= " << other << "\n";
    patch nx= make_history (un, other);
    archive= make_history (patch (q, nx), cdr (branch (re, i)));
    if (depth <= last_save && i != 0) last_save= -1;
    if (depth <= last_autosave && i != 0) last_autosave= -1;
    depth++;
    normalize ();
    //show_all ();
    return cursor_hint (q, the_et);
  }
  return path ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 410 of file archiver.cpp.

                                  {
  return nr_redo (archive);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 607 of file archiver.cpp.

                                {
  last_autosave= -1;
}

Definition at line 592 of file archiver.cpp.

                            {
  last_save= -1;
}

Definition at line 330 of file archiver.cpp.

                       {
  if (!has_history ()) return false;
  if (the_owner != 0 && the_owner != the_author) return false;
  expose ();
  patch un= car (get_undo (archive));
  if (get_author (un) != the_author) return false;
  patch re= get_redo (archive);
  patch nx= cdr (get_undo (archive));
  //cout << "Retract " << un << "\n";
  if (active ()) current= compactify (patch (current, un));
  else current= un;
  the_owner= the_author;
  if (nr_branches (re) != 0) {
    patch q= invert (current, the_et);
    re= patch (q, re);
  }
  if (nr_branches (nx) != 0) nx= get_undo (nx);
  archive= make_history (nx, append_branches (re, get_redo (nx)));
  depth--;
  //show_all ();
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 66 of file archiver.cpp.

                        {
  cout << HRULE << archive << LF << HRULE << LF;
}

Definition at line 371 of file archiver.cpp.

                        {
  if (has_history () &&
      nr_undo (cdr (get_undo (archive))) == 1 &&
      nr_redo (cdr (get_undo (archive))) == 0 &&
      depth != last_save + 1)
    {
      patch p1= car (get_undo (archive));
      patch p2= car (get_undo (cdr (get_undo (archive))));
      //cout << "p1= " << p1 << "\n";
      //cout << "p2= " << p2 << "\n";
      bool r= join (p1, p2, the_et);
      //cout << "pr= " << p1 << "\n";
      if (r) {
       //cout << "\n\nSimplify\n";
       //show_all ();
       patch un= patch (p1, cdr (get_undo (cdr (get_undo (archive)))));
       patch re= get_redo (archive);
       archive= make_history (un, re);
       //show_all ();
       //cout << "\n";
       if (depth == last_autosave + 1) last_autosave= -1;
       depth--;
       simplify ();
      }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void archiver_rep::split ( patch  p1,
patch  p2,
patch re1,
patch re2 
) [protected]

Definition at line 183 of file archiver.cpp.

                                                               {
  //cout << "p1= " << p1 << "\n";
  //cout << "p2= " << p2 << "\n";
  array<patch> a= branches (p2);
  array<patch> a1;
  array<patch> a2;
  for (int i=0; i<N(a); i++) {
    patch q1= p1;
    patch q2= car (a[i]);
    if (get_author (q2) != the_author || !swap (q1, q2)) a1 << a[i];
    else a2 << patch (q1, make_future (q2, cdr (a[i])));
  }
  re1= make_branches (a1);
  re2= make_branches (a2);
  //cout << "re1= " << re1 << "\n";
  //cout << "re2= " << re2 << "\n";
}

Here is the call graph for this function:

Here is the caller graph for this function:

void archiver_rep::start_slave ( double  a)

Definition at line 278 of file archiver.cpp.

                                   {
  if (the_owner != 0 && the_owner != get_author ()) {
    //cout << "Change " << the_owner << " -> " << get_author () << "\n";
    confirm ();
  }
  else the_owner= get_author ();
  patch q (a, false);
  //cout << "Add [" << the_owner << "] " << q << "\n";
  current= patch (q, current);
}

Here is the call graph for this function:

Here is the caller graph for this function:

path archiver_rep::undo ( int  i = 0)

Definition at line 466 of file archiver.cpp.

                         {
  if (active ()) return path ();
  path r;
  while (undo_possibilities () != 0) {
    ASSERT (i == 0, "index out of range");
    expose ();
    if (get_author (car (get_undo (archive))) == the_author)
      return undo_one (i);
    else {
      r= undo_one (i);
      i= 0;
    }
  }
  return r;
}

Here is the call graph for this function:

Definition at line 415 of file archiver.cpp.

                             {
  if (active ()) return path ();
  if (undo_possibilities () != 0) {
    ASSERT (i == 0, "index out of range");
    patch p= car (get_undo (archive));
    ASSERT (is_applicable (p, the_et), "history corrupted");
    patch q= invert (p, the_et);
    apply (p);
    patch re1= patch (q, get_redo (archive));
    patch nx = cdr (get_undo (archive));
    patch re2= get_redo (nx);
    patch re = append_branches (re1, re2);
    patch un = (nr_branches (nx) == 0? nx: get_undo (nx));
    archive= make_history (un, re);
    depth--;
    //show_all ();
    return cursor_hint (q, the_et);
  }
  return path ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 405 of file archiver.cpp.

                                  {
  return nr_undo (archive);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

void archive_announce ( archiver_rep arch,
modification  mod 
) [friend]

Definition at line 73 of file archiver.cpp.

                                                        {
  //cout << "Archive " << mod << "\n";
  if (DEBUG_HISTORY) cout << "Archive " << mod << "\n";
  ASSERT (arch->rp <= mod->p, "invalid modification");
  if (!arch->versioning) {
    arch->add (mod);
    pending_archs->insert ((pointer) arch);
  }
}
void global_clear_history ( ) [friend]

Definition at line 85 of file archiver.cpp.

                        {
  iterator<pointer> it = iterate (archs);
  while (it->busy()) {
    archiver_rep* arch= (archiver_rep*) it->next();
    arch->clear ();
  }
}
void global_confirm ( ) [friend]

Definition at line 94 of file archiver.cpp.

                  {
  iterator<pointer> it = iterate (pending_archs);
  while (it->busy()) {
    archiver_rep* arch= (archiver_rep*) it->next();
    arch->confirm ();
    arch->simplify ();
  }
  pending_archs= hashset<pointer> ();
}

Member Data Documentation

Definition at line 20 of file archiver.hpp.

Definition at line 21 of file archiver.hpp.

int archiver_rep::depth [private]

Definition at line 22 of file archiver.hpp.

Definition at line 24 of file archiver.hpp.

int archiver_rep::last_save [private]

Definition at line 23 of file archiver.hpp.

int concrete_struct::ref_count [inherited]

Definition at line 135 of file basic.hpp.

Definition at line 27 of file archiver.hpp.

double archiver_rep::the_author [private]

Definition at line 25 of file archiver.hpp.

double archiver_rep::the_owner [private]

Definition at line 26 of file archiver.hpp.

Definition at line 28 of file archiver.hpp.

bool archiver_rep::versioning [private]

Definition at line 29 of file archiver.hpp.


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