Guitar
functors.hpp
Go to the documentation of this file.
1 
36 /* If you use this library, you must include dtl.hpp only. */
37 
38 #ifndef DTL_FUNCTORS_H
39 #define DTL_FUNCTORS_H
40 
41 namespace dtl {
42 
46  template <typename sesElem, typename stream = ostream >
47  class Printer
48  {
49  public :
50  Printer () : out_(cout) {}
51  Printer (stream& out) : out_(out) {}
52  virtual ~Printer () {}
53  virtual void operator() (const sesElem& se) const = 0;
54  protected :
55  stream& out_;
56  };
57 
61  template <typename sesElem, typename stream = ostream >
62  class CommonPrinter : public Printer < sesElem, stream >
63  {
64  public :
65  CommonPrinter () : Printer < sesElem, stream > () {}
66  CommonPrinter (stream& out) : Printer < sesElem, stream > (out) {}
68  void operator() (const sesElem& se) const {
69  this->out_ << SES_MARK_COMMON << se.first << endl;
70  }
71  };
72 
76  template <typename sesElem, typename stream = ostream >
77  class ChangePrinter : public Printer < sesElem, stream >
78  {
79  public :
80  ChangePrinter () : Printer < sesElem, stream > () {}
81  ChangePrinter (stream& out) : Printer < sesElem, stream > (out) {}
83  void operator() (const sesElem& se) const {
84  switch (se.second.type) {
85  case SES_ADD:
86  this->out_ << SES_MARK_ADD << se.first << endl;
87  break;
88  case SES_DELETE:
89  this->out_ << SES_MARK_DELETE << se.first << endl;
90  break;
91  case SES_COMMON:
92  this->out_ << SES_MARK_COMMON << se.first << endl;
93  break;
94  }
95  }
96  };
97 
101  template <typename sesElem, typename stream = ostream >
103  {
104  public :
105  UniHunkPrinter () : out_(cout) {}
106  UniHunkPrinter (stream& out) : out_(out) {}
108  void operator() (const uniHunk< sesElem >& hunk) const {
109  out_ << "@@"
110  << " -" << hunk.a << "," << hunk.b
111  << " +" << hunk.c << "," << hunk.d
112  << " @@" << endl;
113 
114  for_each(hunk.common[0].begin(), hunk.common[0].end(), CommonPrinter< sesElem, stream >(out_));
115  for_each(hunk.change.begin(), hunk.change.end(), ChangePrinter< sesElem, stream >(out_));
116  for_each(hunk.common[1].begin(), hunk.common[1].end(), CommonPrinter< sesElem, stream >(out_));
117  }
118  private :
119  stream& out_;
120  };
121 
125  template <typename sesElem, typename storedData >
126  class Storage
127  {
128  public:
129  Storage(storedData& sd) : storedData_(sd) {}
130  virtual ~Storage() {}
131  virtual void operator() (const sesElem& se) const = 0;
132  protected:
133  storedData& storedData_;
134  };
135 
139  template <typename elem>
140  class Compare
141  {
142  public :
143  Compare () {}
144  virtual ~Compare () {}
145  virtual inline bool impl (const elem& e1, const elem& e2) const {
146  return e1 == e2;
147  }
148  };
149 }
150 
151 #endif // DTL_FUNCTORS_H
dtl::uniHunk::common
vector< sesElem > common[2]
Definition: variables.hpp:121
dtl::Storage::~Storage
virtual ~Storage()
Definition: functors.hpp:130
dtl::CommonPrinter
Definition: functors.hpp:62
dtl::CommonPrinter::~CommonPrinter
~CommonPrinter()
Definition: functors.hpp:67
dtl::SES_ADD
const edit_t SES_ADD
Definition: variables.hpp:74
SES_MARK_COMMON
#define SES_MARK_COMMON
Definition: variables.hpp:80
dtl::UniHunkPrinter::out_
stream & out_
Definition: functors.hpp:119
dtl::uniHunk::b
long long b
Definition: variables.hpp:120
dtl::CommonPrinter::operator()
void operator()(const sesElem &se) const
Definition: functors.hpp:68
dtl::uniHunk::c
long long c
Definition: variables.hpp:120
dtl::ChangePrinter::~ChangePrinter
~ChangePrinter()
Definition: functors.hpp:82
dtl::UniHunkPrinter::operator()
void operator()(const uniHunk< sesElem > &hunk) const
Definition: functors.hpp:108
SES_MARK_ADD
#define SES_MARK_ADD
Definition: variables.hpp:81
dtl::uniHunk::d
long long d
Definition: variables.hpp:120
dtl::Storage::Storage
Storage(storedData &sd)
Definition: functors.hpp:129
dtl::UniHunkPrinter::UniHunkPrinter
UniHunkPrinter(stream &out)
Definition: functors.hpp:106
dtl::SES_DELETE
const edit_t SES_DELETE
Definition: variables.hpp:72
dtl::UniHunkPrinter::~UniHunkPrinter
~UniHunkPrinter()
Definition: functors.hpp:107
dtl::SES_COMMON
const edit_t SES_COMMON
Definition: variables.hpp:73
dtl::Compare::Compare
Compare()
Definition: functors.hpp:143
SES_MARK_DELETE
#define SES_MARK_DELETE
Definition: variables.hpp:79
dtl::uniHunk::a
long long a
Definition: variables.hpp:120
dtl::Printer::Printer
Printer(stream &out)
Definition: functors.hpp:51
dtl
Definition: Diff.hpp:41
dtl::Compare::~Compare
virtual ~Compare()
Definition: functors.hpp:144
dtl::ChangePrinter::ChangePrinter
ChangePrinter()
Definition: functors.hpp:80
dtl::Storage
Definition: functors.hpp:126
dtl::Printer
Definition: functors.hpp:47
dtl::uniHunk
Definition: variables.hpp:119
dtl::Storage::storedData_
storedData & storedData_
Definition: functors.hpp:133
dtl::ChangePrinter
Definition: functors.hpp:77
dtl::Printer::~Printer
virtual ~Printer()
Definition: functors.hpp:52
dtl::uniHunk::change
vector< sesElem > change
Definition: variables.hpp:122
dtl::ChangePrinter::ChangePrinter
ChangePrinter(stream &out)
Definition: functors.hpp:81
dtl::UniHunkPrinter
Definition: functors.hpp:102
dtl::ChangePrinter::operator()
void operator()(const sesElem &se) const
Definition: functors.hpp:83
dtl::UniHunkPrinter::UniHunkPrinter
UniHunkPrinter()
Definition: functors.hpp:105
dtl::Compare::impl
virtual bool impl(const elem &e1, const elem &e2) const
Definition: functors.hpp:145
dtl::Printer::operator()
virtual void operator()(const sesElem &se) const =0
dtl::Printer::Printer
Printer()
Definition: functors.hpp:50
dtl::CommonPrinter::CommonPrinter
CommonPrinter(stream &out)
Definition: functors.hpp:66
dtl::CommonPrinter::CommonPrinter
CommonPrinter()
Definition: functors.hpp:65
dtl::Printer::out_
stream & out_
Definition: functors.hpp:55
dtl::Storage::operator()
virtual void operator()(const sesElem &se) const =0
dtl::Compare
Definition: functors.hpp:140