COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/MergeOutputEditList.cpp
Go to the documentation of this file.
00001 #include <coopy/MergeOutputEditList.h>
00002 
00003 using namespace coopy::store;
00004 using namespace coopy::cmp;
00005 using namespace std;
00006 
00007 bool MergeOutputEditList::setSheet(const char *name) {
00008   outputField("sheet");
00009   outputField(name);
00010   outputRecord();
00011   sheet_name = name;
00012   return true;
00013 }
00014 
00015 bool MergeOutputEditList::changeColumn(const OrderChange& change) {
00016   switch (change.mode) {
00017   case ORDER_CHANGE_INSERT:
00018     outputField("column");
00019     outputField("");
00020     outputField("insert");
00021     outputField(SheetCell(change.identityToIndexAfter(change.object)));
00022     outputRecord();
00023     break;
00024   default:
00025     fprintf(stderr,"Sorry, only bare min of 'edit' format implemented yet for a specific task\n");
00026     exit(1);
00027     break;
00028   }
00029   return true;
00030 }
00031 
00032 
00033 bool MergeOutputEditList::changeRow(const RowChange& change) {
00034   switch (change.mode) {
00035   case ROW_CHANGE_UPDATE:
00036     outputField("row");
00037     outputField(change.lRow);
00038     outputField("update");
00039     for (RowChange::txt2cell::const_iterator it = change.val.begin();
00040          it!=change.val.end(); it++) {
00041       string name = it->first;
00042       SheetCell cell = it->second;
00043       outputField(SheetCell(col_map[name]));
00044       outputField(cell);
00045     }
00046     outputRecord();
00047     break;
00048   default:
00049     fprintf(stderr,"Sorry, only bare min of 'edit' format implemented yet for a specific task\n");
00050     exit(1);
00051     break;
00052   }
00053   return true;
00054 }
00055 
00056 bool MergeOutputEditList::makeSafe() {
00057   PolySheet sheet = getSheet();
00058   if (!sheet.isValid()) return false;
00059   if (x<0) {
00060     sheet.deleteData();
00061     x = 0;
00062     y = 0;
00063   }
00064   while (sheet.width()<=x) {
00065     ColumnRef col = sheet.insertColumn(ColumnRef(-1));
00066     if (!col.isValid()) return false;
00067   }
00068   while (sheet.height()<=y) {
00069     RowRef row = sheet.insertRow(RowRef(-1));
00070     if (!row.isValid()) return false;
00071   }
00072   return true;
00073 }
00074 
00075 bool MergeOutputEditList::outputField(const coopy::store::SheetCell& cell) {
00076   if (!makeSafe()) return false;
00077   PolySheet sheet = getSheet();
00078   sheet.cellSummary(x,y,cell);
00079   x++;
00080   return true;
00081 }
00082 
00083 bool MergeOutputEditList::outputRecord() {
00084   x = 0;
00085   y++;
00086   return true;
00087 }
00088 
00089 
00090 bool MergeOutputEditList::changeName(const NameChange& change) {
00091   for (int i=0; i<(int)change.names.size(); i++) {
00092     col_map[change.names[i]] = i;
00093   }
00094   return true;
00095 }
00096 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines