Mercurial > octave-nkf
comparison liboctave/DiagArray2.cc @ 4645:bd2067547b40
[project @ 2003-11-23 08:07:52 by jwe]
author | jwe |
---|---|
date | Sun, 23 Nov 2003 08:07:53 +0000 |
parents | 508238e65af7 |
children | e35b034d3523 |
comparison
equal
deleted
inserted
replaced
4644:3b74f1a86750 | 4645:bd2067547b40 |
---|---|
37 | 37 |
38 #include "lo-error.h" | 38 #include "lo-error.h" |
39 | 39 |
40 // A two-dimensional array with diagonal elements only. | 40 // A two-dimensional array with diagonal elements only. |
41 | 41 |
42 #if 0 | |
43 template <class T> | |
44 T& | |
45 DiagArray2<T>::elem (int r, int c) | |
46 { | |
47 static T foo (0); | |
48 return (r == c) ? Array<T>::xelem (r) : foo; | |
49 } | |
50 | |
51 template <class T> | |
52 T& | |
53 DiagArray2<T>::checkelem (int r, int c) | |
54 { | |
55 static T foo (0); | |
56 if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) | |
57 { | |
58 (*current_liboctave_error_handler) ("range error in DiagArray2"); | |
59 return foo; | |
60 } | |
61 return (r == c) ? Array<T>::xelem (r) : foo; | |
62 } | |
63 | |
64 template <class T> | |
65 T& | |
66 DiagArray2<T>::operator () (int r, int c) | |
67 { | |
68 static T foo (0); | |
69 if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) | |
70 { | |
71 (*current_liboctave_error_handler) ("range error in DiagArray2"); | |
72 return foo; | |
73 } | |
74 return (r == c) ? Array<T>::xelem (r) : foo; | |
75 } | |
76 #endif | |
77 | |
78 template <class T> | 42 template <class T> |
79 T | 43 T |
80 DiagArray2<T>::elem (int r, int c) const | 44 DiagArray2<T>::elem (int r, int c) const |
81 { | 45 { |
82 return (r == c) ? Array<T>::xelem (r) : T (0); | 46 return (r == c) ? Array<T>::xelem (r) : T (0); |
84 | 48 |
85 template <class T> | 49 template <class T> |
86 T | 50 T |
87 DiagArray2<T>::checkelem (int r, int c) const | 51 DiagArray2<T>::checkelem (int r, int c) const |
88 { | 52 { |
89 if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) | 53 if (r < 0 || c < 0 || r >= this->dim1 () || c >= this->dim2 ()) |
90 { | 54 { |
91 (*current_liboctave_error_handler) ("range error in DiagArray2"); | 55 (*current_liboctave_error_handler) ("range error in DiagArray2"); |
92 return T (); | 56 return T (); |
93 } | 57 } |
94 return (r == c) ? Array<T>::xelem (r) : T (0); | 58 return (r == c) ? Array<T>::xelem (r) : T (0); |
96 | 60 |
97 template <class T> | 61 template <class T> |
98 T | 62 T |
99 DiagArray2<T>::operator () (int r, int c) const | 63 DiagArray2<T>::operator () (int r, int c) const |
100 { | 64 { |
101 if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) | 65 if (r < 0 || c < 0 || r >= this->dim1 () || c >= this->dim2 ()) |
102 { | 66 { |
103 (*current_liboctave_error_handler) ("range error in DiagArray2"); | 67 (*current_liboctave_error_handler) ("range error in DiagArray2"); |
104 return T (); | 68 return T (); |
105 } | 69 } |
106 return (r == c) ? Array<T>::xelem (r) : T (0); | 70 return (r == c) ? Array<T>::xelem (r) : T (0); |
129 { | 93 { |
130 (*current_liboctave_error_handler) ("can't resize to negative dimensions"); | 94 (*current_liboctave_error_handler) ("can't resize to negative dimensions"); |
131 return; | 95 return; |
132 } | 96 } |
133 | 97 |
134 if (r == dim1 () && c == dim2 ()) | 98 if (r == this->dim1 () && c == this->dim2 ()) |
135 return; | 99 return; |
136 | 100 |
137 typename Array<T>::ArrayRep *old_rep = Array<T>::rep; | 101 typename Array<T>::ArrayRep *old_rep = Array<T>::rep; |
138 const T *old_data = data (); | 102 const T *old_data = this->data (); |
139 int old_len = length (); | 103 int old_len = this->length (); |
140 | 104 |
141 int new_len = r < c ? r : c; | 105 int new_len = r < c ? r : c; |
142 | 106 |
143 Array<T>::rep = new typename Array<T>::ArrayRep (new_len); | 107 Array<T>::rep = new typename Array<T>::ArrayRep (new_len); |
144 | 108 |
145 dimensions = dim_vector (r, c); | 109 this->dimensions = dim_vector (r, c); |
146 | 110 |
147 if (old_data && old_len > 0) | 111 if (old_data && old_len > 0) |
148 { | 112 { |
149 int min_len = old_len < new_len ? old_len : new_len; | 113 int min_len = old_len < new_len ? old_len : new_len; |
150 | 114 |
164 { | 128 { |
165 (*current_liboctave_error_handler) ("can't resize to negative dimensions"); | 129 (*current_liboctave_error_handler) ("can't resize to negative dimensions"); |
166 return; | 130 return; |
167 } | 131 } |
168 | 132 |
169 if (r == dim1 () && c == dim2 ()) | 133 if (r == this->dim1 () && c == this->dim2 ()) |
170 return; | 134 return; |
171 | 135 |
172 typename Array<T>::ArrayRep *old_rep = Array<T>::rep; | 136 typename Array<T>::ArrayRep *old_rep = Array<T>::rep; |
173 const T *old_data = data (); | 137 const T *old_data = this->data (); |
174 int old_len = length (); | 138 int old_len = this->length (); |
175 | 139 |
176 int new_len = r < c ? r : c; | 140 int new_len = r < c ? r : c; |
177 | 141 |
178 Array<T>::rep = new typename Array<T>::ArrayRep (new_len); | 142 Array<T>::rep = new typename Array<T>::ArrayRep (new_len); |
179 | 143 |
180 dimensions = dim_vector (r, c); | 144 this->dimensions = dim_vector (r, c); |
181 | 145 |
182 int min_len = old_len < new_len ? old_len : new_len; | 146 int min_len = old_len < new_len ? old_len : new_len; |
183 | 147 |
184 if (old_data && old_len > 0) | 148 if (old_data && old_len > 0) |
185 { | 149 { |