NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
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
41namespace 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 elem>
127 {
128 public :
130 virtual ~Compare () {}
131 virtual inline bool impl (const elem& e1, const elem& e2) const {
132 return e1 == e2;
133 }
134 };
135}
136
137#endif // DTL_FUNCTORS_H
ChangePrinter(stream &out)
Definition: functors.hpp:81
void operator()(const sesElem &se) const
Definition: functors.hpp:83
CommonPrinter(stream &out)
Definition: functors.hpp:66
void operator()(const sesElem &se) const
Definition: functors.hpp:68
virtual bool impl(const elem &e1, const elem &e2) const
Definition: functors.hpp:131
virtual ~Compare()
Definition: functors.hpp:130
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
void operator()(const uniHunk< sesElem > &hunk) const
Definition: functors.hpp:108
UniHunkPrinter(stream &out)
Definition: functors.hpp:106
Definition: Diff.hpp:41
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
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