added (broken, but running) diff routines for block-level diffs
[wikiq] / dtl / Ses.hpp
1 /**
2    dtl-1.12 -- Diff Template Library
3    
4    In short, Diff Template Library is distributed under so called "BSD license",
5    
6    Copyright (c) 2008-2011 Tatsuhiko Kubo <cubicdaiya@gmail.com>
7    All rights reserved.
8    
9    Redistribution and use in source and binary forms, with or without modification,
10    are permitted provided that the following conditions are met:
11    
12    * Redistributions of source code must retain the above copyright notice,
13    this list of conditions and the following disclaimer.
14    
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.
18    
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.
22    
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.
34 */
35
36 /* If you use this library, you must include dtl.hpp only. */
37
38 #ifndef DTL_SES_H
39 #define DTL_SES_H
40
41 namespace dtl {
42     
43     /**
44      * Shortest Edit Script template class
45      */
46     template <typename elem>
47     class Ses : public Sequence< elem >
48     {
49     private :
50         typedef pair< elem, elemInfo > sesElem;
51         typedef vector< sesElem >      sesElemVec;
52     public :
53         
54         Ses () : onlyAdd(true), onlyDelete(true), onlyCopy(true) { }
55         ~Ses () {}
56         
57         bool isOnlyAdd () const {
58             return onlyAdd;
59         }
60         
61         bool isOnlyDelete () const {
62             return onlyDelete;
63         }
64         
65         bool isOnlyCopy () const {
66             return onlyCopy;
67         }
68         
69         bool isOnlyOneOperation () const {
70             return isOnlyAdd() || isOnlyAdd() || isOnlyCopy();
71         }
72         
73         bool isChange () const {
74             return !onlyCopy;
75         }
76         
77         using Sequence< elem >::addSequence;
78         void addSequence (elem e, long long beforeIdx, long long afterIdx, const edit_t type) {
79             elemInfo info;
80             info.beforeIdx = beforeIdx;
81             info.afterIdx  = afterIdx;
82             info.type      = type;
83             sesElem pe(e, info);
84             sequence.push_back(pe);
85             switch (type) {
86             case SES_DELETE:
87                 onlyCopy   = false;
88                 onlyAdd    = false;
89                 break;
90             case SES_COMMON:
91                 onlyAdd    = false;
92                 onlyDelete = false;
93                 break;
94             case SES_ADD:
95                 onlyDelete = false;
96                 onlyCopy   = false;
97                 break;
98             }
99         }
100         
101         sesElemVec getSequence () const {
102             return sequence;
103         }
104     private :
105         sesElemVec sequence;
106         bool       onlyAdd;
107         bool       onlyDelete;
108         bool       onlyCopy;
109     };
110 }
111
112 #endif // DTL_SES_H

Benjamin Mako Hill || Want to submit a patch?