Guitar
Ses.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_SES_H
39 #define DTL_SES_H
40 
41 namespace dtl {
42 
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), deletesFirst(false) {
55  nextDeleteIdx = 0;
56  }
57  Ses (bool moveDel) : onlyAdd(true), onlyDelete(true), onlyCopy(true), deletesFirst(moveDel) {
58  nextDeleteIdx = 0;
59  }
60  ~Ses () {}
61 
62  bool isOnlyAdd () const {
63  return onlyAdd;
64  }
65 
66  bool isOnlyDelete () const {
67  return onlyDelete;
68  }
69 
70  bool isOnlyCopy () const {
71  return onlyCopy;
72  }
73 
74  bool isOnlyOneOperation () const {
75  return isOnlyAdd() || isOnlyDelete() || isOnlyCopy();
76  }
77 
78  bool isChange () const {
79  return !onlyCopy;
80  }
81 
83  void addSequence (elem e, long long beforeIdx, long long afterIdx, const edit_t type) {
84  elemInfo info;
85  info.beforeIdx = beforeIdx;
86  info.afterIdx = afterIdx;
87  info.type = type;
88  sesElem pe(e, info);
89  if (!deletesFirst) {
90  sequence.push_back(pe);
91  }
92  switch (type) {
93  case SES_DELETE:
94  onlyCopy = false;
95  onlyAdd = false;
96  if (deletesFirst) {
97  sequence.insert(sequence.begin() + nextDeleteIdx, pe);
98  nextDeleteIdx++;
99  }
100  break;
101  case SES_COMMON:
102  onlyAdd = false;
103  onlyDelete = false;
104  if (deletesFirst) {
105  sequence.push_back(pe);
106  nextDeleteIdx = sequence.size();
107  }
108  break;
109  case SES_ADD:
110  onlyDelete = false;
111  onlyCopy = false;
112  if (deletesFirst) {
113  sequence.push_back(pe);
114  }
115  break;
116  }
117  }
118 
120  return sequence;
121  }
122  private :
124  bool onlyAdd;
126  bool onlyCopy;
129  };
130 }
131 
132 #endif // DTL_SES_H
Definition: Sequence.hpp:48
Definition: Ses.hpp:48
bool isOnlyAdd() const
Definition: Ses.hpp:62
~Ses()
Definition: Ses.hpp:60
Ses()
Definition: Ses.hpp:54
bool isOnlyCopy() const
Definition: Ses.hpp:70
bool onlyCopy
Definition: Ses.hpp:126
Ses(bool moveDel)
Definition: Ses.hpp:57
bool isChange() const
Definition: Ses.hpp:78
bool onlyDelete
Definition: Ses.hpp:125
sesElemVec sequence
Definition: Ses.hpp:123
sesElemVec getSequence() const
Definition: Ses.hpp:119
size_t nextDeleteIdx
Definition: Ses.hpp:128
bool onlyAdd
Definition: Ses.hpp:124
bool isOnlyOneOperation() const
Definition: Ses.hpp:74
bool isOnlyDelete() const
Definition: Ses.hpp:66
pair< elem, elemInfo > sesElem
Definition: Ses.hpp:50
void addSequence(elem e, long long beforeIdx, long long afterIdx, const edit_t type)
Definition: Ses.hpp:83
vector< sesElem > sesElemVec
Definition: Ses.hpp:51
bool deletesFirst
Definition: Ses.hpp:127
Definition: Diff.hpp:43
int edit_t
Definition: variables.hpp:71
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:86
long long afterIdx
Definition: variables.hpp:88
long long beforeIdx
Definition: variables.hpp:87
edit_t type
Definition: variables.hpp:89