update dev300-m58
[ooovba.git] / agg / inc / agg_vertex_iterator.h
blob63959fcbbde9f2db68fc4e1d50fd64e4728aadb4
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 // classes: vertex_iterator
17 // vertex_source_adaptor
18 // vertex_source_adaptor_with_id
20 //----------------------------------------------------------------------------
21 #ifndef AGG_VERTEX_ITERATOR_INCLUDED
22 #define AGG_VERTEX_ITERATOR_INCLUDED
24 #include "agg_basics.h"
27 namespace agg
30 //---------------------------------------------------------vertex_iterator
31 template<class VertexSource> class vertex_iterator
33 public:
34 vertex_iterator() {}
35 vertex_iterator(unsigned cmd) { m_vertex.cmd = cmd; }
36 vertex_iterator(const vertex_iterator& i) : m_vs(i.m_vs), m_vertex(i.m_vertex) {}
37 vertex_iterator(VertexSource& vs, unsigned id) : m_vs(&vs)
39 m_vs->rewind(id);
40 m_vertex.cmd = m_vs->vertex(&m_vertex.x, &m_vertex.y);
42 vertex_iterator& operator++()
44 m_vertex.cmd = m_vs->vertex(&m_vertex.x, &m_vertex.y);
45 return *this;
48 const vertex_type& operator*() const { return m_vertex; }
49 const vertex_type* operator->() const { return &m_vertex; }
51 bool operator != (const vertex_iterator& i)
53 return m_vertex.cmd != i.m_vertex.cmd;
56 private:
57 VertexSource* m_vs;
58 vertex_type m_vertex;
62 //---------------------------------------------------vertex_source_adaptor
63 template<class VertexContainer> class vertex_source_adaptor
65 public:
66 vertex_source_adaptor(const VertexContainer& container) :
67 m_container(&container) {}
69 void rewind(unsigned)
71 m_iterator = m_container->begin();
72 m_end = m_container->end();
75 unsigned vertex(double* x, double* y)
77 unsigned cmd = path_cmd_stop;
78 if(m_iterator != m_end)
80 *x = m_iterator->x;
81 *y = m_iterator->y;
82 cmd = m_iterator->cmd;
83 ++m_iterator;
85 return cmd;
88 private:
89 const VertexContainer* m_container;
90 typename VertexContainer::const_iterator m_iterator;
91 typename VertexContainer::const_iterator m_end;
96 //-------------------------------------------vertex_source_adaptor_with_id
97 template<class VertexContainer> class vertex_source_adaptor_with_id
99 public:
100 vertex_source_adaptor_with_id(const VertexContainer& container) :
101 m_container(&container) {}
103 void rewind(unsigned id)
105 m_iterator = m_container->begin(id);
106 m_end = m_container->end();
109 unsigned vertex(double* x, double* y)
111 unsigned cmd = path_cmd_stop;
112 if(m_iterator != m_end)
114 *x = m_iterator->x;
115 *y = m_iterator->y;
116 cmd = m_iterator->cmd;
117 ++m_iterator;
119 return cmd;
122 private:
123 const VertexContainer* m_container;
124 typename VertexContainer::const_iterator m_iterator;
125 typename VertexContainer::const_iterator m_end;
133 #endif