COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_full/Coopy.cpp
Go to the documentation of this file.
00001 #include <coopy/Coopy.h>
00002 #include <coopy/CsvSheet.h>
00003 #include <coopy/PatchParser.h>
00004 #include <coopy/BookCompare.h>
00005 
00006 using namespace coopy::store;
00007 using namespace coopy::cmp;
00008 using namespace coopy::app;
00009 
00010 
00011 bool Coopy::compare(coopy::store::TextBook& pivot, 
00012                     coopy::store::TextBook& local, 
00013                     coopy::store::TextBook& remote) {
00014   if (!checkFormat()) return false;
00015   coopy::cmp::BookCompare cmp;
00016   if (output_book) {
00017     patcher->attachOutputBook(*output_book);
00018   }
00019   if (!patcher->startOutput(output,flags)) {
00020     return false;
00021   }
00022   if (patcher->outputStartsFromInput()) {
00023     patcher->attachBook(local);
00024     //if (!output_book) {
00025     //patcher->attachOutputBook(local);
00026     //}
00027   }
00028   int r = cmp.compare(pivot,local,remote,*patcher,flags);
00029   patcher->stopOutput(output,flags);
00030   return (r==0);
00031 }
00032 
00033 bool Coopy::merge(coopy::store::TextBook& pivot, 
00034                   coopy::store::TextBook& local, 
00035                   coopy::store::TextBook& remote) {
00036   setFormat("merge");
00037   if (!checkFormat()) return false;
00038   patcher->attachBook(local);
00039   coopy::cmp::BookCompare cmp;
00040   if (!patcher->startOutput(output,flags)) {
00041     return false;
00042   }
00043   int r = cmp.compare(pivot,local,remote,*patcher,flags);
00044   patcher->stopOutput(output,flags);
00045   return (r==0)&&!patcher->isConflicted();
00046 }
00047 
00048 
00049 bool Coopy::patch(coopy::store::TextBook& local, 
00050                   coopy::store::TextBook& mod) {
00051   setFormat("apply");
00052   if (!checkFormat()) return false;
00053   patcher->attachBook(local);
00054   coopy::cmp::BookCompare cmp;
00055   if (!patcher->startOutput(output,flags)) {
00056     return false;
00057   }
00058   PatchParser parser(patcher,flags);
00059   bool ok = parser.applyHiliteBook(mod);
00060   patcher->stopOutput(output,flags);
00061   return ok;
00062 }
00063 
00064 PolySheet Coopy::createSheet() {
00065   CsvSheet *local = new CsvSheet();
00066   if (!local) return PolySheet();
00067   return PolySheet(local,true);
00068 }
00069 
00070 
00071 coopy::store::PolyBook Coopy::createBook(coopy::store::PolySheet sheet) {
00072   WrapBook *book = new WrapBook(sheet);
00073   PolyBook pb;
00074   pb.take(book);
00075   return pb;
00076 }
00077 
00078 coopy::store::PolyBook Coopy::loadBook(const char *filename) {
00079   PolyBook pb;
00080   pb.read(filename);
00081   return pb;
00082 }
00083 
00084 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines