|
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: stkp::DManager 00027 * Purpose: Declaration of the class ImportFromCsv. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 * 00030 */ 00031 00038 #ifndef STK_IMPORTFROMCSV_H 00039 #define STK_IMPORTFROMCSV_H 00040 00041 #include "STK_Import_Util.h" 00042 #include "STK_ReadWriteCsv.h" 00043 #include "STK_DataFrame.h" 00044 00045 namespace STK 00046 { 00047 00055 class ImportFromCsv 00056 { 00057 public: 00062 ImportFromCsv( ReadWriteCsv const& import); 00063 00065 virtual ~ImportFromCsv(); 00066 00068 bool run( Import::TypeImport type = Import::numeric_); 00069 00074 inline void eraseReadWriteCsv() 00075 { 00076 if (p_dataFrame_) delete p_dataFrame_; 00077 p_dataFrame_ = 0; 00078 } 00079 00081 inline String const& error() const 00082 {return msg_error_;} 00083 00085 inline DataFrame const* dataFrame() const 00086 { return p_dataFrame_;} 00087 00088 protected: 00090 DataFrame* p_dataFrame_; 00091 00093 mutable String msg_error_; 00094 00095 private: 00097 ReadWriteCsv const& import_; 00098 00104 template<class TYPE> 00105 bool convertToTYPE( Integer const& iCol, Variable<TYPE>& col) 00106 { 00107 // get dimensions of the variable 00108 // try to ConvertType strings to TYPE 00109 Integer nSuccess = col.importString(import_[iCol]); 00110 return (nSuccess == col.size()); 00111 } 00112 00116 bool runNumeric(); 00120 bool runOnlyNumeric(); 00124 bool runString(); 00125 }; 00126 00127 } // namespace STK 00128 00129 #endif /*STK_IMPORTFROMCSV_H*/