OSDN Git Service

iterator.txt Add. (From sfjp Wiki http://sourceforge.jp/projects/roast/wiki/iterator...
[roast/document.git] / iterator.txt
1 \81\84[FrontPage]\81\84[\83\8a\83t\83@\83\8c\83\93\83X]
2
3 = Roast+ \83C\83e\83\8c\81[\83^
4
5 Roast+\82Å\82Ì\83C\83e\83\8c\81[\83^\82Í\81ASTL\93\99\82Ì\82»\82ê\82Æ\82Í\88Ù\82È\82è\82Ü\82·\81B
6
7 {{{ comment
8
9 STL\82â\81A\82»\82ê\82É\8f\87\82¸\82é\8c`\82Å\8dì\90¬\82³\82ê\82Ä\82¢\82é
10 }}}
11
12 === \8dÅ\92á\8cÀ\96\9e\82½\82·\82×\82«\97v\8c\8f
13
14 {{{ code cpp
15         template <typename ValueType, typename IndexType>
16         class iterator_require
17         {
18         public:
19                 //      Next (Like iterator ++)
20                 void next();
21                 
22                 //      Iterator pointer iValid?
23                 bool is_valid();
24                 
25                 //      Value
26                 operator const ValueType() const ;
27                 ValueType& operator *();
28                 ValueType& operator ->();
29                 ValueType get_value();
30                 
31                 //      Index operations
32                 void set_index(const IndexType& index);
33                 IndexType get_index() const;
34                 
35                 //      Change the end pointer
36                 void change_end(const IndexType& index);
37         };
38 }}}
39 defined by [http://sourceforge.jp/projects/roast/svn/view/trunk/roast/include/roast/container/iterator_require.hpp?view=markup&root=roast roast/include/roast/container/iterator_require.hpp]
40
41  * ValueType\81\81\92l\82Ì\8c^
42  * IndexType\81\81\83C\83\93\83f\83b\83N\83X\82Ì\8c^
43
44 \82Å\82 \82é\81B\94C\88Ó\82Ì\8c^\82Å\82æ\82¢\81B
45 \82Ü\82½\81A\83R\83\93\83X\83g\83\89\83N\83^\81E\83f\83X\83g\83\89\83N\83^\82à\94C\88Ó\82É\92è\8b`\82µ\82Ä\82æ\82¢\81B
46
47 \82±\82Ì\83N\83\89\83X\82ð\8cp\8f³\82µ\81A\83I\81[\83o\81[\83\8d\81[\83h\82·\82é\8e\96\82à\8fo\97\88\82é\82ª\81A\8f\83\90\88\89¼\91z\8aÖ\90\94\82Å\82Í\82È\82¢\81i\89¼\91z\8aÖ\90\94\81A\8by\82Ñ\8f\83\90\88\89¼\91z\8aÖ\90\94\82ð\8eg\97p\82·\82é\82Æ\97]\95ª\82È\83I\81[\83o\81[\83w\83b\83h\82ª\95K\91R\93I\82É\94­\90\82µ\82Ä\82µ\82Ü\82¤\82½\82ß\81j\82½\82ß\92\8d\88Ó\82·\82é\82±\82Æ\81B
48
49 {{{ comment
50 \96¢\92è\8b`\82Ì\8fê\8d\87\82Å\82 \82Á\82Ä\82à\83C\83\93\83X\83^\83\93\83X\89»\82·\82é\8e\96\82ª\8fo\97\88\82Ä\82µ\82Ü\82¤\82Ì\82Å
51 }}}
52
53 === \83T\83\93\83v\83\8b
54
55 {{{ code cpp
56         
57         template <typename T, unsigned int _END=0, unsigned int _START=0>
58         class sample_iterator
59         {
60         protected:
61                 T* m_p_array;
62                 unsigned int m_index;
63                 unsigned int m_end;
64                 
65         public:
66                 //////////////////////////////////////////
67         
68                 //      Constructors
69                 primitive_array_iterator(T* p_array=NULL, unsigned int length=_END){
70                         m_p_array = p_array;
71                         m_index = _START;
72                         m_end = length;
73                 }
74                 primitive_array_iterator(T* p_array, unsigned int start, unsigned int end){
75                         m_p_array = p_array;
76                         m_index = start;
77                         m_end = end;
78                 }
79
80                 //////////////////////////////////////////
81                 
82                 //      Next
83                 void next()
84                 {
85                         m_index++;
86                 }
87                 
88                 //      IsValid?
89                 bool is_valid()
90                 {
91                         return m_index < m_end;
92                 }
93                 
94                 //////////////////////////////////////////
95                 
96                 operator const T() const 
97                 {
98                         return m_p_array[m_index];
99                 }
100                 
101                 T& operator *() 
102                 {
103                         return m_p_array[m_index];
104                 }
105                 
106                 T& operator ->() 
107                 {
108                         return m_p_array[m_index];
109                 }
110                 T get_value() const { return m_p_array[m_index]; }
111                 
112                 void set_index(unsigned int index) { m_index = index; }
113                 unsigned int get_index() const { return m_index; }
114                 
115                 void change_end(unsigned int index) { m_end = index; }
116         };
117 }}}
118
119 sample by [http://sourceforge.jp/projects/roast/svn/view/trunk/roast/include/roast/container/primitive_array_iterator.hpp?view=markup&root=roast roast/include/roast/container/primitive_array_iterator.hpp]
120
121 === \8aî\96{\93I\82È\83C\83e\83\8c\81[\83^
122  * [\8aî\96{\93I\82È\83C\83e\83\8c\81[\83^]