CSV_Data.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include<vector>
00036 #include<iostream>
00037
00038 #include"CSV_Data.h"
00039
00040 CSV_Data::CSV_Data() {
00041 type = "";
00042 initialized = false;
00043 }
00044
00045 CSV_Data::~CSV_Data() {
00046 if(initialized) {
00047 if(type.compare(string(STRING)) == 0) {
00048 delete (vector<string> *)data;
00049 initialized = false;
00050 } else if(type.compare(string(FLOAT32)) == 0) {
00051 delete (vector<float> *)data;
00052 initialized = false;
00053 } else if(type.compare(string(FLOAT64)) == 0) {
00054 delete (vector<double> *)data;
00055 initialized = false;
00056 } else if(type.compare(string(INT16)) == 0) {
00057 delete (vector<short> *)data;
00058 initialized = false;
00059 } else if(type.compare(string(INT32)) == 0) {
00060 delete (vector<int> *)data;
00061 initialized = false;
00062 }
00063 }
00064 }
00065
00066 void CSV_Data::insert(CSV_Field* field, void* value) {
00067
00068 if(type.compare("") == 0)
00069 type = field->getType();
00070
00071 if(!initialized) {
00072 if(type.compare(string(STRING)) == 0) {
00073 data = new vector<string>();
00074 initialized = true;
00075 } else if(type.compare(string(FLOAT32)) == 0) {
00076 data = new vector<float>();
00077 initialized = true;
00078 } else if(type.compare(string(FLOAT64)) == 0) {
00079 data = new vector<double>();
00080 initialized = true;
00081 } else if(type.compare(string(INT16)) == 0) {
00082 data = new vector<short>();
00083 initialized = true;
00084 } else if(type.compare(string(INT32)) == 0) {
00085 data = new vector<int>();
00086 initialized = true;
00087 }
00088 }
00089
00090 if(type.compare(string(STRING)) == 0) {
00091 string str = *reinterpret_cast<string*>(value);
00092 ((vector<string>*)data)->push_back(str);
00093 } else if(type.compare(string(FLOAT32)) == 0) {
00094 float flt = atof((reinterpret_cast<string*>(value))->c_str());
00095 ((vector<float>*)data)->push_back(flt);
00096 } else if(type.compare(string(FLOAT64)) == 0) {
00097 double dbl = atof((reinterpret_cast<string*>(value))->c_str());
00098 ((vector<double>*)data)->push_back(dbl);
00099 } else if(type.compare(string(INT16)) == 0) {
00100 short shrt = atoi((reinterpret_cast<string*>(value))->c_str());
00101 ((vector<short>*)data)->push_back(shrt);
00102 } else if(type.compare(string(INT32)) == 0) {
00103 int integer = atoi((reinterpret_cast<string*>(value))->c_str());
00104 ((vector<int>*)data)->push_back(integer);
00105 }
00106 }
00107
00108 void* CSV_Data::getData() {
00109 return data;
00110 }
00111
00112 string CSV_Data::getType() {
00113 return type;
00114 }