Welcome to mirror list, hosted at ThFree Co, Russian Federation.

StrokeAdvancedIterators.h « stroke « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ccf5773a4c8239453b22a3baa18cd99d7c58b3df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __FREESTYLE_STROKE_ADVANCED_ITERATORS_H__
#define __FREESTYLE_STROKE_ADVANCED_ITERATORS_H__

/** \file
 * \ingroup freestyle
 * \brief Iterators used to iterate over the elements of the Stroke. Can't be used in python
 */

#include "Stroke.h"

namespace Freestyle {

namespace StrokeInternal {

class vertex_const_traits : public Const_traits<StrokeVertex *> {
 public:
  typedef std::deque<StrokeVertex *> vertex_container;
  typedef vertex_container::const_iterator vertex_container_iterator;
};

class vertex_nonconst_traits : public Nonconst_traits<StrokeVertex *> {
 public:
  typedef std::deque<StrokeVertex *> vertex_container;  //! the vertices container
  typedef vertex_container::iterator vertex_container_iterator;
};

template<class Traits>
class vertex_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
 public:
  typedef vertex_iterator_base<Traits> Self;

 protected:
  typedef IteratorBase<Traits, BidirectionalIteratorTag_Traits> parent_class;
  typedef typename Traits::vertex_container_iterator vertex_container_iterator;
  typedef vertex_iterator_base<vertex_nonconst_traits> iterator;
  typedef vertex_iterator_base<vertex_const_traits> const_iterator;

  // protected:
 public:
  vertex_container_iterator _it;
  vertex_container_iterator _begin;
  vertex_container_iterator _end;

 public:
  friend class Stroke;
  // friend class vertex_iterator;

  inline vertex_iterator_base() : parent_class()
  {
  }

  inline vertex_iterator_base(const iterator &iBrother) : parent_class()
  {
    _it = iBrother._it;
    _begin = iBrother._begin;
    _end = iBrother._end;
  }

  inline vertex_iterator_base(const const_iterator &iBrother) : parent_class()
  {
    _it = iBrother._it;
    _begin = iBrother._begin;
    _end = iBrother._end;
  }

  // protected: //FIXME
 public:
  inline vertex_iterator_base(vertex_container_iterator it,
                              vertex_container_iterator begin,
                              vertex_container_iterator end)
      : parent_class()
  {
    _it = it;
    _begin = begin;
    _end = end;
  }

 public:
  virtual ~vertex_iterator_base()
  {
  }

  virtual bool begin() const
  {
    return (_it == _begin) ? true : false;
  }

  virtual bool end() const
  {
    return (_it == _end) ? true : false;
  }

  // operators
  inline Self &operator++()  // operator corresponding to ++i
  {
    ++_it;
    return *(this);
  }

  /* Operator corresponding to i++, i.e. which returns the value *and then* increments.
   * That's why we store the value in a temp.
   */
  inline Self operator++(int)
  {
    Self tmp = *this;
    ++_it;
    return tmp;
  }

  inline Self &operator--()  // operator corresponding to --i
  {
    --_it;
    return *(this);
  }

  inline Self operator--(int)
  {
    Self tmp = *this;
    --_it;
    return tmp;
  }

  // comparibility
  virtual bool operator!=(const Self &b) const
  {
    return (_it != b._it);
  }

  virtual bool operator==(const Self &b) const
  {
    return !(*this != b);
  }

  // dereferencing
  virtual typename Traits::reference operator*() const
  {
    return *(_it);
  }

  virtual typename Traits::pointer operator->() const
  {
    return &(operator*());
  }

  /*! accessors */
  inline vertex_container_iterator it() const
  {
    return _it;
  }

  inline vertex_container_iterator getBegin() const
  {
    return _begin;
  }

  inline vertex_container_iterator getEnd() const
  {
    return _end;
  }
};

}  // end of namespace StrokeInternal

} /* namespace Freestyle */

#endif  // __FREESTYLE_STROKE_ADVANCED_ITERATORS_H__