Browse Source

Properly maintain unique ID accross undo of deletion.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
c748c34cb6
5 changed files with 115 additions and 13 deletions
  1. +97
    -6
      Loggable.C
  2. +18
    -1
      Loggable.H
  3. +0
    -2
      Region.H
  4. +0
    -2
      Tempo_Point.H
  5. +0
    -2
      Time_Point.H

+ 97
- 6
Loggable.C View File

@@ -106,6 +106,68 @@ void free_sa ( char **sa )
free( sa );
}

/* void */
/* Loggable::redo ( const char *s ) */
/* { */
/* int id; */
/* sscanf( s, "%*s %X ", &id ); */
/* Loggable *l = find( id ); */
/* // assert( l ); */

/* char classname[40]; */
/* char command[40]; */
/* char *arguments; */

/* sscanf( s, "%s %*X %s %*[^\n<] << %a[^\n]", classname, command, &arguments ); */


/* int ui = _undo_index; */


/* if ( ! l ) */
/* { */
/* printf( "corrupt undo?\n" ); */
/* abort(); */
/* } */



/* if ( ! strcmp( command, "destroy" ) ) */
/* { */
/* char **sa = parse_alist( arguments ); */

/* if ( ! _class_map[ string( classname ) ] ) */
/* printf( "error class %s is unregistered!\n", classname ); */
/* else */
/* { */
/* /\* create *\/ */
/* Loggable *l = _class_map[ string( classname ) ]( sa ); */
/* l->update_id( id ); */
/* } */
/* } */
/* else */
/* if ( ! strcmp( command, "set" ) ) */
/* { */

/* printf( "got set command.\n" ); */

/* char **sa = parse_alist( arguments ); */

/* l->log_start(); */
/* l->set( sa ); */
/* l->log_end(); */

/* } */
/* else */
/* if ( ! strcmp( command, "create" ) ) */
/* { */
/* int id = l->id(); */
/* delete l; */
/* _loggables[ id ] = NULL; */
/* } */


/* } */

void
Loggable::undo ( void )
@@ -173,11 +235,11 @@ Loggable::undo ( void )
int ui = _undo_index;


if ( ! l )
{
printf( "corrupt undo?\n" );
abort();
}
/* if ( ! l ) */
/* { */
/* printf( "corrupt undo?\n" ); */
/* abort(); */
/* } */



@@ -188,7 +250,12 @@ Loggable::undo ( void )
if ( ! _class_map[ string( classname ) ] )
printf( "error class %s is unregistered!\n", classname );
else
_class_map[ string( classname ) ]( sa );
{
/* create */
Loggable *l = _class_map[ string( classname ) ]( sa );
l->update_id( id );
l->log_create();
}
}
else
if ( ! strcmp( command, "set" ) )
@@ -220,6 +287,30 @@ Loggable::undo ( void )
delete buf;
}

/** write a snapshot of the state of all loggable objects, sufficient
* for later reconstruction, to /file/ */
bool
Loggable::snapshot( const char *file )
{
FILE *ofp = _fp;

if ( ! ( _fp = fopen( file, "a" ) ) )
{
_fp = ofp;
return false;
}

for ( int i = 0; i < _log_id; ++i )
{
_loggables[ i ]->log_create();
}

fclose( _fp );

_fp = ofp;

return true;
}

void
Loggable::log ( const char *fmt, ... )


+ 18
- 1
Loggable.H View File

@@ -75,6 +75,7 @@ public:
static bool open ( const char *filename );
static void undo ( void );
static int undo_index ( void ) { return _undo_index; }
static bool snapshot( const char *file );

static
void
@@ -112,11 +113,26 @@ public:
_loggables.push_back( this );
}

virtual ~Loggable ( )
/** must be called after construction in create() methods */
void
update_id ( int id )
{
assert( _id == _log_id );

_loggables[ _id - 1 ] = NULL;

--_log_id;

_id = id;

assert( ! _loggables[ _id - 1 ] );

_loggables[ _id - 1 ] = this;
}

virtual ~Loggable ( )
{
_loggables[ _id - 1 ] = NULL;
}

static
@@ -148,6 +164,7 @@ public:

int id ( void ) { return _id; }


friend class Logger;
};



+ 0
- 2
Region.H View File

@@ -156,8 +156,6 @@ public:

r->set( sa );

r->log_create();

return (Loggable *)r;
}



+ 0
- 2
Tempo_Point.H View File

@@ -111,8 +111,6 @@ public:

r->set( sa );

r->log_create();

return (Loggable *)r;
}



+ 0
- 2
Time_Point.H View File

@@ -130,8 +130,6 @@ public:

r->set( sa );

r->log_create();

return (Loggable *)r;
}



Loading…
Cancel
Save