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