COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/include/coopy/SheetPatcher.h
Go to the documentation of this file.
00001 #ifndef COOPY_SHEETPATCHER
00002 #define COOPY_SHEETPATCHER
00003 
00004 #include <coopy/Patcher.h>
00005 #include <coopy/DataSheet.h>
00006 #include <coopy/PolySheet.h>
00007 #include <coopy/TextBook.h>
00008 #include <coopy/CsvSheet.h>
00009 #include <coopy/NameSniffer.h>
00010 #include <coopy/MergeOutputFilter.h>
00011 
00012 #include <vector>
00013 #include <list>
00014 
00015 namespace coopy {
00016   namespace cmp {
00017     class SheetPatcher;
00018   }
00019 }
00020 
00021 class coopy::cmp::SheetPatcher : public Patcher {
00022 private:
00023   //coopy::store::PolySheet active_sheet;
00024   ConfigChange config;
00025   coopy::store::CsvSheet activeRow;
00026   coopy::store::CsvSheet activeCol;
00027   coopy::store::CsvSheet statusCol;
00028   std::vector<int> columns;
00029   std::vector<std::string> column_names;
00030   std::map<std::string,int> name2col;
00031   std::map<int,std::string> col2name;
00032   std::map<std::string,int> original_index;
00033   std::map<std::string,coopy::store::PoolColumnLink> name2pool;
00034   std::map<std::string,std::string> syn2name;
00035   std::map<std::string,std::string> name2syn;
00036   std::list<RowUnit> deferred_rows;
00037   int rowCursor;
00038   bool summary;
00039   Patcher *chain;
00040   bool chainOwned;
00041   int changeCount;
00042   bool descriptive;
00043   bool forReview;
00044   bool declaredNames;
00045   bool readyForConflicts;
00046   bool checkedHeader;
00047   int conflictColumn;
00048   int xoff;
00049   bool killNeutral;
00050   bool merging;
00051   bool sheetChange;
00052   std::string sheetName;
00053   bool sheetUpdateNeeded;
00054   coopy::store::NameSniffer *sniffer;
00055   coopy::store::DataSheet *sniffedSheet;
00056 
00057   int matchRow(const std::vector<int>& active_cond,
00058                const std::vector<std::string>& active_name,
00059                const std::vector<coopy::store::SheetCell>& cond,
00060                int width,
00061                bool show=false);
00062 
00063   void checkHeader();
00064 
00065   int matchCol(const std::string& mover);
00066 
00067   int updateCols();
00068 
00069   void updatePool();
00070 
00071   bool moveColumn(int idx, int idx2);
00072   
00073   bool renameColumn(int idx, const std::string& name, 
00074                     const std::string& oldName);
00075 
00076 public:
00077   SheetPatcher(bool descriptive = false,
00078                bool forReview = false,
00079                bool forMerge = false) : descriptive(descriptive),
00080     forReview(forReview), merging(forMerge)
00081   {
00082     sheetUpdateNeeded = false;
00083     rowCursor = -1;
00084     summary = false;
00085     chain = 0/*NULL*/;
00086     chainOwned = false;
00087     changeCount = 0;
00088     xoff = 0;
00089     sniffer = 0/*NULL*/;
00090     sniffedSheet = 0/*NULL*/;
00091     killNeutral = false;
00092     readyForConflicts = false;
00093     conflictColumn = -1;
00094     declaredNames = false;
00095     checkedHeader = false;
00096   }
00097 
00098   static SheetPatcher *createForApply() {
00099     return new SheetPatcher();
00100   }
00101 
00102   static SheetPatcher *createForMerge() {
00103     return new SheetPatcher(false,false,true);
00104   }
00105 
00106   static SheetPatcher *createForDescription() {
00107     return new SheetPatcher(true);
00108   }
00109 
00110   static SheetPatcher *createForReview() {
00111     return new SheetPatcher(true,true);
00112   }
00113 
00114   virtual ~SheetPatcher() {
00115     clearNames();
00116     if (chain!=0/*NULL*/) {
00117       if (chainOwned) {
00118         delete chain;
00119       }
00120       chain = 0/*NULL*/;
00121       chainOwned = false;
00122     }
00123   }
00124 
00125   virtual bool setNames(bool forceSheetChange = false);
00126 
00127   void clearNames() {
00128     if (sniffer!=0/*NULL*/) {
00129       delete sniffer;
00130       sniffer = 0/*NULL*/;
00131     }
00132     sniffedSheet = 0/*NULL*/;
00133   }
00134 
00135   void showSummary(Patcher *chain, bool chainOwned = true) {
00136     summary = true;
00137     this->chain = chain;
00138     this->chainOwned = chainOwned;
00139   }
00140 
00141   int getChangeCount() {
00142     return changeCount;
00143   }
00144 
00145   virtual bool changeName(const NameChange& change);
00146 
00147   virtual bool changeConfig(const ConfigChange& change) { 
00148     if (chain) chain->changeConfig(change);
00149     this->config = change;
00150     return true; 
00151   }
00152 
00153   virtual bool setFlags(const CompareFlags& flags) {
00154     if (chain) chain->setFlags(flags);
00155     return Patcher::setFlags(flags);
00156   }
00157 
00158   virtual bool changeColumn(const OrderChange& change);
00159   virtual bool changeRow(const RowChange& change);
00160   virtual bool declareNames(const std::vector<std::string>& names, bool final);
00161 
00162   virtual bool changePool(const PoolChange& change) {
00163     if (chain) chain->changePool(change);
00164     bool ok = applyPool(change);
00165     updatePool();
00166     return ok;
00167   }
00168 
00169   virtual bool setSheet(const char *name);
00170 
00171   virtual bool mergeStart();
00172 
00173   virtual bool mergeDone();
00174 
00175   virtual bool mergeAllDone();
00176 
00177   virtual void setConflicted() {
00178     if (chain) chain->setConflicted();
00179     Patcher::setConflicted();
00180   }
00181 
00182   virtual bool wantLinks() { 
00183     if (chain) return chain->wantLinks();
00184     return false; 
00185   }
00186 
00187   virtual bool declareLink(const LinkDeclare& decl) {
00188     if (chain) return chain->declareLink(decl);
00189     return false;
00190   }
00191 
00192   virtual bool outputStartsFromInput() {
00193     return descriptive||merging;
00194   }
00195   
00196   virtual bool needOutputBook() {
00197     return true;
00198   }
00199 
00200   bool markChanges(const RowChange& change, int r,int width,
00201                    std::vector<int>& active_val,
00202                    std::vector<coopy::store::SheetCell>& val,
00203                    std::vector<coopy::store::SheetCell>& cval,
00204                    std::vector<coopy::store::SheetCell>& pval);
00205 
00206 
00207   bool handleConflicts();
00208 
00209   bool updateSheet();
00210 
00211   //virtual coopy::store::PolySheet getSheet();
00212 
00213 };
00214 
00215 #endif
00216 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines