COOPY » Guide
version 0.6.5
|
00001 #ifndef COOPY_SHORTTEXTBOOKFACTORY 00002 #define COOPY_SHORTTEXTBOOKFACTORY 00003 00004 #include <coopy/ShortTextBook.h> 00005 #include <coopy/TextBookFactory.h> 00006 #include <coopy/CsvFile.h> 00007 #include <coopy/Dbg.h> 00008 00009 namespace coopy { 00010 namespace store { 00011 class ShortTextBookFactory; 00012 } 00013 } 00014 00020 class coopy::store::ShortTextBookFactory : public TextBookFactory { 00021 virtual std::string getName() { 00022 return "csv"; 00023 } 00024 00025 virtual TextBook *open(AttachConfig& config, AttachReport& report) { 00026 if (config.shouldWrite) { 00027 if (config.prevBook!=NULL) { 00028 //if (config.prevOptions.get("type").asString()==getName()) { 00029 //ShortTextBook *book = (ShortTextBook *) config.prevBook; 00030 dbg_printf("writing csv file %s\n", config.options.get("file").asString().c_str()); 00031 int r = CsvFile::write(config.prevBook->readSheetByIndex(0), 00032 config.options); 00033 if (r==0) { 00034 report.success = true; 00035 return config.prevBook; 00036 } 00037 } 00038 return NULL; 00039 } 00040 00041 ShortTextBook *book = new ShortTextBook; 00042 if (book==NULL) return NULL; 00043 00044 if (config.shouldRead) { 00045 if (!config.options.check("should_attach")) { 00046 dbg_printf("reading csv file %s\n", config.options.get("file").asString().c_str()); 00047 int r = CsvFile::read(config.fname.c_str(),book->sheet,config.options); 00048 if (r!=0) { 00049 delete book; 00050 book = NULL; 00051 } 00052 } 00053 } 00054 00055 if (book!=NULL) { 00056 report.success = true; 00057 } 00058 00059 return book; 00060 } 00061 }; 00062 00063 #endif 00064 00065