// file: tr_mm_debug_0.cc
//
 
// isip include files
//
#include "train_memory_manager.h"
#include "train_memory_manager_constants.h"

#include <train_trace.h>
#include <train_lex_node.h>
#include <train_lattice_node.h>
#include <train_hash_cell.h>

// method: debug_cc
//
// arguments:
//  FILE* fp: (input) file pointer used for output
//  char_1* message: (input) a message concatenated to each debug message
//
// return: a logical_1 value indicating status
//
// this method displays the values of all internal data
//
logical_1 Train_Memory_manager::debug_cc(FILE* fp_a, char_1* message_a) {

  // dump memory count parameters
  //
  fprintf(fp_a, "%s::%s: node_count_d = %ld\n", TRAIN_MM_CLASS_NAME,
	  message_a, node_count_d);
  fprintf(fp_a, "%s::%s: trace_count_d = %ld\n", TRAIN_MM_CLASS_NAME,
	  message_a, trace_count_d);
  fprintf(fp_a, "%s::%s: lex_count_d = %ld\n", TRAIN_MM_CLASS_NAME,
	  message_a, lex_count_d);
  
  // dump memory block size parameters
  //
  fprintf(fp_a, "%s::%s: node_grow_size_d = %ld\n", TRAIN_MM_CLASS_NAME,
	  message_a, node_grow_size_d);
  fprintf(fp_a, "%s::%s: trace_grow_size_d = %ld\n", TRAIN_MM_CLASS_NAME,
	  message_a, trace_grow_size_d);
  fprintf(fp_a, "%s::%s: lex_grow_size_d = %ld\n", TRAIN_MM_CLASS_NAME,
	  message_a, lex_grow_size_d);
  
  // dump the data of the free links
  //
  Train_Link_node* node = node_list_d;
  while (node != (Train_Link_node*)NULL) {
    fprintf(fp_a, "%s::%s: node = %p\n", TRAIN_MM_CLASS_NAME, message_a, node);
    node->debug_cc(fp_a, message_a);
    node = node->get_next_cc();
  }
  
  // dump the data of the free traces
  //
  node = trace_list_d;
  Train_Trace* tr = (Train_Trace*)NULL;
  while (node != (Train_Link_node*)NULL) {
    tr = (Train_Trace*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", TRAIN_MM_CLASS_NAME, message_a, node);
    if (tr != (Train_Trace*)NULL) {
      tr->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }
  
  // dump the data of the free lex nodes
  //
  node = lex_list_d;
  Train_Lex_node* lxn = (Train_Lex_node*)NULL;
  while (node != (Train_Link_node*)NULL) {
    lxn = (Train_Lex_node*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", TRAIN_MM_CLASS_NAME, message_a, node);
    if (lxn != (Train_Lex_node*)NULL) {
      lxn->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }
  
  // dump the data of the free lat nodes
  //
  node = lat_list_d;
  Train_Lattice_node* ltn = (Train_Lattice_node*)NULL;
  while (node != (Train_Link_node*)NULL) {
    ltn = (Train_Lattice_node*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", TRAIN_MM_CLASS_NAME, message_a, node);
    if (ltn != (Train_Lattice_node*)NULL) {
      ltn->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }
  
  // dump the data of the free hash cells
  //
  node = hash_list_d;
  Train_Hash_cell* hcell = (Train_Hash_cell*)NULL;
  while (node != (Train_Link_node*)NULL) {
    hcell = (Train_Hash_cell*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", TRAIN_MM_CLASS_NAME, message_a, node);
    if (hcell != (Train_Hash_cell*)NULL) {
      hcell->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
