COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/MergeOutputCsvDiffV0p2.cpp
Go to the documentation of this file.
00001 
00002 /*
00003 
00004   Old diff version, kept around out of a policy of supporting old versions.
00005   This file is frozen, and will only be updated to match gross API changes.
00006 
00007  */
00008 
00009 #include <coopy/MergeOutputCsvDiff.h>
00010 
00011 #include <coopy/SheetStyle.h>
00012 #include <coopy/DataSheet.h>
00013 
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 
00017 #define WANT_MAP2STRING
00018 #define WANT_VECTOR2STRING
00019 #include <coopy/Stringer.h>
00020 #define ROW_COL "ROW"
00021 
00022 using namespace std;
00023 using namespace coopy::store;
00024 using namespace coopy::cmp;
00025 
00026 MergeOutputCsvDiffV0p2::MergeOutputCsvDiffV0p2() {
00027   result.setStrict(0);
00028   result.addField("dtbl",false);
00029   result.addField("csv",false);
00030   result.addField("version",false);
00031   result.addField("0.2",false);
00032   result.addRecord();
00033   result.addField("config",false);
00034   result.addField("empty_tag",false);
00035   result.addField("*",false);
00036   result.addRecord();
00037   result.addField("config",false);
00038   result.addField("row_tag",false);
00039   result.addField(ROW_COL,false);
00040   result.addRecord();
00041 }
00042 
00043 bool MergeOutputCsvDiffV0p2::mergeAllDone() {
00044   SheetStyle style;
00045   SheetCell c = result.cellSummary(0,0);
00046   fprintf(out,"%s",result.encode(style).c_str());
00047   return true;
00048 }
00049 
00050 bool MergeOutputCsvDiffV0p2::changeColumn(const OrderChange& change) {
00051   switch (change.mode) {
00052   case ORDER_CHANGE_DELETE:
00053     result.addField("column",false);
00054     result.addField("delete",false);
00055     result.addField(ROW_COL,false);
00056     for (int i=0; i<(int)change.namesAfter.size(); i++) {
00057       result.addField(change.namesAfter[i].c_str(),false);
00058     }
00059     result.addRecord();
00060     break;
00061   case ORDER_CHANGE_INSERT:
00062     result.addField("column",false);
00063     result.addField("insert",false);
00064     result.addField(ROW_COL,false);
00065     for (int i=0; i<(int)change.namesAfter.size(); i++) {
00066       result.addField(change.namesAfter[i].c_str(),false);
00067     }
00068     result.addRecord();
00069     break;
00070   case ORDER_CHANGE_MOVE:
00071     result.addField("column",false);
00072     result.addField("move",false);
00073     result.addField(ROW_COL,false);
00074     for (int i=0; i<(int)change.namesAfter.size(); i++) {
00075       result.addField(change.namesAfter[i].c_str(),false);
00076     }
00077     result.addRecord();
00078     break;
00079   default:
00080     fprintf(stderr,"  Unknown column operation\n\n");
00081     exit(1);
00082     break;
00083   }
00084   return true;
00085 }
00086 
00087 bool MergeOutputCsvDiffV0p2::selectRow(const coopy::cmp::RowChange& change, 
00088                                    const char *tag) {
00089   result.addField("row",false);
00090   result.addField(tag,false);
00091   result.addField("*",false);
00092   for (int i=0; i<(int)change.names.size(); i++) {
00093     string name = change.names[i];
00094     if (change.cond.find(name)!=change.cond.end()) {
00095       result.addField(change.cond.find(name)->second);
00096     } else {
00097       result.addField("*",false);
00098     }
00099   }
00100   result.addRecord();
00101   return true;
00102 }
00103 
00104 bool MergeOutputCsvDiffV0p2::describeRow(const RowChange& change, const char *tag){
00105   result.addField("row",false);
00106   result.addField(tag,false);
00107   result.addField("*",false);
00108   for (int i=0; i<(int)change.names.size(); i++) {
00109     string name = change.names[i];
00110     if (change.val.find(name)!=change.val.end()) {
00111       result.addField(change.val.find(name)->second);
00112     } else {
00113       result.addField("*",false);
00114     }
00115   }
00116   result.addRecord();
00117   return true;
00118 }
00119 
00120 bool MergeOutputCsvDiffV0p2::changeRow(const RowChange& change) {
00121   switch (change.mode) {
00122   case ROW_CHANGE_INSERT:
00123     describeRow(change,"insert");
00124     break;
00125   case ROW_CHANGE_DELETE:
00126     selectRow(change,"delete");
00127     break;
00128   case ROW_CHANGE_UPDATE:
00129     selectRow(change,"select");
00130     describeRow(change,"update");
00131     break;
00132   case ROW_CHANGE_MOVE:
00133   case ROW_CHANGE_CONTEXT:
00134     // ignore row ops that were created after v0.2
00135     break;
00136   default:
00137     fprintf(stderr,"  Unknown row operation %s\n\n", change.modeString().c_str());
00138     exit(1);
00139     break;
00140   }
00141   return true;
00142 }
00143 
00144 
00145 bool MergeOutputCsvDiffV0p2::declareNames(const std::vector<std::string>& names, 
00146                                           bool final) {
00147   if (!final) {
00148     result.addField("column",false);
00149     result.addField("name",false);
00150     result.addField(ROW_COL,false);
00151     for (int i=0; i<(int)names.size(); i++) {
00152       result.addField(names[i].c_str(),false);
00153     }
00154     result.addRecord();
00155   }
00156   return true;
00157 }
00158 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines