1
|
1 // The rest of the tree classes. -*- C++ -*- |
|
2 /* |
|
3 |
296
|
4 Copyright (C) 1992, 1993, 1994 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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
383
|
24 #if !defined (octave_tree_const_h) |
|
25 #define octave_tree_const_h 1 |
1
|
26 |
455
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
1
|
31 #include <stdlib.h> |
|
32 |
|
33 #include "builtins.h" |
|
34 #include "tree-base.h" |
455
|
35 |
|
36 #include "mx-base.h" |
|
37 #include "Range.h" |
164
|
38 |
|
39 class idx_vector; |
1
|
40 |
|
41 /* |
|
42 * How about a few macros? |
|
43 */ |
|
44 |
|
45 #ifndef MAX |
|
46 #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
|
47 #endif |
|
48 |
|
49 #ifndef MIN |
|
50 #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
|
51 #endif |
|
52 |
|
53 #ifndef ABS |
|
54 #define ABS(x) (((x) < 0) ? (-x) : (x)) |
|
55 #endif |
|
56 |
|
57 #ifndef NULL_TREE |
|
58 #define NULL_TREE (tree *)NULL |
|
59 #endif |
|
60 |
|
61 #ifndef NULL_TREE_CONST |
|
62 #define NULL_TREE_CONST (tree_constant *)NULL |
|
63 #endif |
|
64 |
|
65 /* |
|
66 * The following are used by some of the functions in the |
|
67 * tree_constant_rep class that must deal with real and complex |
|
68 * matrices. This was not done with overloaded or virtual functions |
|
69 * from the Matrix class because there is no clean way to do that -- |
|
70 * the necessary functions (like elem) need to return values of |
|
71 * different types... |
|
72 */ |
|
73 |
|
74 // Given a tree_constant, and the names to be used for the real and |
|
75 // complex matrix and their dimensions, declare a real or complex |
|
76 // matrix, and initialize it from the tree_constant. Note that m, cm, |
|
77 // nr, and nc must not be previously declared, and they must not be |
|
78 // expressions. Since only one of the matrices will be defined after |
|
79 // this macro is used, only one set of dimesions is declared. |
|
80 |
|
81 // This macro only makes sense inside a friend or member function of |
|
82 // the tree_constant_rep class |
|
83 |
|
84 #define REP_RHS_MATRIX(tc,m,cm,nr,nc) \ |
399
|
85 int nr = 0; \ |
|
86 int nc = 0; \ |
1
|
87 Matrix m; \ |
|
88 ComplexMatrix cm; \ |
|
89 if ((tc).const_type () == tree_constant_rep::complex_matrix_constant) \ |
|
90 { \ |
|
91 cm = (tc).complex_matrix_value (); \ |
|
92 nr = (cm).rows (); \ |
|
93 nc = (cm).columns (); \ |
|
94 } \ |
399
|
95 else if ((tc).const_type () == tree_constant_rep::matrix_constant) \ |
1
|
96 { \ |
|
97 m = (tc).matrix_value (); \ |
|
98 nr = (m).rows (); \ |
|
99 nc = (m).columns (); \ |
399
|
100 } \ |
|
101 else \ |
|
102 abort (); |
1
|
103 |
|
104 // Assign a real or complex value to a tree_constant. |
|
105 // |
|
106 // This macro only makes sense inside a friend or member function of |
|
107 // the tree_constant_rep class. |
|
108 |
|
109 #define REP_ELEM_ASSIGN(i,j,rval,cval,real_type) \ |
|
110 do \ |
|
111 { \ |
|
112 if (type_tag == tree_constant_rep::matrix_constant) \ |
|
113 { \ |
|
114 if (real_type) \ |
|
115 matrix->elem ((i), (j)) = (rval); \ |
|
116 else \ |
|
117 abort (); \ |
|
118 } \ |
|
119 else \ |
|
120 { \ |
|
121 if (real_type) \ |
|
122 complex_matrix->elem ((i), (j)) = (rval); \ |
|
123 else \ |
|
124 complex_matrix->elem ((i), (j)) = (cval); \ |
|
125 } \ |
|
126 } \ |
|
127 while (0) |
|
128 |
|
129 // Given a real and complex matrix and row and column dimensions, |
|
130 // declare both and size one of them. Only one of the matrices should |
|
131 // be used after this macro has been used. |
|
132 |
|
133 // This macro only makes sense inside a friend or member function of |
|
134 // the tree_constant_rep class. |
|
135 |
|
136 #define CRMATRIX(m,cm,nr,nc) \ |
|
137 Matrix m; \ |
|
138 ComplexMatrix cm; \ |
|
139 if (type_tag == tree_constant_rep::matrix_constant) \ |
399
|
140 (m).resize ((nr), (nc)); \ |
1
|
141 else if (type_tag == complex_matrix_constant) \ |
399
|
142 (cm).resize ((nr), (nc)); \ |
1
|
143 else \ |
399
|
144 abort (); \ |
1
|
145 |
|
146 // Assign a real or complex matrix to a tree constant. |
|
147 |
|
148 // This macro only makes sense inside a friend or member function of |
|
149 // the tree_constant_rep class. |
|
150 |
|
151 #define ASSIGN_CRMATRIX_TO(tc,m,cm) \ |
|
152 do \ |
|
153 { \ |
|
154 if (type_tag == matrix_constant) \ |
|
155 tc = tree_constant (m); \ |
|
156 else \ |
|
157 tc = tree_constant (cm); \ |
|
158 } \ |
|
159 while (0) |
|
160 |
|
161 // Assign an element of this tree_constant_rep's real or complex |
|
162 // matrix to another real or complex matrix. |
|
163 |
|
164 // This macro only makes sense inside a friend or member function of |
|
165 // the tree_constant_rep class. |
|
166 |
|
167 #define CRMATRIX_ASSIGN_REP_ELEM(m,cm,i1,j1,i2,j2) \ |
|
168 do \ |
|
169 { \ |
|
170 if (type_tag == matrix_constant) \ |
|
171 (m).elem ((i1), (j1)) = matrix->elem ((i2), (j2)); \ |
|
172 else \ |
|
173 (cm).elem ((i1), (j1)) = complex_matrix->elem ((i2), (j2)); \ |
|
174 } \ |
|
175 while (0) |
|
176 |
|
177 // Assign a value to an element of a real or complex matrix. Assumes |
|
178 // that the lhs and rhs are either both real or both complex types. |
|
179 |
|
180 #define CRMATRIX_ASSIGN_ELEM(m,cm,i,j,rval,cval,real_type) \ |
|
181 do \ |
|
182 { \ |
|
183 if (real_type) \ |
|
184 (m).elem ((i), (j)) = (rval); \ |
|
185 else \ |
|
186 (cm).elem ((i), (j)) = (cval); \ |
|
187 } \ |
|
188 while (0) |
|
189 |
|
190 |
|
191 /* |
|
192 * Forward class declarations. |
|
193 */ |
|
194 class tree; |
|
195 class tree_constant; |
|
196 |
|
197 #ifndef TREE_FCN_TYPEDEFS |
|
198 #define TREE_FCN_TYPEDEFS 1 |
|
199 |
|
200 typedef tree_constant (*Text_fcn)(int, char **); |
|
201 typedef tree_constant* (*General_fcn)(tree_constant *, int, int); |
|
202 |
|
203 #endif |
|
204 |
|
205 /* |
|
206 * The actual representation of the tree_constant. |
|
207 */ |
|
208 class |
|
209 tree_constant_rep |
|
210 { |
|
211 friend class tree_constant; |
|
212 |
|
213 enum force_orient |
|
214 { |
|
215 no_orient, |
|
216 row_orient, |
|
217 column_orient, |
|
218 }; |
|
219 |
|
220 public: |
|
221 enum constant_type |
|
222 { |
|
223 unknown_constant, |
|
224 scalar_constant, |
|
225 matrix_constant, |
|
226 complex_scalar_constant, |
|
227 complex_matrix_constant, |
|
228 string_constant, |
|
229 range_constant, |
|
230 magic_colon, |
|
231 }; |
|
232 |
|
233 tree_constant_rep (void); |
|
234 |
|
235 tree_constant_rep (double d); |
161
|
236 tree_constant_rep (const Matrix& m); |
|
237 tree_constant_rep (const DiagMatrix& d); |
|
238 tree_constant_rep (const RowVector& v, int pcv); |
|
239 tree_constant_rep (const ColumnVector& v, int pcv); |
1
|
240 |
161
|
241 tree_constant_rep (const Complex& c); |
|
242 tree_constant_rep (const ComplexMatrix& m); |
|
243 tree_constant_rep (const ComplexDiagMatrix& d); |
|
244 tree_constant_rep (const ComplexRowVector& v, int pcv); |
|
245 tree_constant_rep (const ComplexColumnVector& v, int pcv); |
1
|
246 |
|
247 tree_constant_rep (const char *s); |
|
248 |
|
249 tree_constant_rep (double base, double limit, double inc); |
161
|
250 tree_constant_rep (const Range& r); |
1
|
251 |
|
252 tree_constant_rep (tree_constant_rep::constant_type t); |
|
253 |
161
|
254 tree_constant_rep (const tree_constant_rep& t); |
1
|
255 |
|
256 ~tree_constant_rep (void); |
|
257 |
|
258 #if defined (MDEBUG) |
|
259 void *operator new (size_t size); |
|
260 void operator delete (void *p, size_t size); |
|
261 #endif |
|
262 |
|
263 void resize (int i, int j); |
|
264 void resize (int i, int j, double val); |
|
265 |
|
266 void maybe_resize (int imax, force_orient fo = no_orient); |
|
267 void maybe_resize (int imax, int jmax); |
|
268 |
164
|
269 int valid_as_scalar_index (void) const; |
1
|
270 |
164
|
271 int is_defined (void) const |
1
|
272 { return type_tag != tree_constant_rep::unknown_constant; } |
|
273 |
164
|
274 int is_undefined (void) const |
1
|
275 { return type_tag == tree_constant_rep::unknown_constant; } |
|
276 |
164
|
277 int is_string_type (void) const |
1
|
278 { return type_tag == tree_constant_rep::string_constant; } |
|
279 |
164
|
280 int is_scalar_type (void) const |
1
|
281 { return type_tag == scalar_constant |
|
282 || type_tag == complex_scalar_constant; } |
|
283 |
164
|
284 int is_matrix_type (void) const |
1
|
285 { return type_tag == matrix_constant |
|
286 || type_tag == complex_matrix_constant; } |
|
287 |
164
|
288 int is_real_type (void) const |
1
|
289 { return type_tag == scalar_constant |
|
290 || type_tag == matrix_constant |
|
291 || type_tag == range_constant; } |
|
292 |
164
|
293 int is_complex_type (void) const |
1
|
294 { return type_tag == complex_matrix_constant |
|
295 || type_tag == complex_scalar_constant; } |
|
296 |
|
297 |
164
|
298 int is_numeric_type (void) const |
1
|
299 { return type_tag == scalar_constant |
|
300 || type_tag == matrix_constant |
|
301 || type_tag == complex_matrix_constant |
|
302 || type_tag == complex_scalar_constant; } |
|
303 |
164
|
304 int is_numeric_or_range_type (void) const |
1
|
305 { return type_tag == scalar_constant |
|
306 || type_tag == matrix_constant |
|
307 || type_tag == complex_matrix_constant |
|
308 || type_tag == complex_scalar_constant |
|
309 || type_tag == range_constant; } |
|
310 |
164
|
311 double to_scalar (void) const; |
|
312 ColumnVector to_vector (void) const; |
|
313 Matrix to_matrix (void) const; |
1
|
314 |
|
315 tree_constant_rep::constant_type force_numeric (int force_str_conv = 0); |
164
|
316 tree_constant make_numeric (int force_str_conv = 0) const; |
1
|
317 |
|
318 friend tree_constant |
|
319 do_binary_op (tree_constant& a, tree_constant& b, tree::expression_type t); |
|
320 |
|
321 friend tree_constant |
|
322 do_unary_op (tree_constant& a, tree::expression_type t); |
|
323 |
|
324 void assign (tree_constant& rhs, tree_constant *args, int nargs); |
|
325 |
|
326 void do_scalar_assignment |
|
327 (tree_constant& rhs, tree_constant *args, int nargin); |
|
328 |
|
329 void do_matrix_assignment |
|
330 (tree_constant& rhs, tree_constant *args, int nargin); |
|
331 |
|
332 void do_matrix_assignment |
|
333 (tree_constant& rhs, tree_constant& i_arg); |
|
334 |
|
335 void do_matrix_assignment |
|
336 (tree_constant& rhs, tree_constant& i_arg, tree_constant& j_arg); |
|
337 |
|
338 void fortran_style_matrix_assignment (tree_constant& rhs, |
|
339 tree_constant& i_arg); |
|
340 |
|
341 void fortran_style_matrix_assignment (tree_constant& rhs, constant_type ci); |
|
342 |
|
343 void fortran_style_matrix_assignment (tree_constant& rhs, idx_vector& i); |
|
344 |
|
345 void vector_assignment (tree_constant& rhs, tree_constant& i_arg); |
|
346 |
164
|
347 void check_vector_assign (int rhs_nr, int rhs_nc, int ilen, |
|
348 const char *rm); |
1
|
349 |
|
350 void do_vector_assign (tree_constant& rhs, int i); |
|
351 void do_vector_assign (tree_constant& rhs, idx_vector& i); |
212
|
352 void do_vector_assign (tree_constant& rhs, Range& i); |
1
|
353 |
|
354 void do_matrix_assignment |
|
355 (tree_constant& rhs, int i, tree_constant& j_arg); |
|
356 void do_matrix_assignment |
|
357 (tree_constant& rhs, idx_vector& i, tree_constant& j_arg); |
|
358 void do_matrix_assignment |
212
|
359 (tree_constant& rhs, Range& i, tree_constant& j_arg); |
1
|
360 void do_matrix_assignment |
|
361 (tree_constant& rhs, constant_type i, tree_constant& j_arg); |
|
362 |
|
363 void do_matrix_assignment (tree_constant& rhs, int i, int j); |
|
364 void do_matrix_assignment (tree_constant& rhs, int i, idx_vector& jv); |
|
365 void do_matrix_assignment (tree_constant& rhs, int i, Range& j); |
|
366 void do_matrix_assignment (tree_constant& rhs, int i, constant_type cj); |
|
367 |
|
368 void do_matrix_assignment (tree_constant& rhs, idx_vector& iv, int j); |
|
369 void do_matrix_assignment (tree_constant& rhs, idx_vector& iv, |
|
370 idx_vector& jv); |
|
371 void do_matrix_assignment (tree_constant& rhs, idx_vector& iv, Range& j); |
|
372 void do_matrix_assignment (tree_constant& rhs, idx_vector& iv, |
|
373 constant_type j); |
|
374 |
|
375 void do_matrix_assignment (tree_constant& rhs, Range& i, int j); |
|
376 void do_matrix_assignment (tree_constant& rhs, Range& i, idx_vector& jv); |
|
377 void do_matrix_assignment (tree_constant& rhs, Range& i, Range& j); |
|
378 void do_matrix_assignment (tree_constant& rhs, Range& i, constant_type j); |
|
379 |
|
380 void do_matrix_assignment (tree_constant& rhs, constant_type i, int j); |
|
381 void do_matrix_assignment (tree_constant& rhs, constant_type i, |
|
382 idx_vector& jv); |
|
383 void do_matrix_assignment (tree_constant& rhs, constant_type i, Range& j); |
|
384 void do_matrix_assignment (tree_constant& rhs, constant_type i, |
|
385 constant_type j); |
|
386 |
208
|
387 void delete_row (int); |
|
388 void delete_rows (idx_vector& i); |
|
389 void delete_rows (Range& i); |
|
390 |
|
391 void delete_column (int); |
|
392 void delete_columns (idx_vector& j); |
|
393 void delete_columns (Range& j); |
|
394 |
1
|
395 void bump_value (tree::expression_type); |
|
396 |
|
397 void eval (int print); |
|
398 |
164
|
399 tree_constant *eval (const tree_constant *args, int n_in, int n_out, |
|
400 int print); |
1
|
401 |
164
|
402 tree_constant do_scalar_index (const tree_constant *args, |
|
403 int nargin) const; |
1
|
404 |
164
|
405 tree_constant do_matrix_index (const tree_constant *args, int nargin) const; |
|
406 |
|
407 tree_constant do_matrix_index (const tree_constant& i_arg) const; |
1
|
408 |
164
|
409 tree_constant do_matrix_index (const tree_constant& i_arg, |
|
410 const tree_constant& j_arg) const; |
1
|
411 |
164
|
412 tree_constant do_matrix_index (constant_type i) const; |
1
|
413 |
164
|
414 tree_constant fortran_style_matrix_index (const tree_constant& i_arg) const; |
|
415 tree_constant fortran_style_matrix_index (const Matrix& mi) const; |
1
|
416 |
164
|
417 tree_constant do_vector_index (const tree_constant& i_arg) const; |
1
|
418 |
164
|
419 tree_constant do_matrix_index (int i, const tree_constant& i_arg) const; |
|
420 tree_constant do_matrix_index (const idx_vector& i, |
|
421 const tree_constant& i_arg) const; |
212
|
422 tree_constant do_matrix_index (const Range& i, |
164
|
423 const tree_constant& i_arg) const; |
|
424 tree_constant do_matrix_index (constant_type i, |
|
425 const tree_constant& i_arg) const; |
1
|
426 |
164
|
427 tree_constant do_matrix_index (int i, int j) const; |
|
428 tree_constant do_matrix_index (int i, const idx_vector& j) const; |
|
429 tree_constant do_matrix_index (int i, const Range& j) const; |
|
430 tree_constant do_matrix_index (int i, constant_type cj) const; |
1
|
431 |
164
|
432 tree_constant do_matrix_index (const idx_vector& i, int j) const; |
|
433 tree_constant do_matrix_index (const idx_vector& i, |
|
434 const idx_vector& j) const; |
|
435 tree_constant do_matrix_index (const idx_vector& i, const Range& j) const; |
|
436 tree_constant do_matrix_index (const idx_vector& i, constant_type j) const; |
1
|
437 |
164
|
438 tree_constant do_matrix_index (const Range& i, int j) const; |
|
439 tree_constant do_matrix_index (const Range& i, const idx_vector& j) const; |
|
440 tree_constant do_matrix_index (const Range& i, const Range& j) const; |
|
441 tree_constant do_matrix_index (const Range& i, constant_type j) const; |
1
|
442 |
164
|
443 tree_constant do_matrix_index (constant_type i, int j) const; |
|
444 tree_constant do_matrix_index (constant_type i, const idx_vector& j) const; |
|
445 tree_constant do_matrix_index (constant_type i, const Range& j) const; |
|
446 tree_constant do_matrix_index (constant_type i, constant_type j) const; |
1
|
447 |
276
|
448 int save (ostream& os, int mark_as_global, int precision); |
1
|
449 int save_three_d (ostream& os, int parametric); |
|
450 int load (istream& is); |
|
451 constant_type load (istream& is, constant_type t); |
|
452 |
164
|
453 double double_value (void) const; |
|
454 Matrix matrix_value (void) const; |
|
455 Complex complex_value (void) const; |
|
456 ComplexMatrix complex_matrix_value (void) const; |
|
457 char *string_value (void) const; |
|
458 Range range_value (void) const; |
1
|
459 |
164
|
460 int rows (void) const; |
|
461 int columns (void) const; |
1
|
462 |
164
|
463 tree_constant all (void) const; |
|
464 tree_constant any (void) const; |
|
465 tree_constant isstr (void) const; |
1
|
466 |
|
467 tree_constant convert_to_str (void); |
|
468 |
435
|
469 void convert_to_row_or_column_vector (void); |
|
470 |
428
|
471 int is_true (void) const; |
|
472 |
164
|
473 tree_constant cumprod (void) const; |
|
474 tree_constant cumsum (void) const; |
|
475 tree_constant prod (void) const; |
|
476 tree_constant sum (void) const; |
|
477 tree_constant sumsq (void) const; |
1
|
478 |
164
|
479 tree_constant diag (void) const; |
|
480 tree_constant diag (const tree_constant& a) const; |
1
|
481 |
164
|
482 friend tree_constant fill_matrix (const tree_constant& a, |
|
483 double d, const char *warn_for); |
|
484 friend tree_constant fill_matrix (const tree_constant& a, |
|
485 const tree_constant& b, |
|
486 double d, const char *warn_for); |
1
|
487 |
164
|
488 friend tree_constant identity_matrix (const tree_constant& a); |
|
489 friend tree_constant identity_matrix (const tree_constant& a, |
|
490 const tree_constant& b); |
1
|
491 |
164
|
492 friend tree_constant find_nonzero_elem_idx (const tree_constant& a); |
1
|
493 |
164
|
494 friend tree_constant *matrix_log (const tree_constant& a); |
|
495 friend tree_constant *matrix_sqrt (const tree_constant& a); |
|
496 |
|
497 friend tree_constant *column_max (const tree_constant *args, int nargin, |
1
|
498 int nargout); |
|
499 |
164
|
500 friend tree_constant *column_min (const tree_constant *args, int nargin, |
1
|
501 int nargout); |
|
502 |
164
|
503 friend tree_constant *sort (const tree_constant *args, int nargin, |
|
504 int nargout); |
1
|
505 |
164
|
506 friend tree_constant *feval (const tree_constant *args, int nargin, |
|
507 int nargout); |
1
|
508 |
164
|
509 friend tree_constant eval_string (const tree_constant& arg, int& |
|
510 parse_status); |
1
|
511 |
164
|
512 friend tree_constant get_user_input (const tree_constant *args, |
|
513 int nargin, int nargout, |
|
514 int debug = 0); |
1
|
515 |
164
|
516 constant_type const_type (void) const { return type_tag; } |
1
|
517 |
164
|
518 tree_constant mapper (Mapper_fcn& m_fcn, int print) const; |
1
|
519 |
|
520 private: |
|
521 int count; |
|
522 constant_type type_tag; |
|
523 union |
|
524 { |
|
525 double scalar; // A real scalar constant. |
|
526 Matrix *matrix; // A real matrix constant. |
|
527 Complex *complex_scalar; // A real scalar constant. |
|
528 ComplexMatrix *complex_matrix; // A real matrix constant. |
|
529 char *string; // A character string constant. |
|
530 Range *range; // A set of evenly spaced values. |
|
531 }; |
|
532 }; |
|
533 |
|
534 /* |
|
535 * Constants. Nice -- No need to interpret them anymore. Logically, |
|
536 * this should be ahead of the tree_constant_rep class, but that |
|
537 * causes problems with my version of g++ (~2.2.2)... |
|
538 */ |
455
|
539 class |
|
540 tree_constant : public tree |
1
|
541 { |
|
542 friend class tree_constant_rep; |
|
543 |
|
544 public: |
|
545 tree_constant (void) |
|
546 { rep = new tree_constant_rep (); rep->count = 1; } |
|
547 |
|
548 tree_constant (double d) |
|
549 { rep = new tree_constant_rep (d); rep->count = 1; } |
161
|
550 tree_constant (const Matrix& m) |
1
|
551 { rep = new tree_constant_rep (m); rep->count = 1; } |
161
|
552 tree_constant (const DiagMatrix& d) |
1
|
553 { rep = new tree_constant_rep (d); rep->count = 1; } |
455
|
554 tree_constant (const RowVector& v, int pcv = -1) |
1
|
555 { rep = new tree_constant_rep (v, pcv); rep->count = 1; } |
455
|
556 tree_constant (const ColumnVector& v, int pcv = -1) |
1
|
557 { rep = new tree_constant_rep (v, pcv); rep->count = 1; } |
|
558 |
161
|
559 tree_constant (const Complex& c) |
1
|
560 { rep = new tree_constant_rep (c); rep->count = 1; } |
161
|
561 tree_constant (const ComplexMatrix& m) |
1
|
562 { rep = new tree_constant_rep (m); rep->count = 1; } |
161
|
563 tree_constant (const ComplexDiagMatrix& d) |
1
|
564 { rep = new tree_constant_rep (d); rep->count = 1; } |
455
|
565 tree_constant (const ComplexRowVector& v, int pcv = -1) |
1
|
566 { rep = new tree_constant_rep (v, pcv); rep->count = 1; } |
455
|
567 tree_constant (const ComplexColumnVector& v, int pcv = -1) |
1
|
568 { rep = new tree_constant_rep (v, pcv); rep->count = 1; } |
|
569 |
|
570 tree_constant (const char *s) |
|
571 { rep = new tree_constant_rep (s); rep->count = 1; } |
|
572 |
|
573 tree_constant (double base, double limit, double inc) |
|
574 { rep = new tree_constant_rep (base, limit, inc); rep->count = 1; } |
161
|
575 tree_constant (const Range& r) |
1
|
576 { rep = new tree_constant_rep (r); rep->count = 1; } |
|
577 |
|
578 tree_constant (tree_constant_rep::constant_type t) |
|
579 { rep = new tree_constant_rep (t); rep->count = 1; } |
|
580 |
161
|
581 tree_constant (const tree_constant& a) |
1
|
582 { rep = a.rep; rep->count++; } |
|
583 tree_constant (tree_constant_rep& r) |
|
584 { rep = &r; rep->count++; } |
|
585 |
|
586 ~tree_constant (void); |
|
587 |
|
588 #if defined (MDEBUG) |
|
589 void *operator new (size_t size); |
|
590 void operator delete (void *p, size_t size); |
|
591 #endif |
|
592 |
|
593 tree_constant operator = (tree_constant& a) |
|
594 { |
|
595 if (--rep->count <= 0 && rep != a.rep) |
|
596 delete rep; |
|
597 |
|
598 rep = a.rep; |
|
599 rep->count++; |
|
600 return *this; |
|
601 } |
|
602 |
164
|
603 int is_constant (void) const { return 1; } |
1
|
604 |
164
|
605 int is_scalar_type (void) const { return rep->is_scalar_type (); } |
|
606 int is_matrix_type (void) const { return rep->is_matrix_type (); } |
1
|
607 |
164
|
608 int is_real_type (void) const { return rep->is_real_type (); } |
|
609 int is_complex_type (void) const { return rep->is_complex_type (); } |
1
|
610 |
164
|
611 int is_numeric_type (void) const { return rep->is_numeric_type (); } |
1
|
612 |
164
|
613 int is_numeric_or_range_type (void) const |
1
|
614 { return rep->is_numeric_or_range_type (); } |
|
615 |
164
|
616 int is_string_type (void) const { return rep->is_string_type (); } |
1
|
617 |
164
|
618 int valid_as_scalar_index (void) const |
|
619 { return rep->valid_as_scalar_index (); } |
1
|
620 |
164
|
621 int is_defined (void) const { return rep->is_defined (); } |
|
622 int is_undefined (void) const { return rep->is_undefined (); } |
1
|
623 |
164
|
624 double to_scalar (void) const { return rep->to_scalar (); } |
|
625 ColumnVector to_vector (void) const { return rep->to_vector (); } |
|
626 Matrix to_matrix (void) const { return rep->to_matrix (); } |
1
|
627 |
|
628 tree_constant_rep::constant_type force_numeric (int force_str_conv = 0) |
|
629 { return rep->force_numeric (force_str_conv); } |
|
630 |
164
|
631 tree_constant make_numeric (int force_str_conv = 0) const |
1
|
632 { |
|
633 if (is_numeric_type ()) |
|
634 return *this; |
|
635 else |
|
636 return rep->make_numeric (force_str_conv); |
|
637 } |
|
638 |
164
|
639 tree_constant make_numeric_or_range (void) const |
1
|
640 { |
|
641 if (is_numeric_type () |
|
642 || rep->type_tag == tree_constant_rep::range_constant) |
|
643 return *this; |
|
644 else |
|
645 return rep->make_numeric (); |
|
646 } |
|
647 |
164
|
648 tree_constant make_numeric_or_magic (void) const |
1
|
649 { |
|
650 if (is_numeric_type () |
|
651 || rep->type_tag == tree_constant_rep::magic_colon) |
|
652 return *this; |
|
653 else |
|
654 return rep->make_numeric (); |
|
655 } |
|
656 |
164
|
657 tree_constant make_numeric_or_range_or_magic (void) const |
1
|
658 { |
|
659 if (is_numeric_type () |
|
660 || rep->type_tag == tree_constant_rep::magic_colon |
|
661 || rep->type_tag == tree_constant_rep::range_constant) |
|
662 return *this; |
|
663 else |
|
664 return rep->make_numeric (); |
|
665 } |
|
666 |
|
667 tree_constant assign (tree_constant& rhs, tree_constant *args, int nargs) |
|
668 { |
|
669 if (rep->count > 1) |
|
670 { |
|
671 --rep->count; |
|
672 rep = new tree_constant_rep (*rep); |
|
673 rep->count = 1; |
|
674 } |
|
675 rep->assign (rhs, args, nargs); |
|
676 return *this; |
|
677 } |
|
678 |
276
|
679 int save (ostream& os, int mark_as_global = 0, int precision = 17) |
|
680 { return rep->save (os, mark_as_global, precision); } |
1
|
681 int save_three_d (ostream& os, int parametric = 0) |
|
682 { return rep->save_three_d (os, parametric); } |
|
683 |
|
684 int load (istream& is) { return rep->load (is); } |
|
685 tree_constant_rep::constant_type load |
|
686 (istream& is, tree_constant_rep::constant_type t) |
|
687 { return rep->load (is, t); } |
|
688 |
164
|
689 double double_value (void) const { return rep->double_value (); } |
|
690 Matrix matrix_value (void) const { return rep->matrix_value (); } |
|
691 Complex complex_value (void) const { return rep->complex_value (); } |
|
692 ComplexMatrix complex_matrix_value (void) const |
1
|
693 { return rep->complex_matrix_value (); } |
164
|
694 char *string_value (void) const { return rep->string_value (); } |
|
695 Range range_value (void) const { return rep->range_value (); } |
1
|
696 |
164
|
697 int rows (void) const { return rep->rows (); } |
|
698 int columns (void) const { return rep->columns (); } |
1
|
699 |
208
|
700 int is_empty (void) const |
|
701 { |
|
702 return (rep->type_tag != tree_constant_rep::magic_colon |
|
703 && rep->type_tag != tree_constant_rep::unknown_constant |
|
704 && (rows () == 0 || columns () == 0)); |
|
705 } |
|
706 |
|
707 int is_zero_by_zero (void) const |
212
|
708 { |
|
709 return (rep->type_tag != tree_constant_rep::magic_colon |
|
710 && rep->type_tag != tree_constant_rep::unknown_constant |
|
711 && rows () == 0 |
|
712 && columns () == 0); |
|
713 } |
208
|
714 |
93
|
715 |
164
|
716 tree_constant all (void) const { return rep->all (); } |
|
717 tree_constant any (void) const { return rep->any (); } |
|
718 tree_constant isstr (void) const { return rep->isstr (); } |
1
|
719 |
|
720 tree_constant convert_to_str (void) { return rep->convert_to_str (); } |
|
721 |
435
|
722 void convert_to_row_or_column_vector (void) |
455
|
723 { rep->convert_to_row_or_column_vector (); } |
435
|
724 |
428
|
725 int is_true (void) const { return rep->is_true (); } |
|
726 |
164
|
727 tree_constant cumprod (void) const { return rep->cumprod (); } |
|
728 tree_constant cumsum (void) const { return rep->cumsum (); } |
|
729 tree_constant prod (void) const { return rep->prod (); } |
|
730 tree_constant sum (void) const { return rep->sum (); } |
|
731 tree_constant sumsq (void) const { return rep->sumsq (); } |
1
|
732 |
164
|
733 tree_constant diag (void) const { return rep->diag (); } |
|
734 tree_constant diag (const tree_constant& a) const { return rep->diag (a); } |
1
|
735 |
164
|
736 tree_constant_rep::constant_type const_type (void) const |
1
|
737 { return rep->const_type (); } |
|
738 |
164
|
739 tree_constant mapper (Mapper_fcn& m_fcn, int print) const |
1
|
740 { return rep->mapper (m_fcn, print); } |
|
741 |
|
742 void bump_value (tree::expression_type et) |
|
743 { |
|
744 if (rep->count > 1) |
|
745 { |
|
746 --rep->count; |
|
747 rep = new tree_constant_rep (*rep); |
|
748 rep->count = 1; |
|
749 } |
|
750 rep->bump_value (et); |
|
751 } |
|
752 |
|
753 tree_constant eval (int print) |
|
754 { rep->eval (print); return *this; } |
|
755 |
|
756 // A tree constant can have one and only one value to return. |
|
757 tree_constant *eval (int print, int nargout) |
|
758 { |
|
759 rep->eval (print); |
|
760 tree_constant *retval = new tree_constant [2]; |
|
761 retval[0] = *this; |
|
762 return retval; |
|
763 } |
|
764 |
259
|
765 tree_constant eval (int argc, char **argv, int print); |
|
766 |
164
|
767 tree_constant *eval (const tree_constant *args, int n_in, int n_out, |
|
768 int print) |
1
|
769 { return rep->eval (args, n_in, n_out, print); } |
|
770 |
|
771 private: |
|
772 tree_constant_rep *rep; |
|
773 }; |
|
774 |
94
|
775 /* |
|
776 * Here are some extra functions that are related to the tree_constant |
|
777 * class but that don't need to be class members or friends. |
|
778 */ |
|
779 |
164
|
780 extern tree_constant *vector_of_empties (int nargout, const char *fcn_name); |
94
|
781 |
1
|
782 #endif |
|
783 |
|
784 /* |
|
785 ;;; Local Variables: *** |
|
786 ;;; mode: C++ *** |
|
787 ;;; page-delimiter: "^/\\*" *** |
|
788 ;;; End: *** |
|
789 */ |