bes  Updated for version 3.20.5
CSV_Data.cc
1 // CSV_Data.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Stephan Zednik <zednik@ucar.edu> and Patrick West <pwest@ucar.edu>
8 // and Jose Garcia <jgarcia@ucar.edu>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact University Corporation for Atmospheric Research at
25 // 3080 Center Green Drive, Boulder, CO 80301
26 
27 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
28 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
29 //
30 // Authors:
31 // zednik Stephan Zednik <zednik@ucar.edu>
32 // pwest Patrick West <pwest@ucar.edu>
33 // jgarcia Jose Garcia <jgarcia@ucar.edu>
34 
35 #include<vector>
36 #include<iostream>
37 #include<cstdlib>
38 
39 #include"CSV_Data.h"
40 
41 CSV_Data::CSV_Data() : data(0), type(""), initialized(false) {
42 }
43 
44 CSV_Data::~CSV_Data() {
45  if(initialized) {
46  if(type.compare(string(STRING)) == 0) {
47  delete (vector<string> *)data;
48  initialized = false;
49  } else if(type.compare(string(FLOAT32)) == 0) {
50  delete (vector<float> *)data;
51  initialized = false;
52  } else if(type.compare(string(FLOAT64)) == 0) {
53  delete (vector<double> *)data;
54  initialized = false;
55  } else if(type.compare(string(INT16)) == 0) {
56  delete (vector<short> *)data;
57  initialized = false;
58  } else if(type.compare(string(INT32)) == 0) {
59  delete (vector<int> *)data;
60  initialized = false;
61  }
62  }
63 }
64 
65 void CSV_Data::insert(CSV_Field* field, void* value) {
66 
67  if(type.compare("") == 0)
68  type = field->getType();
69 
70  if(!initialized) {
71  if(type.compare(string(STRING)) == 0) {
72  data = new vector<string>();
73  initialized = true;
74  } else if(type.compare(string(FLOAT32)) == 0) {
75  data = new vector<float>();
76  initialized = true;
77  } else if(type.compare(string(FLOAT64)) == 0) {
78  data = new vector<double>();
79  initialized = true;
80  } else if(type.compare(string(INT16)) == 0) {
81  data = new vector<short>();
82  initialized = true;
83  } else if(type.compare(string(INT32)) == 0) {
84  data = new vector<int>();
85  initialized = true;
86  }
87  }
88 
89  if(type.compare(string(STRING)) == 0) {
90  string str = *reinterpret_cast<string*>(value);
91  ((vector<string>*)data)->push_back(str);
92  } else if(type.compare(string(FLOAT32)) == 0) {
93  float flt = atof((reinterpret_cast<string*>(value))->c_str());
94  ((vector<float>*)data)->push_back(flt);
95  } else if(type.compare(string(FLOAT64)) == 0) {
96  double dbl = atof((reinterpret_cast<string*>(value))->c_str());
97  ((vector<double>*)data)->push_back(dbl);
98  } else if(type.compare(string(INT16)) == 0) {
99  short shrt = atoi((reinterpret_cast<string*>(value))->c_str());
100  ((vector<short>*)data)->push_back(shrt);
101  } else if(type.compare(string(INT32)) == 0) {
102  int integer = atoi((reinterpret_cast<string*>(value))->c_str());
103  ((vector<int>*)data)->push_back(integer);
104  }
105 }
106 
107 void* CSV_Data::getData() {
108  return data;
109 }
110 
111 string CSV_Data::getType() {
112  return type;
113 }
CSV_Field
Definition: CSV_Field.h:44