COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/PolySheet.cpp
Go to the documentation of this file.
00001 #include <coopy/PolySheet.h>
00002 #include <coopy/SchemaSniffer.h>
00003 
00004 using namespace coopy::store;
00005 
00006 bool PolySheet::mustHaveSchema() {
00007   if (getSchema()) return true;
00008   if (!sheet) return false;
00009   if (!may_sniff) return false;
00010   SchemaSniffer ss(*sheet);
00011   SheetSchema *sc = ss.suggestSchema();
00012   COOPY_ASSERT(sc);
00013   setSchema(sc->clone(),true);
00014   return true;
00015 }
00016 
00017 SheetSchema *PolySheet::preApplyInfo(const ColumnInfo& info) {
00018   COOPY_ASSERT(sheet);
00019 
00020   SheetSchema *s = getSchema();
00021   if (info.getName()!="") {
00022     if (!sheet->hasExternalColumnNames()) {
00023       if (!s) {
00024         mustHaveSchema();
00025         s = getSchema();
00026       }
00027     }
00028   }
00029   return s;
00030 }
00031 
00032 bool PolySheet::postApplyInfo(const ColumnInfo& info, 
00033                               const ColumnRef& result) {
00034   SheetSchema *s = getSchema();
00035   /*
00036   if (info.getName()!="") {
00037     if (!sheet->hasExternalColumnNames()) {
00038       int at = -1;
00039       if (s) {
00040         at = s->headerHeight() - 1;
00041       }
00042       if (at>=0) {
00043         sheet->cellString(result.getIndex(),at,info.getName());
00044       }
00045     }
00046   }
00047   */
00048   if (s) {
00049     if (info.hasName()) {
00050       if (!sheet->hasExternalColumnNames()) {
00051         if (s->headerHeight()>0) {
00052           dbg_printf("Clobber %s with %s\n",
00053                      sheet->cellString(result.getIndex(),s->headerHeight()-1).c_str(),
00054                      info.getName().c_str());
00055                             
00056           sheet->cellString(result.getIndex(),s->headerHeight()-1,
00057                             info.getName());
00058         }
00059       }
00060     }
00061   }
00062   return true;
00063 }
00064 
00065 ColumnRef PolySheet::insertColumn(const ColumnRef& base, 
00066                                   const ColumnInfo& info) {
00067   SheetSchema *s = preApplyInfo(info);
00068   ColumnRef result = sheet->insertColumn(base,info);
00069   if (!result.isValid()) return result;
00070   if (s) {
00071     if (!s->isShadow()) {
00072       ColumnRef result2 = s->insertColumn(base,info);
00073       COOPY_ASSERT(result2.getIndex()==result.getIndex());
00074     }
00075   }
00076   postApplyInfo(info,result);
00077   return result;
00078 }
00079 
00080 
00081 bool PolySheet::modifyColumn(const ColumnRef& base, 
00082                              const ColumnInfo& info) {
00083   COOPY_ASSERT(sheet);
00084   SheetSchema *s = preApplyInfo(info);
00085   bool result = sheet->modifyColumn(base,info);
00086   if (!result) return false;
00087   if (s) {
00088     if (!s->isShadow()) {
00089       bool result2 = s->modifyColumn(base,info);
00090       COOPY_ASSERT(result2);
00091     }
00092   }
00093   postApplyInfo(info,base);
00094   return true;
00095 }
00096 
00097 
00098 
00099 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines