next up previous contents
Next: The Void List Class: Up: The Void Access Class: Previous: The Child Classes:

The Void Access Implementation:

#include "voidaccess.h"
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
#include "voidgraph.h"
#include "voidlist.h"

//ACCESS_FLOAT
int ACCESS_FLOAT::equal(Arbent a,Arbent b)
{ return( *((float *)a) == *((float *)b) );}
void ACCESS_FLOAT::entry(Arbent *a,Arbent b)
{ (float *)(*a) = new float; *a = b;}
ostream& ACCESS_FLOAT::show(ostream& out, Arbent a)
{ out << *((float *)a) << endl; return out; }
istream& ACCESS_FLOAT::input(istream& in, Arbent* a)
{ 
  //allocate data
  if(*a==NULL)
    (float *)(*a) = new float;    
  in >> *((float *)(*a)); 
  return in; 
}

//ACCESS_DOUBLE
int ACCESS_DOUBLE::equal(Arbent a,Arbent b)
{ return( *((double *)a) == *((double *)b) ); }
void ACCESS_DOUBLE::entry(Arbent *a,Arbent b)
{ (double *)(*a) = new double; *a = b;}
ostream& ACCESS_DOUBLE::show(ostream& out, Arbent a)
{ out << *((double *)a) << endl; return out; }
istream& ACCESS_DOUBLE::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (double *)(*a) = new double;    
  in >> *((double *)(*a)); 
  return in;
}

//ACCESS_NODESTRUCT  
int ACCESS_NODESTRUCT::equal(Arbent a,Arbent b)
{ 
  NodeStruct *t = (NodeStruct *)a;
  NodeStruct *s = (NodeStruct *)b;
  
  return(  (t->load==s->load)
	 &&(t->time==s->time)
	 &&(t->V.x==s->V.x)
	 &&(t->V.y==s->V.y) ); 
}
void ACCESS_NODESTRUCT::entry(Arbent *a,Arbent b)
{ 
  (NodeStruct *)(*a) = new NodeStruct;
  NodeStruct *t = (NodeStruct *)b;
  ((NodeStruct *)(*a))->load = t->load;
  ((NodeStruct *)(*a))->time = t->time;
  ((NodeStruct *)(*a))->V.x = t->V.x;
  ((NodeStruct *)(*a))->V.y = t->V.y; 
}  
ostream& ACCESS_NODESTRUCT::show(ostream& out, Arbent a)
{ 
  NodeStruct *t = (NodeStruct *)a;
  out << "Load = " << t->load << endl; 
  out << "Time = " << t->time << endl;
  out << "Vertex = (" << t->V.x << "," << t->V.y << ")" << endl;  
  return out; 
}
istream& ACCESS_NODESTRUCT::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (NodeStruct *)(*a) = new NodeStruct;
  NodeStruct *t = (NodeStruct *)a;
  in >> t->load; 
  in >> t->time;
  in >> t->V.x >> t->V.y;  
  return in;
}

//ACCESS_DPEDGESTRUCT
int ACCESS_DPEDGESTRUCT::equal(Arbent a,Arbent b)
{ 
  DPEdgeStruct *t = (DPEdgeStruct *)a;
  DPEdgeStruct *s = (DPEdgeStruct *)b;
  
  return(  (t->time==s->time)); 
}
void ACCESS_DPEDGESTRUCT::entry(Arbent *a,Arbent b)
{ 
  (DPEdgeStruct *)(*a) = new DPEdgeStruct;
  DPEdgeStruct *t = (DPEdgeStruct *)b;
  ((DPEdgeStruct *)(*a))->time = t->time;
}  
ostream& ACCESS_DPEDGESTRUCT::show(ostream& out, Arbent a)
{ 
  DPEdgeStruct *t = (DPEdgeStruct *)a;
  out << "time = " << t->time << endl;
  return out; 
}
istream& ACCESS_DPEDGESTRUCT::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (DPEdgeStruct *)(*a) = new DPEdgeStruct;
  DPEdgeStruct *t = (DPEdgeStruct *)a; 
  in >> t->time; 
  return in;
}

//ACCESS_DPNODESTRUCT  
int ACCESS_DPNODESTRUCT::equal(Arbent a,Arbent b)
{ 
  DPNodeStruct *t = (DPNodeStruct *)a;
  DPNodeStruct *s = (DPNodeStruct *)b;
  
  return(  (t->value==s->value)
	 &&(t->previous_value==s->previous_value)
	 &&(t->control==s->control)); 
}
void ACCESS_DPNODESTRUCT::entry(Arbent *a,Arbent b)
{ 
  (DPNodeStruct *)(*a) = new DPNodeStruct;
  DPNodeStruct *t = (DPNodeStruct *)b;
  ((DPNodeStruct *)(*a))->value = t->value;
  ((DPNodeStruct *)(*a))->previous_value = t->previous_value;
  ((DPNodeStruct *)(*a))->control = t->control;
}  
ostream& ACCESS_DPNODESTRUCT::show(ostream& out, Arbent a)
{ 
  DPNodeStruct *t = (DPNodeStruct *)a;
  out << "value = " << t->value << endl; 
  out << "previous_value = " << t->previous_value << endl;  
  return out; 
}
istream& ACCESS_DPNODESTRUCT::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (DPNodeStruct *)(*a) = new DPNodeStruct;
  DPNodeStruct *t = (DPNodeStruct *)a;
  in >> t->value; 
  in >> t->previous_value;  
  return in;
}

//ACCESS_EDGESTRUCT
int ACCESS_EDGESTRUCT::equal(Arbent a,Arbent b)
{ 
  EdgeStruct *t = (EdgeStruct *)a;
  EdgeStruct *s = (EdgeStruct *)b;
  
  return(  (t->capacity==s->capacity)
         &&(t->loss==s->loss)
	 &&(t->time==s->time)
	 &&(t->V.x==s->V.x)
	 &&(t->V.y==s->V.y) ); 
}
void ACCESS_EDGESTRUCT::entry(Arbent *a,Arbent b)
{ 
  (EdgeStruct *)(*a) = new EdgeStruct;
  EdgeStruct *t = (EdgeStruct *)b;
  ((EdgeStruct *)(*a))->capacity = t->capacity;
  ((EdgeStruct *)(*a))->loss = t->loss;
  ((EdgeStruct *)(*a))->time = t->time;
  ((EdgeStruct *)(*a))->V.x = t->V.x;
  ((EdgeStruct *)(*a))->V.y = t->V.y; 
}  
ostream& ACCESS_EDGESTRUCT::show(ostream& out, Arbent a)
{ 
  EdgeStruct *t = (EdgeStruct *)a;
  out << "Capacity = " << t->capacity << endl; 
  out << "Loss = " << t->loss << endl;
  out << "time = " << t->time << endl;
  out << "Vertex = (" << t->V.x << "," << t->V.y << ")" << endl;  
  return out; 
}
istream& ACCESS_EDGESTRUCT::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (EdgeStruct *)(*a) = new EdgeStruct;
  EdgeStruct *t = (EdgeStruct *)a;
  in >> t->capacity; 
  in >> t->loss;
  in >> t->time;
  in >> t->V.x >> t->V.y;  
  return in;
}

//ACCESS_GRAPH
int ACCESS_GRAPH::equal(Arbent a,Arbent b)
{ 
}
void ACCESS_GRAPH::entry(Arbent *a,Arbent b)
{ 
  
  //cast incoming data to proper type
  cout << "Cast incoming data to proper type" << endl;
  //Graph *T = (Graph *)b;
  cout << "Construct a new Graph" << endl;
  (Graph *)(*a) = new Graph( *(Graph *)b );
}  
ostream& ACCESS_GRAPH::show(ostream& out, Arbent a)
{ 
  cout << endl << " Output Access Graph " << endl;
  Graph *t = (Graph *)a;
  out << *((Graph *)a) << endl; 
  return out; 
}
istream& ACCESS_GRAPH::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (Graph *)(*a) = new Graph;
  Graph *t = (Graph *)a;
  in >> t;  
  return in;
}

//ACCESS_SLCELL
int ACCESS_SLCELL::equal(Arbent a,Arbent b)
{
  VOID_SL_CELL *t = (VOID_SL_CELL *)a;
  VOID_SL_CELL *s = (VOID_SL_CELL *)b;
  
  return(t==s); 
}
void ACCESS_SLCELL::entry(Arbent *a,Arbent b)
{ 
  
  //cast incoming data to proper type
  if(b!=NULL)
    //we know the access method to use for this
    //constructor as it comes from b
    (VOID_SL_CELL *)(*a) = new VOID_SL_CELL( *(VOID_SL_CELL *)b );
  else
    //we are assuming we want to read in data but there
    //is no cell to hold it.  So what access method should we use?
    //
    (VOID_SL_CELL *)(*a) = new VOID_SL_CELL;    
}  
ostream& ACCESS_SLCELL::show(ostream& out, Arbent a)
{ 
  cout << endl << " Output Access SLCELL " << endl;
  VOID_SL_CELL *t = (VOID_SL_CELL *)a;
  out << *((VOID_SL_CELL *)a) << endl; 
  return out; 
}
istream& ACCESS_SLCELL::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (VOID_SL_CELL *)(*a) = new VOID_SL_CELL;
  //input data
  VOID_SL_CELL *t = (VOID_SL_CELL *)a;
  in >> t;  
  return in;
}

//ACCESS_DLCELL
int ACCESS_DLCELL::equal(Arbent a,Arbent b)
{
  VOID_DL_CELL *t = (VOID_DL_CELL *)a;
  VOID_DL_CELL *s = (VOID_DL_CELL *)b;
  
  return(t==s); 
}
void ACCESS_DLCELL::entry(Arbent *a,Arbent b)
{ 
  
  //cast incoming data to proper type
  if(b!=NULL)
    (VOID_DL_CELL *)(*a) = new VOID_DL_CELL( *(VOID_DL_CELL *)b );
  else
    (VOID_DL_CELL *)(*a) = new VOID_DL_CELL;
}  
ostream& ACCESS_DLCELL::show(ostream& out, Arbent a)
{ 
  cout << endl << " Output Access DLCELL " << endl;
  VOID_DL_CELL *t = (VOID_DL_CELL *)a;
  out << *((VOID_DL_CELL *)a) << endl; 
  return out; 
}
istream& ACCESS_DLCELL::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (VOID_DL_CELL *)(*a) = new VOID_DL_CELL;
  VOID_DL_CELL *t = (VOID_DL_CELL *)a;
  in >> t;  
  return in;
}

//ACCESS_SLLIST
int ACCESS_SLIST::equal(Arbent a,Arbent b)
{ 
}
void ACCESS_SLIST::entry(Arbent *a,Arbent b)
{ 
  
  //cast incoming data to proper type
  cout << "Cast incoming data to proper type" << endl;
  cout << "Construct a new SLLIST" << endl;
  ( *)(*a) = new VOID_SLLIST( *(VOID_SLLIST *)b );
}  
ostream& ACCESS_SLIST::show(ostream& out, Arbent a)
{ 
  cout << endl << " Output Access SLList " << endl;
  VOID_SLLIST *t = (VOID_SLLIST *)a;
  out << *((VOID_SLLIST *)a) << endl; 
  return out; 
}
istream& ACCESS_SLIST::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (VOID_SLLIST *)(*a) = new VOID_SLLIST;
  VOID_SLLIST *t = (VOID_SLLIST *)a;
  in >> t;  
  return in;
}

//ACCESS_DLLIST
int ACCESS_DLIST::equal(Arbent a,Arbent b)
{ 
}
void ACCESS_DLIST::entry(Arbent *a,Arbent b)
{ 
  
  //cast incoming data to proper type
  cout << "Cast incoming data to proper type" << endl;
  cout << "Construct a new DLLIST" << endl;
  ( *)(*a) = new VOID_DLLIST( *(VOID_DLLIST *)b );
}  
ostream& ACCESS_DLIST::show(ostream& out, Arbent a)
{ 
  cout << endl << " Output Access DLList " << endl;
  VOID_DLLIST *t = (VOID_DLLIST *)a;
  out << *((VOID_DLLIST *)a) << endl; 
  return out; 
}
istream& ACCESS_DLIST::input(istream& in, Arbent* a)
{
  //allocate data
  if(*a==NULL)
    (VOID_DLLIST *)(*a) = new VOID_DLLIST;
  VOID_DLLIST *t = (VOID_DLLIST *)a;
  in >> t;  
  return in;
}

//ACCESS_CLLIST
int ACCESS_CLIST::equal(Arbent a,Arbent b)
{ 
}
void ACCESS_CLIST::entry(Arbent *a,Arbent b)
{ 
  
  //cast incoming data to proper type
  cout << "Cast incoming data to proper type" << endl;
  cout << "Construct a new CLLIST" << endl;
  ( *)(*a) = new VOID_CLLIST( *(VOID_CLLIST *)b );
}  
ostream& ACCESS_CLIST::show(ostream& out, Arbent a)
{ 
  cout << endl << " Output Access CLList " << endl;
  VOID_CLLIST *t = (VOID_CLLIST *)a;
  out << *((VOID_CLLIST *)a) << endl; 
  return out; 
}
istream& ACCESS_CLIST::input(istream& in, Arbent a)
{
  //allocate data
  if(*a==NULL)
    (VOID_CLLIST *)(*a) = new VOID_CLLIST;
  VOID_CLLIST *t = (VOID_CLLIST *)a;
  in >> t;  
  return in;
}



Jim Peterson
1999-05-17