]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Array.h
e556912f6037672148eb21cb7fbcce2a823327e9
[wxWidgets.git] / src / stc / scintilla / src / Array.h
1 /** file Array.h
2 * This file is defining a kind of tool for simulating std::vector
3 * for using wx on OS which are not supporting the STL
4 * @author foldink (foldink@gmail.com)
5 * @date 26-February-2010
6 */
7
8 #ifndef ARRAY_H
9 #define ARRAY_H
10
11 #include <stdio.h>
12 /* defines */
13 class Array;
14 class ArrayIterator;
15 //struct SelectionRange;
16
17 /**
18 * @class ArrayIterator
19 * @brief This class is used to simulate an iterator in the array
20 * @author foldink (foldink@gmail.com)
21 * @date 26-February-2010
22 */
23 class ArrayIterator
24 {
25 friend class Array;
26
27 public :
28 /** ctor
29 * @param parent, parented array to store positions in
30 */
31 ArrayIterator( Array* parent , size_t idx ):
32 m_parent(parent),
33 m_idx(idx) {};
34
35 /** dtor */
36 virtual ~ArrayIterator()
37 {
38 m_parent = 0L;
39 }
40
41 /** copy ctor */
42 ArrayIterator(const ArrayIterator& rhs):
43 m_parent(rhs.m_parent),
44 m_idx(rhs.m_idx) { }
45
46 /***********************************************************************
47 * OPERATOR OVERLOADS
48 **********************************************************************/
49 /** the equal operator is used to overload copy for the array */
50 ArrayIterator& operator=(const ArrayIterator& rhs)
51 {
52 m_parent = rhs.m_parent;
53 m_idx = rhs.m_idx;
54
55 return (*this);
56 }
57
58 /** Smart pointer part overload as it is in standard templates arrays */
59 SelectionRange& operator*();
60
61 /** a++ operator */
62 ArrayIterator operator++(int);
63
64 /** ++a operator */
65 ArrayIterator& operator++();
66
67 /** a-- operator */
68 ArrayIterator operator--(int);
69
70 /** --a operator */
71 ArrayIterator& operator--();
72
73 /** a + int operator */
74 ArrayIterator operator+(size_t idx);
75
76 /** a - int operator */
77 ArrayIterator operator-(size_t idx);
78
79 /** a += int operator */
80 ArrayIterator& operator+=(size_t idx);
81
82 /** a -= int operator */
83 ArrayIterator& operator-=(size_t idx);
84
85 /** != operator */
86 bool operator!=(const ArrayIterator& rhs);
87
88 /** == operator */
89 bool operator==(const ArrayIterator& rhs);
90
91 /** Set the idx if needed */
92 void SetIdx(size_t idx) {m_idx = idx;};
93 /** Get the idx if needed */
94 size_t GetIdx() {return m_idx;};
95
96 Array* m_parent;
97 size_t m_idx;
98 };
99
100 /**
101 * @class Array
102 * @brief simple array of SelectionRange
103 * @brief This class is used to simulate an iterator in the array
104 * @author foldink (foldink@gmail.com)
105 * @date 26-February-2010
106 */
107 class Array
108 {
109 friend class ArrayIterator;
110
111 public :
112 /** default ctor taking the len in input */
113 Array( size_t len = 0 );
114
115 /** ctor with len and initial value */
116 Array( size_t len , const SelectionRange& val );
117
118 /** copy ctor */
119 Array( const Array& rhs );
120
121 /** dtor */
122 virtual ~Array();
123
124 /** operator= */
125 Array& operator=( const Array& rhs );
126
127 /** operator[] */
128 SelectionRange& operator[]( size_t idx )
129 {
130 if( idx >= m_size )
131 throw "Error access to vector range out of bounds";
132
133 return *(m_data + idx);
134 }
135
136 /** operator[] */
137 const SelectionRange& operator[]( size_t idx ) const
138 {
139 if( idx >= m_size )
140 throw "Error access to vector range out of bounds";
141
142 return *(m_data + idx);
143 }
144
145 /** Get the size */
146 size_t size() const {return m_size;};
147
148 /** check if the array is empty or not */
149 bool empty() const {return (m_size == 0);};
150
151 /** reserve */
152 void reserve( size_t len );
153
154 /** front */
155 SelectionRange& front() {
156 if( !m_data )
157 throw "Trying to access to an uninitialized array";
158
159 return (*m_data);
160 }
161
162 /** back */
163 SelectionRange& back() {
164 if( !m_data )
165 throw "Trying to access to an uninitialized array";
166
167 return *(m_data + m_size-1);
168 }
169
170 /** push back */
171 void push_back( const SelectionRange& val );
172
173 /** pop back */
174 void pop_back( );
175
176 /** insert before the given iterator position */
177 void insert( ArrayIterator it , SelectionRange& val );
178
179 /** erase */
180 void erase( ArrayIterator it );
181
182 /** clear */
183 void clear( );
184
185 /** resize */
186 void resize( size_t n , SelectionRange val = SelectionRange() );
187
188 /** == operator */
189 bool operator==(const Array& rhs);
190
191 /** begin */
192 ArrayIterator begin();
193
194 /** end */
195 ArrayIterator end();
196
197 private :
198 SelectionRange* m_data;
199 size_t m_size;
200 };
201
202 /**
203 * @brief Sorting method for a replace in Editor.cxx
204 * @author foldink (foldink@gmail.com)
205 * @date 26-February-2010
206 */
207 extern void ArraySort( ArrayIterator start , ArrayIterator finish );
208
209 #endif