Merge pull request #6 from wlawski/custom-change-printer-example-improvement

Make custom change printer example more mature
This commit is contained in:
Tatsuhiko Kubo 2020-09-21 15:35:11 +09:00 committed by GitHub
commit ef50138616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 16 deletions

View File

@ -1,23 +1,25 @@
#ifndef DTL_PRINTERS #ifndef DTL_PRINTERS
#define DTL_PRINTERS #define DTL_PRINTERS
#include <dtl/dtl.hpp>
template <typename sesElem, typename stream = ostream > template <typename sesElem, typename stream = ostream >
class customChangePrinter : public Printer < sesElem, stream > class customChangePrinter : public dtl::Printer < sesElem, stream >
{ {
public : public :
customChangePrinter () : Printer < sesElem, stream > () {} customChangePrinter () : dtl::Printer < sesElem, stream > () {}
customChangePrinter (stream& out) : Printer < sesElem, stream > (out) {} customChangePrinter (stream& out) : dtl::Printer < sesElem, stream > (out) {}
~customChangePrinter () {} ~customChangePrinter () {}
void operator() (const sesElem& se) const { void operator() (const sesElem& se) const {
switch (se.second.type) { switch (se.second.type) {
case SES_ADD: case dtl::SES_ADD:
this->out_ << "Add: " << se.first << endl; this->out_ << "Add: " << se.first << std::endl;
break; break;
case SES_DELETE: case dtl::SES_DELETE:
this->out_ << "Delete: " << se.first << endl; this->out_ << "Delete: " << se.first << std::endl;
break; break;
case SES_COMMON: case dtl::SES_COMMON:
this->out_ << "Common: " << se.first << endl; this->out_ << "Common: " << se.first << std::endl;
break; break;
} }
} }

View File

@ -1,19 +1,14 @@
#include <dtl/dtl.hpp> #include <dtl/dtl.hpp>
#include "common.hpp" #include "common.hpp"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "printers.hpp"
using namespace std; using namespace std;
using dtl::Diff; using dtl::Diff;
using dtl::SES_ADD;
using dtl::SES_DELETE;
using dtl::SES_COMMON;
using dtl::Printer;
#include "printers.hpp"
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){