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