2871
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2871
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
2901
|
32 |
2871
|
33 #include "lo-ieee.h" |
|
34 #include "mx-base.h" |
|
35 |
|
36 #include "gripes.h" |
|
37 #include "oct-obj.h" |
|
38 #include "ops.h" |
3219
|
39 #include "ov-base.h" |
|
40 #include "ov-base-mat.h" |
|
41 #include "ov-base-mat.cc" |
2871
|
42 #include "ov-bool.h" |
|
43 #include "ov-bool-mat.h" |
|
44 #include "ov-re-mat.h" |
|
45 #include "pr-output.h" |
|
46 |
4513
|
47 template class octave_base_matrix<boolNDArray>; |
2871
|
48 |
3219
|
49 DEFINE_OCTAVE_ALLOCATOR (octave_bool_matrix); |
2871
|
50 |
3219
|
51 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_bool_matrix, "bool matrix"); |
2871
|
52 |
|
53 static octave_value * |
|
54 default_numeric_conversion_function (const octave_value& a) |
|
55 { |
|
56 CAST_CONV_ARG (const octave_bool_matrix&); |
|
57 |
|
58 return new octave_matrix (Matrix (v.bool_matrix_value ())); |
|
59 } |
|
60 |
|
61 type_conv_fcn |
|
62 octave_bool_matrix::numeric_conversion_function (void) const |
|
63 { |
|
64 return default_numeric_conversion_function; |
|
65 } |
|
66 |
|
67 octave_value * |
|
68 octave_bool_matrix::try_narrowing_conversion (void) |
|
69 { |
|
70 octave_value *retval = 0; |
|
71 |
4513
|
72 if (matrix.ndims () == 2) |
|
73 { |
|
74 boolMatrix bm = matrix.matrix_value (); |
2871
|
75 |
4513
|
76 int nr = bm.rows (); |
|
77 int nc = bm.cols (); |
|
78 |
|
79 if (nr == 1 && nc == 1) |
|
80 retval = new octave_bool (bm (0, 0)); |
|
81 } |
2871
|
82 |
|
83 return retval; |
|
84 } |
|
85 |
|
86 bool |
|
87 octave_bool_matrix::valid_as_scalar_index (void) const |
|
88 { |
|
89 // XXX FIXME XXX |
|
90 return false; |
|
91 } |
|
92 |
|
93 double |
|
94 octave_bool_matrix::double_value (bool) const |
|
95 { |
4102
|
96 double retval = lo_ieee_nan_value (); |
2871
|
97 |
4455
|
98 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
99 if (rows () > 0 && columns () > 0) |
|
100 { |
|
101 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
102 if (Vwarn_fortran_indexing) |
|
103 gripe_implicit_conversion ("bool matrix", "real scalar"); |
|
104 |
|
105 retval = matrix (0, 0); |
|
106 } |
2871
|
107 else |
|
108 gripe_invalid_conversion ("bool matrix", "real scalar"); |
|
109 |
|
110 return retval; |
|
111 } |
|
112 |
|
113 Complex |
|
114 octave_bool_matrix::complex_value (bool) const |
|
115 { |
4102
|
116 double tmp = lo_ieee_nan_value (); |
|
117 |
|
118 Complex retval (tmp, tmp); |
2871
|
119 |
4455
|
120 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
121 if (rows () > 0 && columns () > 0) |
|
122 { |
|
123 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
124 if (Vwarn_fortran_indexing) |
|
125 gripe_implicit_conversion ("bool matrix", "complex scalar"); |
|
126 |
|
127 retval = matrix (0, 0); |
|
128 } |
2871
|
129 else |
|
130 gripe_invalid_conversion ("bool matrix", "complex scalar"); |
|
131 |
|
132 return retval; |
|
133 } |
|
134 |
4457
|
135 octave_value |
|
136 octave_bool_matrix::convert_to_str_internal (bool pad, bool force) const |
|
137 { |
|
138 octave_value tmp = octave_value (matrix_value ()); |
|
139 return tmp.convert_to_str (pad, force); |
|
140 } |
|
141 |
2871
|
142 /* |
|
143 ;;; Local Variables: *** |
|
144 ;;; mode: C++ *** |
|
145 ;;; End: *** |
|
146 */ |