3353
|
1 /* |
|
2 |
|
3 Copyright (C) 1999 John W. Eaton |
|
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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
|
32 #include <strstream> |
3353
|
33 |
|
34 #include "Cell.h" |
|
35 #include "defun.h" |
|
36 #include "error.h" |
|
37 #include "oct-obj.h" |
|
38 #include "pt-arg-list.h" |
3770
|
39 #include "pt-bp.h" |
3353
|
40 #include "pt-exp.h" |
|
41 #include "pt-cell.h" |
|
42 #include "pt-walk.h" |
|
43 #include "utils.h" |
|
44 #include "ov.h" |
|
45 #include "variables.h" |
|
46 |
|
47 octave_value |
|
48 tree_cell::rvalue (void) |
|
49 { |
|
50 octave_value retval; |
|
51 |
3770
|
52 MAYBE_DO_BREAKPOINT; |
|
53 |
3353
|
54 int nr = length (); |
|
55 int nc = -1; |
|
56 |
|
57 for (Pix p = first (); p != 0; next (p)) |
|
58 { |
|
59 tree_argument_list *elt = this->operator () (p); |
|
60 |
|
61 if (nc < 0) |
|
62 nc = elt->length (); |
|
63 else if (nc != elt->length ()) |
|
64 { |
|
65 ::error ("number of columns must match"); |
|
66 return retval; |
|
67 } |
|
68 } |
|
69 |
|
70 Cell val (nr, nc); |
|
71 |
|
72 int i = 0; |
|
73 |
|
74 for (Pix p = first (); p != 0; next (p)) |
|
75 { |
|
76 tree_argument_list *elt = this->operator () (p); |
|
77 |
|
78 octave_value_list row = elt->convert_to_const_vector (); |
|
79 |
|
80 for (int j = 0; j < nc; j++) |
|
81 val(i,j) = row(j); |
|
82 |
|
83 i++; |
|
84 } |
|
85 |
|
86 retval = val; |
|
87 |
|
88 return retval; |
|
89 } |
|
90 |
3556
|
91 octave_value_list |
|
92 tree_cell::rvalue (int nargout) |
|
93 { |
|
94 octave_value_list retval; |
|
95 |
|
96 if (nargout > 1) |
|
97 error ("invalid number of output arguments for cell array"); |
|
98 else |
|
99 retval = rvalue (); |
|
100 |
|
101 return retval; |
|
102 } |
|
103 |
3353
|
104 void |
|
105 tree_cell::accept (tree_walker& tw) |
|
106 { |
|
107 tw.visit_cell (*this); |
|
108 } |
|
109 |
|
110 /* |
|
111 ;;; Local Variables: *** |
|
112 ;;; mode: C++ *** |
|
113 ;;; End: *** |
|
114 */ |