// file: memory_manager.h
//

// make sure definitions are only made once
//
#ifndef __ISIP_MEMORY_MANAGER
#define __ISIP_MEMORY_MANAGER

// isip include files
//
#ifndef __ISIP_INTEGRAL
#include <integral.h>
#endif

// forward declaration of classes
//
#ifndef __ISIP_LINK_NODE
#include <link_node.h>
#endif

// Memory_manager: a class that handles memory allocation and deletion
// for link list nodes
//
class Memory_manager {
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:
  
  // pointer to a list of free node pointers and the count of node
  // pointers left on the free node list
  //
  Link_node* node_list_d;
  int_4 node_count_d;
  int_4 num_node_d;
  
  // the number of nodes or traces to allocate if one of the free
  // lists becomes empty
  //
  int_4 node_grow_size_d;
  
  //---------------------------------------------------------------------------
  //
  // public methods
  //
  //---------------------------------------------------------------------------
public:

  // required methods
  //
  char_1* name_cc();
  volatile void error_handler_cc(char_1* method_name, char_1* message);
  logical_1 debug_cc(FILE* fp, char_1* message);
  int_4 size_cc();
  
  // destructors/constructors
  //
  ~Memory_manager();  
  Memory_manager();                                         // default
  Memory_manager(int_4 grow_size, int_4 node_size);         // overloaded
  Memory_manager(const Memory_manager& manager);            // copy

  // methods that take memory units off of the free lists and give
  // them to the user
  //
  Link_node* new_node_cc();
  
  // methods that put memory units back on the free lists
  //
  logical_1 delete_cc(Link_node* node);  
  
  // set methods
  //
  logical_1 set_node_grow_size_cc(int_4 size);

  // get methods
  //
  int_4 get_node_grow_size_cc();

  // count methods
  //
  int_4 get_node_count_cc();
  
  // total number methods
  //
  int_4 get_num_node_cc();
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

  // methods to allocate more memory for the free traces list and the
  // free nodes list
  //
  logical_1 grow_node_cc();
};

// end of file
// 
#endif
