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
Definition: functors.hpp:78
ChangePrinter(stream &out)
Definition: functors.hpp:81
~ChangePrinter()
Definition: functors.hpp:82
ChangePrinter()
Definition: functors.hpp:80
void operator()(const sesElem &se) const
Definition: functors.hpp:83
Definition: functors.hpp:63
~CommonPrinter()
Definition: functors.hpp:67
CommonPrinter()
Definition: functors.hpp:65
CommonPrinter(stream &out)
Definition: functors.hpp:66
void operator()(const sesElem &se) const
Definition: functors.hpp:68
Definition: functors.hpp:141
Compare()
Definition: functors.hpp:143
virtual bool impl(const elem &e1, const elem &e2) const
Definition: functors.hpp:145
virtual ~Compare()
Definition: functors.hpp:144
Definition: functors.hpp:48
Printer()
Definition: functors.hpp:50
virtual ~Printer()
Definition: functors.hpp:52
Printer(stream &out)
Definition: functors.hpp:51
stream & out_
Definition: functors.hpp:55
virtual void operator()(const sesElem &se) const =0
Definition: functors.hpp:127
virtual ~Storage()
Definition: functors.hpp:130
Storage(storedData &sd)
Definition: functors.hpp:129
storedData & storedData_
Definition: functors.hpp:133
virtual void operator()(const sesElem &se) const =0
Definition: functors.hpp:103
stream & out_
Definition: functors.hpp:119
UniHunkPrinter()
Definition: functors.hpp:105
void operator()(const uniHunk< sesElem > &hunk) const
Definition: functors.hpp:108
UniHunkPrinter(stream &out)
Definition: functors.hpp:106
~UniHunkPrinter()
Definition: functors.hpp:107
Definition: Diff.hpp:43
const edit_t SES_ADD
Definition: variables.hpp:74
const edit_t SES_COMMON
Definition: variables.hpp:73
const edit_t SES_DELETE
Definition: variables.hpp:72
Definition: variables.hpp:119
vector< sesElem > change
Definition: variables.hpp:122
long long b
Definition: variables.hpp:120
long long d
Definition: variables.hpp:120
long long c
Definition: variables.hpp:120
long long a
Definition: variables.hpp:120
vector< sesElem > common[2]
Definition: variables.hpp:121
#define SES_MARK_DELETE
Definition: variables.hpp:79
#define SES_MARK_ADD
Definition: variables.hpp:81
#define SES_MARK_COMMON
Definition: variables.hpp:80