1
|
1 /* |
|
2 |
1882
|
3 Copyright (C) 1996 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
383
|
23 #if !defined (octave_idx_vector_h) |
|
24 #define octave_idx_vector_h 1 |
1
|
25 |
1297
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
164
|
30 class ostream; |
1560
|
31 class ColumnVector; |
164
|
32 class Matrix; |
|
33 class Range; |
|
34 |
453
|
35 class |
|
36 idx_vector |
1
|
37 { |
1560
|
38 private: |
|
39 |
1879
|
40 class |
1560
|
41 idx_vector_rep |
1879
|
42 { |
|
43 public: |
|
44 |
|
45 idx_vector_rep::idx_vector_rep (void) |
|
46 { |
|
47 colon = 0; |
|
48 len = 0; |
|
49 num_zeros = 0; |
|
50 num_ones = 0; |
|
51 one_zero = 0; |
|
52 orig_nr = 0; |
|
53 orig_nc = 0; |
|
54 initialized = 0; |
|
55 frozen = 0; |
|
56 colon_equiv_checked = 0; |
|
57 colon_equiv = 0; |
|
58 data = 0; |
|
59 } |
1560
|
60 |
1879
|
61 idx_vector_rep (const ColumnVector& v); |
1560
|
62 |
1879
|
63 idx_vector_rep (const Matrix& m); |
|
64 |
|
65 idx_vector_rep (const Range& r); |
1560
|
66 |
2386
|
67 idx_vector_rep (double d); |
|
68 |
1879
|
69 idx_vector_rep (char c); |
1560
|
70 |
1879
|
71 idx_vector_rep (const idx_vector_rep& a); |
1560
|
72 |
1879
|
73 idx_vector_rep::~idx_vector_rep (void) { delete [] data; } |
1560
|
74 |
1879
|
75 idx_vector_rep& operator = (const idx_vector_rep& a); |
1560
|
76 |
1879
|
77 int ok (void) { return initialized; } |
1560
|
78 |
1879
|
79 int capacity (void) const { return len; } |
|
80 int length (int colon_len) const { return colon ? colon_len : len; } |
1560
|
81 |
1879
|
82 int elem (int n) const { return colon ? n : data[n]; } |
1560
|
83 |
1879
|
84 int checkelem (int n) const; |
|
85 int operator () (int n) const { return checkelem (n); } |
1560
|
86 |
1879
|
87 int max (void) const { return max_val; } |
|
88 int min (void) const { return min_val; } |
|
89 |
|
90 int one_zero_only (void) const { return one_zero; } |
|
91 int zeros_count (void) const { return num_zeros; } |
|
92 int ones_count (void) const { return num_ones; } |
|
93 |
|
94 int is_colon (void) const { return colon; } |
2356
|
95 int is_colon_equiv (int n, int sort_uniq); |
1560
|
96 |
1879
|
97 int orig_rows (void) const { return orig_nr; } |
|
98 int orig_columns (void) const { return orig_nc; } |
1560
|
99 |
1879
|
100 // other stuff |
1560
|
101 |
1879
|
102 void shorten (int n); // Unsafe. Avoid at all cost. |
1560
|
103 |
1879
|
104 int freeze (int z_len, const char *tag, int prefer_zero_one, |
|
105 int resize_ok); |
1560
|
106 |
1879
|
107 // i/o |
1560
|
108 |
1879
|
109 ostream& print (ostream& os) const; |
1560
|
110 |
1879
|
111 int *data; |
|
112 int len; |
|
113 int num_zeros; |
|
114 int num_ones; |
|
115 int max_val; |
|
116 int min_val; |
|
117 int orig_nr; |
|
118 int orig_nc; |
|
119 int count; |
|
120 int frozen_at_z_len; |
|
121 int frozen_len; |
|
122 unsigned int colon : 1; |
|
123 unsigned int one_zero : 1; |
|
124 unsigned int initialized : 1; |
|
125 unsigned int frozen : 1; |
|
126 unsigned int colon_equiv_checked : 1; |
|
127 unsigned int colon_equiv : 1; |
1560
|
128 |
1879
|
129 void init_state (void); |
1560
|
130 |
1879
|
131 void maybe_convert_one_zero_to_idx (int z_len, int prefer_zero_one); |
|
132 }; |
1560
|
133 |
1
|
134 public: |
1551
|
135 |
|
136 idx_vector::idx_vector (void) |
|
137 { |
1560
|
138 rep = new idx_vector_rep (); |
|
139 rep->count = 1; |
|
140 } |
|
141 |
|
142 idx_vector (const ColumnVector& v) |
|
143 { |
|
144 rep = new idx_vector_rep (v); |
|
145 rep->count = 1; |
|
146 } |
|
147 |
|
148 idx_vector (const Matrix& m) |
|
149 { |
|
150 rep = new idx_vector_rep (m); |
|
151 rep->count = 1; |
|
152 } |
|
153 |
|
154 idx_vector (const Range& r) |
|
155 { |
|
156 rep = new idx_vector_rep (r); |
|
157 rep->count = 1; |
|
158 } |
|
159 |
2386
|
160 idx_vector (double d) |
|
161 { |
|
162 rep = new idx_vector_rep (d); |
|
163 rep->count = 1; |
|
164 } |
|
165 |
1560
|
166 idx_vector (char c) |
|
167 { |
|
168 rep = new idx_vector_rep (c); |
|
169 rep->count = 1; |
|
170 } |
|
171 |
|
172 idx_vector (const idx_vector& a) |
|
173 { |
|
174 rep = a.rep; |
|
175 rep->count++; |
1551
|
176 } |
|
177 |
1560
|
178 idx_vector::~idx_vector (void) |
|
179 { |
|
180 if (--rep->count <= 0) |
|
181 delete rep; |
|
182 } |
1
|
183 |
1560
|
184 idx_vector& operator = (const idx_vector& a) |
|
185 { |
|
186 if (this != &a) |
|
187 { |
|
188 if (--rep->count <= 0) |
|
189 delete rep; |
1
|
190 |
1560
|
191 rep = a.rep; |
|
192 rep->count++; |
|
193 } |
|
194 return *this; |
1551
|
195 } |
|
196 |
1560
|
197 idx_vector::operator void * () const { return (void *) rep->ok (); } |
|
198 |
|
199 int idx_vector::capacity (void) const { return rep->capacity (); } |
|
200 int idx_vector::length (int cl) const { return rep->length (cl); } |
191
|
201 |
1560
|
202 int idx_vector::elem (int n) const { return rep->elem (n); } |
|
203 int idx_vector::checkelem (int n) const { return rep->checkelem (n); } |
|
204 int idx_vector::operator () (int n) const { return rep->operator () (n); } |
1
|
205 |
1560
|
206 int idx_vector::max (void) const { return rep->max (); } |
|
207 int idx_vector::min (void) const { return rep->min (); } |
1551
|
208 |
1560
|
209 int idx_vector::one_zero_only (void) const { return rep->one_zero_only (); } |
|
210 int idx_vector::zeros_count (void) const { return rep->zeros_count (); } |
|
211 int idx_vector::ones_count (void) const { return rep->ones_count (); } |
1
|
212 |
1560
|
213 int is_colon (void) const { return rep->is_colon (); } |
2356
|
214 int is_colon_equiv (int n, int sort_uniq = 0) const |
|
215 { return rep->is_colon_equiv (n, sort_uniq); } |
1
|
216 |
1560
|
217 int orig_rows (void) const { return rep->orig_rows (); } |
|
218 int orig_columns (void) const { return rep->orig_columns (); } |
208
|
219 |
2663
|
220 int orig_empty (void) const |
|
221 { |
|
222 return (! is_colon () |
|
223 && (orig_rows () == 0 || orig_columns () == 0)); |
|
224 } |
|
225 |
1560
|
226 // Unsafe. Avoid at all cost. |
|
227 void shorten (int n) { rep->shorten (n); } |
434
|
228 |
1
|
229 // i/o |
|
230 |
1560
|
231 int freeze (int z_len, const char *tag, int prefer_zero_one = 0, |
|
232 int resize_ok = 0) |
|
233 { return rep->freeze (z_len, tag, prefer_zero_one, resize_ok); } |
|
234 |
|
235 ostream& print (ostream& os) const { return rep->print (os); } |
|
236 |
|
237 friend ostream& operator << (ostream& os, const idx_vector& a) |
|
238 { return a.print (os); } |
|
239 |
|
240 void maybe_convert_one_zero_to_idx (int z_len, int prefer_zero_one = 0) |
|
241 { rep->maybe_convert_one_zero_to_idx (z_len, prefer_zero_one); } |
1
|
242 |
|
243 private: |
|
244 |
1560
|
245 idx_vector_rep *rep; |
1
|
246 |
1560
|
247 void init_state (void) { rep->init_state (); } |
1
|
248 }; |
|
249 |
|
250 #endif |
|
251 |
|
252 /* |
|
253 ;;; Local Variables: *** |
|
254 ;;; mode: C++ *** |
|
255 ;;; End: *** |
|
256 */ |