next up previous contents
Next: The Print/ Grab Code: Up: CHAR_DL_CELL Source: Previous: CHAR_DL_CELL Source:

The Constructor/Destructor Code:

    // ***************************************************** //
    // Explicit constructor for CHAR_DL_CELL class           //
    // ***************************************************** // 
CHAR_DL_CELL::CHAR_DL_CELL(char *name_in)
{
  if(SCREEN_DIAGNOSTIC)
  cout << "In explict CHAR_DL_CELL<" << name << "> constructor." << endl;
  name = new char[strlen(name_in)+1];
  strcpy(name,name_in);
  previous = NULL;
  next = NULL;
  if(SCREEN_DIAGNOSTIC)
  cout << "Exit explict CHAR_DL_CELL<" << name << "> constructor." << endl;
}
    // ********************************************** //
    // destructor for CHAR_DL_CELL<class TYPE> class       //
    // ********************************************** //
 
CHAR_DL_CELL::~CHAR_DL_CELL()
{
  static int count = -2;
  static int reset = 0;
  if(SCREEN_DIAGNOSTIC){
    for(int j=0;j<(count+2)*2;++j)
      cout << " ";
    cout << "In CHAR_DL_CELL<" << name << "> destructor: ~previous." << endl;
    }
  if(previous!=NULL){
    if(SCREEN_DIAGNOSTIC){
      for(int j=0;j<(count+2)*2;++j)
        cout << " ";
      cout << "  Calling destructor: ~previous." << endl;
      }
    count++;
    if(name!=NULL){
      delete [] name;
      }
    if(next!=NULL)
      delete next;
    }
  if(reset==0 && previous==NULL){ 
    if(SCREEN_DIAGNOSTIC){
      for(int j=0;j<(count+2)*2;++j)
        cout << " ";
      cout << "Exit CHAR_DL_CELL<" << name << "> destructor: ~previous." << endl;
      }
    reset = 1;
    } 
  if(reset==1 && previous==NULL){
    count = -2;
    if(SCREEN_DIAGNOSTIC){
      for(int j=0;j<(count+2)*2;++j)
        cout << " ";
      cout << "Exit CHAR_DL_CELL<" << name << "> destructor: ~previous." << endl;
      }
    }
}

Ughh! This is really messy diagnostic code. The stripped down version is a lot easier to follow and indeed is the same as the destructor code for the ChAR_SL_CELL's.

    // *************************************** //
    // destructor for CHAR_DL_CELL class       //
    // *************************************** //
 
CHAR_DL_CELL::~CHAR_DL_CELL()
{
  if(name!=NULL){
    delete [] name;
    }
  if(next!=NULL)
    delete next;
}



Jim Peterson
1999-04-22