2 dtl-1.12 -- Diff Template Library
4 In short, Diff Template Library is distributed under so called "BSD license",
6 Copyright (c) 2008-2011 Tatsuhiko Kubo <cubicdaiya@gmail.com>
9 Redistribution and use in source and binary forms, with or without modification,
10 are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 * Neither the name of the authors nor the names of its contributors
20 may be used to endorse or promote products derived from this software
21 without specific prior written permission.
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /* If you use this library, you must include dtl.hpp only. */
38 #ifndef DTL_FUNCTORS_H
39 #define DTL_FUNCTORS_H
44 * printer class template
46 template <typename sesElem, typename stream = ostream >
50 Printer () : out_(cout) {}
51 Printer (stream& out) : out_(out) {}
52 virtual ~Printer () {}
53 virtual void operator() (const sesElem& se) const = 0;
59 * common element printer class template
61 template <typename sesElem, typename stream = ostream >
62 class CommonPrinter : public Printer < sesElem, stream >
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;
74 * ses element printer class template
76 template <typename sesElem, typename stream = ostream >
77 class ChangePrinter : public Printer < sesElem, stream >
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) {
86 this->out_ << SES_MARK_ADD << se.first << endl;
89 this->out_ << SES_MARK_DELETE << se.first << endl;
92 this->out_ << SES_MARK_COMMON << se.first << endl;
99 * unfiend format element printer class template
101 template <typename sesElem, typename stream = ostream >
105 UniHunkPrinter () : out_(cout) {}
106 UniHunkPrinter (stream& out) : out_(out) {}
107 ~UniHunkPrinter () {}
108 void operator() (const uniHunk< sesElem >& hunk) const {
110 << " -" << hunk.a << "," << hunk.b
111 << " +" << hunk.c << "," << hunk.d
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_));
123 * compare class template
125 template <typename elem>
130 virtual ~Compare () {}
131 virtual inline bool impl (const elem& e1, const elem& e2) const {
137 #endif // DTL_FUNCTORS_H