COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/MergeOutputRowOps.cpp
Go to the documentation of this file.
00001 #include <coopy/MergeOutputRowOps.h>
00002 #include <coopy/SheetSchema.h>
00003 
00004 using namespace std;
00005 using namespace coopy::cmp;
00006 using namespace coopy::store;
00007 
00008 bool MergeOutputRowOps::changeRow(const RowChange& change) {
00009   const CompareFlags& flags = getFlags();
00010   if (!ops.isValid()) {
00011     SimpleSheetSchema ss;
00012     if (sheet_name=="") {
00013       sheet_name = "sheet";
00014     }
00015     ss.setSheetName(sheet_name.c_str());
00016     ss.addColumn("name",ColumnType("TEXT"));
00017     ss.addColumn("op",ColumnType("TEXT"));
00018     if (flags.ids.size()>0) {
00019       ids = flags.ids;
00020     } else {
00021       ids = change.allNames;
00022     }
00023     for (int i=0; i<(int)ids.size(); i++) {
00024       ss.addColumn((ids[i] + "0").c_str());
00025     }
00026     for (int i=0; i<(int)ids.size(); i++) {
00027       ss.addColumn((ids[i] + "1").c_str());
00028     }
00029     if (getOutputBook()!=NULL) {
00030       ops = getOutputBook()->provideSheet(ss);
00031     }
00032     
00033     if (!ops.isValid()) {
00034       fprintf(stderr,"* Could not generate row operations sheet\n");
00035       exit(1);
00036       return false;
00037     }
00038 
00039     ops.deleteData();
00040   }
00041 
00042   Poly<SheetRow> row = ops.insertRow();
00043   row->setCell(0,SheetCell(sheet_name.c_str(),false));
00044   row->setCell(1,SheetCell(change.modeString().c_str(),false));
00045   int at = 2;
00046   for (int i=0; i<(int)ids.size(); i++) {
00047     string id = ids[i];
00048     if (change.cond.find(id)!=change.cond.end()) {
00049       row->setCell(at,change.cond.find(id)->second);
00050     }
00051     at++;
00052   }
00053   for (int i=0; i<(int)ids.size(); i++) {
00054     string id = ids[i];
00055     if (change.val.find(id)!=change.val.end()) {
00056       row->setCell(at,change.val.find(id)->second);
00057     }
00058     at++;
00059   }
00060   row->flush();
00061 
00062   return true;
00063 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines