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
dtl::Ses::isOnlyDelete
bool isOnlyDelete() const
Definition: Ses.hpp:66
dtl::eleminfo::afterIdx
long long afterIdx
Definition: variables.hpp:88
dtl::Ses::sequence
sesElemVec sequence
Definition: Ses.hpp:123
dtl::Ses::Ses
Ses()
Definition: Ses.hpp:54
dtl::Ses::isOnlyCopy
bool isOnlyCopy() const
Definition: Ses.hpp:70
dtl::SES_ADD
const edit_t SES_ADD
Definition: variables.hpp:74
dtl::Ses::deletesFirst
bool deletesFirst
Definition: Ses.hpp:127
dtl::Ses::isOnlyOneOperation
bool isOnlyOneOperation() const
Definition: Ses.hpp:74
dtl::edit_t
int edit_t
Definition: variables.hpp:71
dtl::Ses::sesElemVec
vector< sesElem > sesElemVec
Definition: Ses.hpp:51
dtl::Ses::isOnlyAdd
bool isOnlyAdd() const
Definition: Ses.hpp:62
dtl::SES_DELETE
const edit_t SES_DELETE
Definition: variables.hpp:72
dtl::SES_COMMON
const edit_t SES_COMMON
Definition: variables.hpp:73
dtl::Ses::isChange
bool isChange() const
Definition: Ses.hpp:78
dtl::Ses::getSequence
sesElemVec getSequence() const
Definition: Ses.hpp:119
dtl::eleminfo
Definition: variables.hpp:86
dtl::Ses::Ses
Ses(bool moveDel)
Definition: Ses.hpp:57
dtl
Definition: Diff.hpp:41
dtl::eleminfo::type
edit_t type
Definition: variables.hpp:89
dtl::Ses::~Ses
~Ses()
Definition: Ses.hpp:60
dtl::Ses::onlyDelete
bool onlyDelete
Definition: Ses.hpp:125
dtl::eleminfo::beforeIdx
long long beforeIdx
Definition: variables.hpp:87
dtl::Ses::sesElem
pair< elem, elemInfo > sesElem
Definition: Ses.hpp:50
dtl::Sequence
Definition: Sequence.hpp:47
dtl::Ses::nextDeleteIdx
size_t nextDeleteIdx
Definition: Ses.hpp:128
dtl::Ses::addSequence
void addSequence(elem e, long long beforeIdx, long long afterIdx, const edit_t type)
Definition: Ses.hpp:83
dtl::Ses::onlyAdd
bool onlyAdd
Definition: Ses.hpp:124
dtl::Ses
Definition: Ses.hpp:47
dtl::Ses::onlyCopy
bool onlyCopy
Definition: Ses.hpp:126