Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

hk_importcsv.h

00001 // ****************************************************************************
00002 // copyright (c) 2000-2005 Horst Knorr <hk_classes@knoda.org>  
00003 // This file is part of the hk_classes library.
00004 // This file may be distributed and/or modified under the terms of the
00005 // GNU Library Public License version 2 as published by the Free Software
00006 // Foundation and appearing in the file COPYING included in the
00007 // packaging of this file.
00008 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00009 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00010 // ****************************************************************************
00011 #ifndef HK_IMPORTCSV
00012 #define HK_IMPORTCSV
00013 #include <iostream>
00014 #include <fstream>
00015 #include "hk_class.h"
00016 #include "hk_datasource.h"
00017 #include "hk_dsvisible.h"
00018 #include <vector>
00019 using namespace std;
00020 
00021 class hk_column;
00022 
00023 typedef class colstruct
00024 {
00025     public:
00026         colstruct(void){col=NULL;}
00027         hk_string colname;
00028         hk_column* col;
00029 } colstruct;
00038 class hk_importcsv:public hk_dsvisible
00039 {
00040     public:
00041         hk_importcsv(void);
00042         virtual ~hk_importcsv(void);
00043 
00044 
00049         bool    execute(enum_interaction i=interactive);
00053         void    set_filedefinition(const hk_string& textdelimiter="\"",const hk_string& betweenfields=",", const hk_string& rowdelimiter="\n");
00057         void    set_filename(const hk_string& filename);
00062         void    set_firstrow_contains_fieldnames(bool f=true);
00068         void    set_append_rows(bool f=false);
00072         void    set_create_new_table(bool n=true);
00077         void    add_columnname(const hk_string& col);
00078         void    clear_columnlist(void);
00079         hk_string textdelimiter(void){return p_textdelimiter;}
00080         hk_string betweenfield(void) {return p_betweenfields;}
00081         hk_string rowdelimiter(void) {return p_rowdelimiter;}
00082         void set_overwrite_table(bool);
00083         bool overwrite_table(void);
00084 
00085     protected:
00086 
00087         void    set_columns(void);
00088         void    create_automatic_columns(void);
00089         bool    initialize_table(enum_interaction);
00090         virtual bool before_columns_deleted(void);
00095         virtual bool widget_specific_after_new_row(void);
00096 
00097     private:
00098         void    reset(void);
00099         void    create_valuelist( hk_string& row);
00100         void    get_line(ifstream&,hk_string&);
00101         bool        p_create_new_table;
00102 /*
00103  * 0= hk_string
00104  * 1= float
00105  * 2= Integer
00106  * 3= boolean
00107  */
00108         int         interpret_columntype(hk_string&f);
00109         ifstream*   p_filestream;
00110         hk_string   p_filename;
00111         hk_string   p_textdelimiter;
00112         hk_string   p_rowdelimiter;
00113         hk_string   p_betweenfields;
00114         bool        p_firstrow_contains_fieldnames;
00115         vector<hk_string>  p_valuelist;
00116         vector<colstruct> p_columnlist;
00117         bool        p_datamode;
00118         bool        p_notcancelimport;
00119         bool        p_overwrite;
00120         hk_datasource::enum_accessmode p_accessmode;
00121 };
00122 #endif

Generated on Tue Sep 13 02:13:09 2005 for Databaseconnectionclasses by  doxygen 1.4.4