Documentation.
[qshowdiff.git] / hunk.h
bloba73fd36b4bb03a4d8f206f6edc5128c4494c8fef
1 #ifndef _HUNK_H_
2 #define _HUNK_H_
4 #include <vector>
6 #include "snippet.h"
7 #include "utils.h"
10 /**
11 * This class describes a hunk of changes from diff.
12 * Hunk is aggregation of snippets.
14 class Hunk{
15 private:
16 std::vector<Snippet *> _snippets;//! list of snippets
17 int _original_from_line;//! line on which begin changes in original file
18 int _modified_from_line;//! line on which begin changes in modified file
20 void _copy(const Hunk &);
21 void _free();
22 public:
23 class iterator; // front declaration
25 Hunk(const int original_from, const int modified_from) :
26 _original_from_line(original_from),
27 _modified_from_line(modified_from){}
28 Hunk(const Hunk &h){ _copy(h); }
29 ~Hunk(){ _free(); }
31 Hunk &operator=(const Hunk &h){ _free(); _copy(h); return *this; }
33 void addSnippet(Snippet *sn){ _snippets.push_back(sn); }
34 int numSnippets() const { return _snippets.size(); }
36 int originalBeginsAt() const { return _original_from_line;}
37 int modifiedBeginsAt() const { return _modified_from_line;}
39 iterator begin() const;
40 iterator end() const;
42 /**
43 * Iterator over _snippets.
45 class iterator : public VectorPointerIterator<Snippet>{
46 public:
47 friend iterator Hunk::begin() const;
48 friend iterator Hunk::end() const;
51 #endif