OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
CSV_Data.cc
Go to the documentation of this file.
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 
42  type = "";
43  initialized = false;
44 }
45 
47  if(initialized) {
48  if(type.compare(string(STRING)) == 0) {
49  delete (vector<string> *)data;
50  initialized = false;
51  } else if(type.compare(string(FLOAT32)) == 0) {
52  delete (vector<float> *)data;
53  initialized = false;
54  } else if(type.compare(string(FLOAT64)) == 0) {
55  delete (vector<double> *)data;
56  initialized = false;
57  } else if(type.compare(string(INT16)) == 0) {
58  delete (vector<short> *)data;
59  initialized = false;
60  } else if(type.compare(string(INT32)) == 0) {
61  delete (vector<int> *)data;
62  initialized = false;
63  }
64  }
65 }
66 
67 void CSV_Data::insert(CSV_Field* field, void* value) {
68 
69  if(type.compare("") == 0)
70  type = field->getType();
71 
72  if(!initialized) {
73  if(type.compare(string(STRING)) == 0) {
74  data = new vector<string>();
75  initialized = true;
76  } else if(type.compare(string(FLOAT32)) == 0) {
77  data = new vector<float>();
78  initialized = true;
79  } else if(type.compare(string(FLOAT64)) == 0) {
80  data = new vector<double>();
81  initialized = true;
82  } else if(type.compare(string(INT16)) == 0) {
83  data = new vector<short>();
84  initialized = true;
85  } else if(type.compare(string(INT32)) == 0) {
86  data = new vector<int>();
87  initialized = true;
88  }
89  }
90 
91  if(type.compare(string(STRING)) == 0) {
92  string str = *reinterpret_cast<string*>(value);
93  ((vector<string>*)data)->push_back(str);
94  } else if(type.compare(string(FLOAT32)) == 0) {
95  float flt = atof((reinterpret_cast<string*>(value))->c_str());
96  ((vector<float>*)data)->push_back(flt);
97  } else if(type.compare(string(FLOAT64)) == 0) {
98  double dbl = atof((reinterpret_cast<string*>(value))->c_str());
99  ((vector<double>*)data)->push_back(dbl);
100  } else if(type.compare(string(INT16)) == 0) {
101  short shrt = atoi((reinterpret_cast<string*>(value))->c_str());
102  ((vector<short>*)data)->push_back(shrt);
103  } else if(type.compare(string(INT32)) == 0) {
104  int integer = atoi((reinterpret_cast<string*>(value))->c_str());
105  ((vector<int>*)data)->push_back(integer);
106  }
107 }
108 
110  return data;
111 }
112 
114  return type;
115 }
string getType()
Definition: CSV_Field.h:62
void insert(CSV_Field *field, void *value)
Definition: CSV_Data.cc:67
~CSV_Data()
Definition: CSV_Data.cc:46
CSV_Data()
Definition: CSV_Data.cc:41
void * getData()
Definition: CSV_Data.cc:109
string getType()
Definition: CSV_Data.cc:113