CSV_Data.cc

Go to the documentation of this file.
00001 // CSV_Data.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
00007 // Author: Stephan Zednik <zednik@ucar.edu> and Patrick West <pwest@ucar.edu>
00008 // and Jose Garcia <jgarcia@ucar.edu>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 // 
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact University Corporation for Atmospheric Research at
00025 // 3080 Center Green Drive, Boulder, CO 80301
00026  
00027 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00028 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00029 //
00030 // Authors:
00031 //      zednik      Stephan Zednik <zednik@ucar.edu>
00032 //      pwest       Patrick West <pwest@ucar.edu>
00033 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
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 }

Generated on 27 Oct 2009 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.6.1