1
|
1 // Very simple integer vectors for indexing -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (_idx_vector_h) |
|
25 #define _idx_vector_h 1 |
|
26 |
|
27 #ifdef __GNUG__ |
|
28 #pragma interface |
|
29 #endif |
|
30 |
|
31 #include <stdlib.h> |
|
32 #include <assert.h> |
|
33 |
|
34 #define FAIL assert(0) /* XXX FIXME XXX */ |
|
35 |
164
|
36 class ostream; |
|
37 class Matrix; |
|
38 class Range; |
|
39 |
1
|
40 class idx_vector |
|
41 { |
|
42 public: |
|
43 idx_vector (void); |
|
44 idx_vector (const idx_vector& a); |
|
45 |
164
|
46 idx_vector (const Matrix& m, int do_ftn_idx, |
|
47 const char *rc = (char *) NULL, int z_len = 0); |
1
|
48 |
|
49 idx_vector (const Range& r); |
|
50 |
|
51 ~idx_vector (void); |
|
52 |
|
53 idx_vector& operator = (const idx_vector& a); |
|
54 |
|
55 int capacity (void) const; |
|
56 int length (void) const; |
|
57 |
|
58 int elem (int n) const; |
|
59 int checkelem (int n) const; |
|
60 int operator () (int n) const; |
|
61 |
|
62 // other stuff |
|
63 |
|
64 int max (void) const; |
|
65 int min (void) const; |
|
66 |
|
67 int one_zero_only (void) const; |
|
68 int zeros_count (void) const; |
|
69 int ones_count (void) const; |
|
70 |
|
71 // i/o |
|
72 |
|
73 friend ostream& operator << (ostream& os, const idx_vector& a); |
|
74 |
|
75 private: |
|
76 |
|
77 int len; |
|
78 int one_zero; |
|
79 int num_zeros; |
|
80 int num_ones; |
|
81 int max_val; |
|
82 int min_val; |
|
83 int *data; |
|
84 |
164
|
85 void init_state (const char *rc = (char *) NULL, int z_len = 0); |
1
|
86 void convert_one_zero_to_idx (void); |
|
87 }; |
|
88 |
|
89 inline idx_vector::idx_vector (void) |
|
90 { |
|
91 len = 0; |
|
92 data = 0; |
|
93 num_zeros = 0; |
|
94 num_ones = 0; |
|
95 one_zero = 0; |
|
96 } |
|
97 |
|
98 inline idx_vector::~idx_vector (void) |
|
99 { |
|
100 delete [] data; |
|
101 data = 0; |
|
102 num_zeros = 0; |
|
103 num_ones = 0; |
|
104 len = 0; |
|
105 one_zero = 0; |
|
106 } |
|
107 |
|
108 inline int idx_vector::capacity (void) const { return len; } |
|
109 inline int idx_vector::length (void) const { return len; } |
|
110 |
|
111 inline int idx_vector::elem (int n) const { return data[n]; } |
|
112 |
|
113 inline int |
|
114 idx_vector::checkelem (int n) const |
|
115 { |
|
116 if (n < 0 || n >= len) |
|
117 FAIL; |
|
118 |
|
119 return elem (n); |
|
120 } |
|
121 |
|
122 inline int idx_vector::operator () (int n) const { return checkelem (n); } |
|
123 |
|
124 inline int idx_vector::max (void) const { return max_val; } |
|
125 inline int idx_vector::min (void) const { return min_val; } |
|
126 |
|
127 inline int idx_vector::one_zero_only (void) const { return one_zero; } |
|
128 inline int idx_vector::zeros_count (void) const { return num_zeros; } |
|
129 inline int idx_vector::ones_count (void) const { return num_ones; } |
|
130 |
|
131 #endif |
|
132 |
|
133 /* |
|
134 ;;; Local Variables: *** |
|
135 ;;; mode: C++ *** |
|
136 ;;; page-delimiter: "^/\\*" *** |
|
137 ;;; End: *** |
|
138 */ |