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 "lo-utils.h" |
|
35 |
|
36 #include "defun.h" |
|
37 #include "error.h" |
|
38 #include "ov-cell.h" |
3354
|
39 #include "oct-obj.h" |
3353
|
40 #include "unwind-prot.h" |
3354
|
41 #include "utils.h" |
3928
|
42 #include "ov-base-mat.h" |
|
43 #include "ov-base-mat.cc" |
|
44 #include "ov-re-mat.h" |
|
45 #include "ov-scalar.h" |
|
46 |
|
47 template class octave_base_matrix<Cell>; |
3353
|
48 |
|
49 DEFINE_OCTAVE_ALLOCATOR (octave_cell); |
|
50 |
|
51 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell"); |
|
52 |
|
53 void |
|
54 octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) |
|
55 { |
3928
|
56 if (rhs.is_cell ()) |
|
57 octave_base_matrix<Cell>::assign (idx, rhs.cell_value ()); |
3353
|
58 else |
3928
|
59 octave_base_matrix<Cell>::assign (idx, Cell (rhs)); |
3353
|
60 } |
|
61 |
3354
|
62 DEFUN (iscell, args, , |
3448
|
63 "-*- texinfo -*-\n\ |
|
64 @deftypefn {Built-in Function} {} iscell (@var{x})\n\ |
|
65 Return true if @var{x} is a cell array object. Otherwise, return\n\ |
|
66 false.\n\ |
|
67 @end deftypefn") |
3354
|
68 { |
|
69 octave_value retval; |
|
70 |
|
71 if (args.length () == 1) |
|
72 retval = args(0).is_cell (); |
|
73 else |
|
74 print_usage ("iscell"); |
|
75 |
|
76 return retval; |
|
77 } |
|
78 |
|
79 DEFUN (cell, args, , |
3448
|
80 "-*- texinfo -*-\n\ |
|
81 @deftypefn {Built-in Function} {} cell (@var{x})\n\ |
|
82 @deftypefnx {Built-in Function} {} cell (@var{n}, @var{m})\n\ |
|
83 Create a new cell array object. If invoked with a single scalar\n\ |
|
84 argument, @code{cell} returns a square cell array with the dimension\n\ |
|
85 specified. If you supply two scalar arguments, @code{cell} takes\n\ |
|
86 them to be the number of rows and columns. If given a vector with two\n\ |
|
87 elements, @code{cell} uses the values of the elements as the number of\n\ |
|
88 rows and columns, respectively.\n\ |
|
89 @end deftypefn") |
3354
|
90 { |
|
91 octave_value retval; |
|
92 |
|
93 int nargin = args.length (); |
|
94 |
|
95 switch (nargin) |
|
96 { |
|
97 case 1: |
|
98 { |
|
99 int nr, nc; |
|
100 get_dimensions (args(0), "cell", nr, nc); |
|
101 |
|
102 if (! error_state) |
|
103 retval = Cell (nr, nc, Matrix ()); |
|
104 } |
|
105 break; |
|
106 |
|
107 case 2: |
|
108 { |
|
109 int nr, nc; |
|
110 get_dimensions (args(0), args(1), "cell", nr, nc); |
|
111 |
|
112 if (! error_state) |
|
113 retval = Cell (nr, nc, Matrix ()); |
|
114 } |
|
115 break; |
|
116 |
|
117 default: |
|
118 print_usage ("cell"); |
|
119 break; |
|
120 } |
|
121 |
|
122 return retval; |
|
123 } |
|
124 |
3353
|
125 /* |
|
126 ;;; Local Variables: *** |
|
127 ;;; mode: C++ *** |
|
128 ;;; End: *** |
|
129 */ |