COOPY » Guide
version 0.6.5
|
00001 #ifndef COOPY_LOGDIFFRENDER 00002 #define COOPY_LOGDIFFRENDER 00003 00004 #include <coopy/DiffRender.h> 00005 00006 #include <list> 00007 00008 #include <stdio.h> 00009 00010 namespace coopy { 00011 namespace light { 00012 class LogRow; 00013 class LogCell; 00014 class LogDiffRender; 00015 } 00016 } 00017 00018 class coopy::light::LogRow { 00019 public: 00020 int row; 00021 std::string mode; 00022 }; 00023 00024 class coopy::light::LogCell { 00025 public: 00026 int col; 00027 int row; 00028 Cell cell; 00029 std::string cell_mode; 00030 std::string row_mode; 00031 std::string separator; 00032 }; 00033 00034 class coopy::light::LogDiffRender : public DiffRender { 00035 private: 00036 int row, col; 00037 std::string row_mode; 00038 public: 00039 00040 std::list<LogRow> row_log; 00041 std::list<LogCell> cell_log; 00042 00043 LogDiffRender() { 00044 row = col = 0; 00045 } 00046 00047 virtual bool begin_table() { 00048 return true; 00049 } 00050 00051 virtual bool begin_row(const std::string& mode) { 00052 row_mode = mode; 00053 LogRow item = { row, mode }; 00054 row_log.push_back(item); 00055 col = 0; 00056 return true; 00057 } 00058 00059 virtual bool insert_cell(const Cell& cell, 00060 const std::string& mode, 00061 const std::string& separator) { 00062 LogCell item = { col, row, cell, mode, row_mode, separator }; 00063 cell_log.push_back(item); 00064 col++; 00065 return true; 00066 } 00067 00068 virtual bool end_row() { 00069 row++; 00070 return true; 00071 } 00072 00073 virtual bool end_table() { 00074 return true; 00075 } 00076 00077 virtual std::string to_string() const { 00078 std::string result = ""; 00079 char buf[1000]; // finite length since this is a test class 00080 for (std::list<LogCell>::const_iterator it = cell_log.begin(); 00081 it != cell_log.end(); it++) { 00082 sprintf(buf,"%d,%d [%s/%s] %s : %s\n", it->col, it->row, 00083 it->cell_mode.c_str(), 00084 it->row_mode.c_str(), 00085 it->separator.c_str(), 00086 it->cell.txt.c_str()); 00087 result += buf; 00088 } 00089 return result; 00090 } 00091 00092 }; 00093 00094 #endif