1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
// Types noted in caps are taken from an enum variable
// The class Filed, is a helper for creating new types, it includes functions for data loading which are designed to be overloaded
// Data is where the data for the array is stored, other functions will be provided for writing this data correctly depending on the type
template<class T> T* handleArray(char type = UNKNOWN, int depth, int size[], std::string& data, T** out){
if(depth < 1 || size[0] < 1)
return NULL;
if(depth == 1){
T* temp = new T[size[0]];
for(int i=0; i<size[0]; i++){
switch(type){
case CHAR:{
sscanf_s(data.substr(i, 1).c_str(), "%c", temp[i]);
break;
}
case SHORT:{
sscanf_s(data.substr(i, 2).c_str(), "%hd", temp[i]);
break;
}
case INT:{
sscanf_s(data.substr(i, 4).c_str(), "%d", temp[i]);
break;
}
case FLOAT:{
sscanf_s(data.substr(i, 4).c_str(), "%f", temp[i]);
break;
}
case DOUBLE:{
sscanf_s(data.substr(i, 8).c_str(), "%lf", temp[i]);
break;
}
default:{
if(type & FILED){
Filed* t = dynamic_cast<Filed*>(temp[i]);
t->loadFromString(data, true);
}
break;
}
}//switch
}//for
}//if
}//func
|