00001 // -*- c++ -*- 00002 // 00003 // $Id: csvimport.h 3344 2010-09-17 19:26:56Z java $ 00004 // 00005 // Copyright (C) 2009-2010 Rafael Ostertag 00006 // 00007 // This file is part of YAPET. 00008 // 00009 // YAPET is free software: you can redistribute it and/or modify it under the 00010 // terms of the GNU General Public License as published by the Free Software 00011 // Foundation, either version 3 of the License, or (at your option) any later 00012 // version. 00013 // 00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY 00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00017 // details. 00018 // 00019 // You should have received a copy of the GNU General Public License along with 00020 // YAPET. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 00023 #ifndef _CSVIMPORT_H 00024 #define _CSVIMPORT_H 00025 00026 00027 #ifdef HAVE_CONFIG_H 00028 # include <config.h> 00029 #endif 00030 00031 #ifdef HAVE_STRING 00032 # include <string> 00033 #endif 00034 00035 #ifdef HAVE_STDEXCEPT 00036 # include <stdexcept> 00037 #endif 00038 00039 #ifdef HAVE_LIST 00040 # include <list> 00041 #endif 00042 00046 class CSVImport { 00047 public: 00051 struct LogEntry { 00055 unsigned int lineno; 00059 std::string message; 00060 }; 00061 00062 private: 00066 inline const CSVImport& operator= (const CSVImport&) { 00067 return *this; 00068 } 00072 inline CSVImport (const CSVImport&) {} 00073 00074 enum { 00078 NUM_SEPARATORS = 4 00079 }; 00080 00084 std::string srcfile; 00088 std::string dstfile; 00092 char separator; 00093 00097 bool verbose; 00101 bool had_errors; 00105 unsigned int num_errors; 00106 00110 std::list<LogEntry> logs; 00111 00113 void cleanupValue (std::string& str); 00115 void logError (unsigned long lno, const std::string& errmsg); 00116 00117 public: 00118 CSVImport (std::string src, std::string dst, char sep, bool verb = true) throw (std::runtime_error); 00119 ~CSVImport() {}; 00121 void import (const char* pw) throw (std::exception); 00123 inline void setVerbose (bool v) { 00124 verbose = v; 00125 } 00127 inline bool getVerbose() const { 00128 return verbose; 00129 } 00131 inline bool hadErrors() const { 00132 return had_errors; 00133 } 00135 inline unsigned int numErrors() const { 00136 return num_errors; 00137 } 00139 inline std::list<LogEntry> getLog() const { 00140 return logs; 00141 } 00143 void printLog() const; 00144 }; 00145 00146 #endif // _CSVIMPORT_H
1.7.1