Original Post
#ifndef GENERIC_H_
#define GENERIC_H_
//runtime type flags used by the Generic class
#define RT_int
#define RT_char
#define RT_long
#define RT_float
#define RT_double
#define RT_unsigned_int
#define RT_unsigned_long
/*
#define RT_apstring //replace ap classes with your own
#define RT_apvector //container classes of choice
#define RT_apmatrix //and uncomment this block
#define RT_apstack
#define RT_apqueue
#define RT_LList
#define RT_DyQueue
#define RT_DyStack
*/
class Generic
{
public:
Generic()
{
defined = false;
}
Generic(int type)
{
defined = true;
G_type = type;
}
Generic(int type,void* data)
{
defined = true;
G_type = type;
G_data = data;
}
~Generic()
{
delete G_data;
}
//make G_data store new data
//assumes user works with same G_type
void modify(void *data)
{
G_data = data;
}
//return a copy of G_data
void *retrieve() const
{
return G_data;
}
//return size for type of data stored
int get_size() const
{
return G_size;
}
//destroy data and return a copy of its data
friend void *pop(Generic data)
{
void *temp = data.retrieve();
delete data;
return temp;
}
private:
int G_size;
int G_type;
void *G_data;
bool defined;
};
//type casting
const char* (Generic &data)
{
return ((char*)data.retrieve());
}
const int* (Generic &data)
{
return ((int*)data.retrieve());
}
const long* (Generic &data)
{
return ((long*)data.retrieve());
}
const float* (Generic &data)
{
return ((float*)data.retrieve());
}
const double* (Generic &data)
{
return ((double*)data.retrieve());
}
const unsigned int* (Generic &data)
{
return ((unsigned int*)data.retrieve());
}
const unsigned long* (Generic &data)
{
return ((unsigned long*)data.retrieve());
}
#endif