// file: mm_debug_0.cc
//
 
// isip include files
//
#include "memory_manager.h"
#include "memory_manager_constants.h"

#include <trace.h>
#include <lex_node.h>
#include <lattice_node.h>
#include <lattice_path.h>
#include <ngram_node.h>
#include <hash_cell.h>
#include <history.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 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", MM_CLASS_NAME,
	  message_a, node_count_d);
  fprintf(fp_a, "%s::%s: trace_count_d = %ld\n", MM_CLASS_NAME,
	  message_a, trace_count_d);
  fprintf(fp_a, "%s::%s: lex_count_d = %ld\n", MM_CLASS_NAME,
	  message_a, lex_count_d);
  fprintf(fp_a, "%s::%s: lat_count_d = %ld\n", MM_CLASS_NAME,
	  message_a, lat_count_d);
  fprintf(fp_a, "%s::%s: lpath_count_d = %ld\n", MM_CLASS_NAME,
	  message_a, lpath_count_d);
  fprintf(fp_a, "%s::%s: ngram_count_d = %ld\n", MM_CLASS_NAME,
	  message_a, ngram_count_d);
  fprintf(fp_a, "%s::%s: hash_count_d = %ld\n", MM_CLASS_NAME,
	  message_a, hash_count_d);
  fprintf(fp_a, "%s::%s: hist_count_d = %ld\n", MM_CLASS_NAME,
	  message_a, hist_count_d);
  fprintf(fp_a, "%s::%s: instance_count_d = %ld\n", MM_CLASS_NAME,
	  message_a, instance_count_d);
  
  // dump total memory count parameters
  //
  fprintf(fp_a, "%s::%s: num_node_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_node_d);
  fprintf(fp_a, "%s::%s: num_trace_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_trace_d);
  fprintf(fp_a, "%s::%s: num_lex_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_lex_d);
  fprintf(fp_a, "%s::%s: num_lat_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_lat_d);
  fprintf(fp_a, "%s::%s: num_lpath_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_lpath_d);
  fprintf(fp_a, "%s::%s: num_ngram_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_ngram_d);
  fprintf(fp_a, "%s::%s: num_hash_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_hash_d);
  fprintf(fp_a, "%s::%s: num_hist_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_hist_d);
  fprintf(fp_a, "%s::%s: num_instance_d = %ld\n", MM_CLASS_NAME,
	  message_a, num_instance_d);
  
  // dump memory block size parameters
  //
  fprintf(fp_a, "%s::%s: node_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, node_grow_size_d);
  fprintf(fp_a, "%s::%s: trace_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, trace_grow_size_d);
  fprintf(fp_a, "%s::%s: lex_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, lex_grow_size_d);
  fprintf(fp_a, "%s::%s: lat_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, lat_grow_size_d);
  fprintf(fp_a, "%s::%s: lpath_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, lpath_grow_size_d);
  fprintf(fp_a, "%s::%s: ngram_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, ngram_grow_size_d);
  fprintf(fp_a, "%s::%s: hash_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, hash_grow_size_d);
  fprintf(fp_a, "%s::%s: hist_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, hist_grow_size_d);
  fprintf(fp_a, "%s::%s: instance_grow_size_d = %ld\n", MM_CLASS_NAME,
	  message_a, instance_grow_size_d);
  
  // dump the data of the free links
  //
  Link_node* node = node_list_d;
  while (node != (Link_node*)NULL) {
    fprintf(fp_a, "%s::%s: node = %p\n", 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;
  Trace* tr = (Trace*)NULL;
  while (node != (Link_node*)NULL) {
    tr = (Trace*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", MM_CLASS_NAME, message_a, node);
    if (tr != (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;
  Lex_node* lxn = (Lex_node*)NULL;
  while (node != (Link_node*)NULL) {
    lxn = (Lex_node*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", MM_CLASS_NAME, message_a, node);
    if (lxn != (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;
  Lattice_node* ltn = (Lattice_node*)NULL;
  while (node != (Link_node*)NULL) {
    ltn = (Lattice_node*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", MM_CLASS_NAME, message_a, node);
    if (ltn != (Lattice_node*)NULL) {
      ltn->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }
  
  // dump the data of the free lat nodes
  //
  node = lpath_list_d;
  Lattice_path* lpth = (Lattice_path*)NULL;
  while (node != (Link_node*)NULL) {
    lpth = (Lattice_path*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", MM_CLASS_NAME, message_a, node);
    if (lpth != (Lattice_path*)NULL) {
      lpth->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }
  
  // dump the data of the free ngram nodes
  //
  node = ngram_list_d;
  Ngram_node* ngn = (Ngram_node*)NULL;
  while (node != (Link_node*)NULL) {
    ngn = (Ngram_node*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", MM_CLASS_NAME, message_a, node);
    if (ngn != (Ngram_node*)NULL) {
      ngn->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }
  
  // dump the data of the free hash cells
  //
  node = hash_list_d;
  Hash_cell* hcell = (Hash_cell*)NULL;
  while (node != (Link_node*)NULL) {
    hcell = (Hash_cell*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", MM_CLASS_NAME, message_a, node);
    if (hcell != (Hash_cell*)NULL) {
      hcell->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }

  // dump the data of the free history nodes
  //
  node = hist_list_d;
  History* hist = (History*)NULL;
  while (node != (Link_node*)NULL) {
    hist = (History*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", MM_CLASS_NAME, message_a, node);
    if (hist != (History*)NULL) {
      hist->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }

  // dump the data of the free instance nodes
  //
  node = instance_list_d;
  Instance* inst = (Instance*)NULL;
  while (node != (Link_node*)NULL) {
    inst = (Instance*)(node->get_item_cc());
    fprintf(fp_a, "%s::%s: node = %p\n", MM_CLASS_NAME, message_a, node);
    if (inst != (Instance*)NULL) {
      inst->debug_cc(fp_a, message_a);
    }
    node = node->get_next_cc();
  }

  // exit gracefully
  //
  return ISIP_TRUE;
}
