Introduction
In this Code I have tried to provide a functionality to save different type of data type under same umbrella.
for example map<key,value> here you are bounded with your value type. if suppose your key is always same but not the the value. and you have more than one value at a time. i mean a list of value(uncountable values) so you have to use multi map where you have to insert your
value and keys as many times as you want to insert.
but in case of table you can only key at one time and as many values you want.
typedef pair<const char*,enum DataType> mypair;
map<const char*,enum DataType> obj;
obj.insert(mypair("INT",INT));
obj.insert(mypair("STRING",CHAR_PTR));
obj.insert(mypair("DOUBLE",DOUBLE));
table tableobj(&obj);
tableobj.DescribeTable();
tableobj.InsertValue<int>("INT",12);
tableobj.InsertValue<int>("INT",13);
tableobj.InsertValue<int>("INT",14);
tableobj.InsertValue<char*>("STRING","vikas");
tableobj.InsertValue<char*>("STRING","tyagi");
tableobj.InsertValue<char*>("STRING","Trial");
tableobj.InsertValue<double>("DOUBLE",12.445);
tableobj.InsertValue<double>("DOUBLE",15.445);
tableobj.InsertValue<double>("DOUBLE",19.445);
like you have only limited no of keys and there type and than you can insert as many values as you want.
Using the code
the file name main.cpp contains a test program which is describing all what to do and how to do in this code.
but just to give a brief idea i m explaining here also.
void main()
{
typedef pair<const char*,enum DataType> mypair;
map<const char*,enum DataType> obj;
obj.insert(mypair("INT",INT));
obj.insert(mypair("STRING",CHAR_PTR));
obj.insert(mypair("DOUBLE",DOUBLE));
table tableobj(&obj);
tableobj.DescribeTable();
tableobj.InsertValue<int>("INT",12);
tableobj.InsertValue<int>("INT",13);
tableobj.InsertValue<int>("INT",14);
tableobj.InsertValue<char*>("STRING","vikas");
tableobj.InsertValue<char*>("STRING","tyagi");
tableobj.InsertValue<char*>("STRING","Trial");
tableobj.InsertValue<double>("DOUBLE",12.445);
tableobj.InsertValue<double>("DOUBLE",15.445);
tableobj.InsertValue<double>("DOUBLE",19.445);
cout<<"==========Data Retrival=============="<<endl;
List*obj1 = tableobj["STRING"];
char* svalue = obj1->operator[]<char*>(0);
cout<<svalue<<endl;
svalue = obj1->operator[]<char*>(1);
cout<<svalue<<endl;
svalue = obj1->operator[]<char*>(2);
cout<<svalue<<endl;
obj1 = tableobj["INT"];
int ivalue = obj1->operator[]<int>(0);
cout<<ivalue<<endl;
ivalue = obj1->operator[]<int>(1);
cout<<ivalue<<endl;
ivalue = obj1->operator[]<int>(2);
cout<<ivalue<<endl;
obj1 = tableobj["DOUBLE"];
double dvalue = obj1->operator []<double>(0);
cout<<dvalue<<endl;
dvalue = obj1->operator []<double>(1);
cout<<dvalue<<endl;
dvalue = obj1->operator []<double>(2);
cout<<dvalue<<endl;
tableobj.RemoveAt("DOUBLE",1);
tableobj.RemoveValue("STRING","vikas");
}
Points of Interest
the most interesting thing in this code is that this contains an operator[] which can retrieve any type of data from table. the definition is written. here just pass the index and will return the data at a particular index.
template<class T>
T operator[](int index)
{
list<T>* ptr = GetListInstance<T>();
list<T>::iterator itrlist;
itrlist = ptr->begin();
while(index-- && itrlist != ptr->end())
{
itrlist++;
}
return *itrlist;
}
Plateform
this code can work on any platform. Window/Unix/Linux/Mac OSX
Limitation
unicode not supported
History
verison 1.0 this code