Sun, 30 Aug 2015 04:45:16 +0300
Fix result reporting in "add borders"
956
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | #pragma once |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | #include "ldObject.h" |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | #include "ldDocument.h" |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | template<typename T> |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | class LDObjectIterator |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | public: |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | LDObjectIterator (LDDocument* doc) : |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | m_list (doc->objects()), |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | m_i (-1) |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | seekTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | LDObjectIterator (const LDObjectList& objs) : |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | m_list (objs), |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | m_i (-1) |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | seekTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | bool outOfBounds() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | return m_i < 0 or m_i >= m_list.size(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | T* get() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | return (T*) m_list[m_i]; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | bool isValid() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | return not outOfBounds() and get()->type() == T::SubclassType; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | void seek (int i) |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | m_i = i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | void seekTillValid() |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | do ++m_i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | while (not outOfBounds() and not isValid()); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | void rewindTillValid() |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | do --m_i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | while (m_i >= 0 and not isValid()); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | int tell() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | return m_i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | T* operator*() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | return get(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | T* operator->() const |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | return get(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | void operator++() |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | seekTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | void operator++ (int) |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | seekTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | void operator--() |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | rewindTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | void operator-- (int) |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | { |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | rewindTillValid(); |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | } |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | private: |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | const LDObjectList& m_list; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | int m_i; |
2af18ba2665f
Replace LDIterate function with LDObjectIterator class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | }; |