|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2007 Serge Iovleff 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the 00016 Free Software Foundation, Inc., 00017 59 Temple Place, 00018 Suite 330, 00019 Boston, MA 02111-1307 00020 USA 00021 00022 Contact : Serge.Iovleff@stkpp.org 00023 */ 00024 00025 /* 00026 * Project: IOaccess 00027 * Purpose: Implementation of the classes ImportExportToCsv. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 * 00030 */ 00031 00036 #include "../include/STK_ExportToCsv.h" 00037 00038 namespace STK 00039 { 00040 00041 ExportToCsv::ExportToCsv() : p_data_(0) 00042 , isColNamed_(true) 00043 { 00044 // create an empty ReadWriteCsv 00045 p_data_ = new ReadWriteCsv(); 00046 } 00047 00048 ExportToCsv::ExportToCsv( const DataFrame& df) 00049 : p_data_(0) 00050 , isColNamed_(true) 00051 { 00052 // create an empty ReadWriteCsv 00053 p_data_ = new ReadWriteCsv(); 00054 00055 // for each field Try a String conversion 00056 for(Integer iVar = df.firstCol(); iVar<=df.lastCol(); iVar++) 00057 { 00058 // add an empty string variable 00059 p_data_->push_back(); 00060 // use virtual method exportString() for getting Strings into Csv 00061 if (df.elt(iVar)) df.elt(iVar)->exportString(p_data_->back()); 00062 } 00063 } 00064 00065 ExportToCsv::~ExportToCsv() 00066 { if (p_data_) delete p_data_;} 00067 00068 /* Set a name to each column of the ReadWriteCsv using the form 00069 * prefix + number. 00070 * @param prefix the prefix to use for the names of the columns 00071 **/ 00072 void ExportToCsv::setColumnsNames(String const& prefix) 00073 { 00074 // get first and last column indexes 00075 const Integer first = p_data_->first(), last = p_data_->last(); 00076 // set names of the variables 00077 for(Integer i = first; i<=last; i++) 00078 { 00079 p_data_->setName(i, prefix + typeToString(i)) ; 00080 } 00081 isColNamed_ = true; 00082 } 00083 00084 } // namespace STK