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 |
1879
|
67 idx_vector_rep (char c); |
1560
|
68 |
1879
|
69 idx_vector_rep (const idx_vector_rep& a); |
1560
|
70 |
1879
|
71 idx_vector_rep::~idx_vector_rep (void) { delete [] data; } |
1560
|
72 |
1879
|
73 idx_vector_rep& operator = (const idx_vector_rep& a); |
1560
|
74 |
1879
|
75 int ok (void) { return initialized; } |
1560
|
76 |
1879
|
77 int capacity (void) const { return len; } |
|
78 int length (int colon_len) const { return colon ? colon_len : len; } |
1560
|
79 |
1879
|
80 int elem (int n) const { return colon ? n : data[n]; } |
1560
|
81 |
1879
|
82 int checkelem (int n) const; |
|
83 int operator () (int n) const { return checkelem (n); } |
1560
|
84 |
1879
|
85 int max (void) const { return max_val; } |
|
86 int min (void) const { return min_val; } |
|
87 |
|
88 int one_zero_only (void) const { return one_zero; } |
|
89 int zeros_count (void) const { return num_zeros; } |
|
90 int ones_count (void) const { return num_ones; } |
|
91 |
|
92 int is_colon (void) const { return colon; } |
2356
|
93 int is_colon_equiv (int n, int sort_uniq); |
1560
|
94 |
1879
|
95 int orig_rows (void) const { return orig_nr; } |
|
96 int orig_columns (void) const { return orig_nc; } |
1560
|
97 |
1879
|
98 // other stuff |
1560
|
99 |
1879
|
100 void shorten (int n); // Unsafe. Avoid at all cost. |
1560
|
101 |
1879
|
102 int freeze (int z_len, const char *tag, int prefer_zero_one, |
|
103 int resize_ok); |
1560
|
104 |
1879
|
105 // i/o |
1560
|
106 |
1879
|
107 ostream& print (ostream& os) const; |
1560
|
108 |
1879
|
109 int *data; |
|
110 int len; |
|
111 int num_zeros; |
|
112 int num_ones; |
|
113 int max_val; |
|
114 int min_val; |
|
115 int orig_nr; |
|
116 int orig_nc; |
|
117 int count; |
|
118 int frozen_at_z_len; |
|
119 int frozen_len; |
|
120 unsigned int colon : 1; |
|
121 unsigned int one_zero : 1; |
|
122 unsigned int initialized : 1; |
|
123 unsigned int frozen : 1; |
|
124 unsigned int colon_equiv_checked : 1; |
|
125 unsigned int colon_equiv : 1; |
1560
|
126 |
1879
|
127 void init_state (void); |
1560
|
128 |
1879
|
129 void maybe_convert_one_zero_to_idx (int z_len, int prefer_zero_one); |
|
130 }; |
1560
|
131 |
1
|
132 public: |
1551
|
133 |
|
134 idx_vector::idx_vector (void) |
|
135 { |
1560
|
136 rep = new idx_vector_rep (); |
|
137 rep->count = 1; |
|
138 } |
|
139 |
|
140 idx_vector (const ColumnVector& v) |
|
141 { |
|
142 rep = new idx_vector_rep (v); |
|
143 rep->count = 1; |
|
144 } |
|
145 |
|
146 idx_vector (const Matrix& m) |
|
147 { |
|
148 rep = new idx_vector_rep (m); |
|
149 rep->count = 1; |
|
150 } |
|
151 |
|
152 idx_vector (const Range& r) |
|
153 { |
|
154 rep = new idx_vector_rep (r); |
|
155 rep->count = 1; |
|
156 } |
|
157 |
|
158 idx_vector (char c) |
|
159 { |
|
160 rep = new idx_vector_rep (c); |
|
161 rep->count = 1; |
|
162 } |
|
163 |
|
164 idx_vector (const idx_vector& a) |
|
165 { |
|
166 rep = a.rep; |
|
167 rep->count++; |
1551
|
168 } |
|
169 |
1560
|
170 idx_vector::~idx_vector (void) |
|
171 { |
|
172 if (--rep->count <= 0) |
|
173 delete rep; |
|
174 } |
1
|
175 |
1560
|
176 idx_vector& operator = (const idx_vector& a) |
|
177 { |
|
178 if (this != &a) |
|
179 { |
|
180 if (--rep->count <= 0) |
|
181 delete rep; |
1
|
182 |
1560
|
183 rep = a.rep; |
|
184 rep->count++; |
|
185 } |
|
186 return *this; |
1551
|
187 } |
|
188 |
1560
|
189 idx_vector::operator void * () const { return (void *) rep->ok (); } |
|
190 |
|
191 int idx_vector::capacity (void) const { return rep->capacity (); } |
|
192 int idx_vector::length (int cl) const { return rep->length (cl); } |
191
|
193 |
1560
|
194 int idx_vector::elem (int n) const { return rep->elem (n); } |
|
195 int idx_vector::checkelem (int n) const { return rep->checkelem (n); } |
|
196 int idx_vector::operator () (int n) const { return rep->operator () (n); } |
1
|
197 |
1560
|
198 int idx_vector::max (void) const { return rep->max (); } |
|
199 int idx_vector::min (void) const { return rep->min (); } |
1551
|
200 |
1560
|
201 int idx_vector::one_zero_only (void) const { return rep->one_zero_only (); } |
|
202 int idx_vector::zeros_count (void) const { return rep->zeros_count (); } |
|
203 int idx_vector::ones_count (void) const { return rep->ones_count (); } |
1
|
204 |
1560
|
205 int is_colon (void) const { return rep->is_colon (); } |
2356
|
206 int is_colon_equiv (int n, int sort_uniq = 0) const |
|
207 { return rep->is_colon_equiv (n, sort_uniq); } |
1
|
208 |
1560
|
209 int orig_rows (void) const { return rep->orig_rows (); } |
|
210 int orig_columns (void) const { return rep->orig_columns (); } |
208
|
211 |
1560
|
212 // Unsafe. Avoid at all cost. |
|
213 void shorten (int n) { rep->shorten (n); } |
434
|
214 |
1
|
215 // i/o |
|
216 |
1560
|
217 int freeze (int z_len, const char *tag, int prefer_zero_one = 0, |
|
218 int resize_ok = 0) |
|
219 { return rep->freeze (z_len, tag, prefer_zero_one, resize_ok); } |
|
220 |
|
221 ostream& print (ostream& os) const { return rep->print (os); } |
|
222 |
|
223 friend ostream& operator << (ostream& os, const idx_vector& a) |
|
224 { return a.print (os); } |
|
225 |
|
226 void maybe_convert_one_zero_to_idx (int z_len, int prefer_zero_one = 0) |
|
227 { rep->maybe_convert_one_zero_to_idx (z_len, prefer_zero_one); } |
1
|
228 |
|
229 private: |
|
230 |
1560
|
231 idx_vector_rep *rep; |
1
|
232 |
1560
|
233 void init_state (void) { rep->init_state (); } |
1
|
234 }; |
|
235 |
|
236 #endif |
|
237 |
|
238 /* |
|
239 ;;; Local Variables: *** |
|
240 ;;; mode: C++ *** |
|
241 ;;; End: *** |
|
242 */ |