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 |
4612
|
51 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_bool_matrix, |
|
52 "bool matrix", "logical"); |
2871
|
53 |
|
54 static octave_value * |
|
55 default_numeric_conversion_function (const octave_value& a) |
|
56 { |
|
57 CAST_CONV_ARG (const octave_bool_matrix&); |
|
58 |
4668
|
59 return new octave_matrix (NDArray (v.bool_array_value ())); |
2871
|
60 } |
|
61 |
|
62 type_conv_fcn |
|
63 octave_bool_matrix::numeric_conversion_function (void) const |
|
64 { |
|
65 return default_numeric_conversion_function; |
|
66 } |
|
67 |
|
68 octave_value * |
|
69 octave_bool_matrix::try_narrowing_conversion (void) |
|
70 { |
|
71 octave_value *retval = 0; |
|
72 |
4513
|
73 if (matrix.ndims () == 2) |
|
74 { |
|
75 boolMatrix bm = matrix.matrix_value (); |
2871
|
76 |
4513
|
77 int nr = bm.rows (); |
|
78 int nc = bm.cols (); |
|
79 |
|
80 if (nr == 1 && nc == 1) |
|
81 retval = new octave_bool (bm (0, 0)); |
|
82 } |
2871
|
83 |
|
84 return retval; |
|
85 } |
|
86 |
|
87 bool |
|
88 octave_bool_matrix::valid_as_scalar_index (void) const |
|
89 { |
|
90 // XXX FIXME XXX |
|
91 return false; |
|
92 } |
|
93 |
|
94 double |
|
95 octave_bool_matrix::double_value (bool) const |
|
96 { |
4102
|
97 double retval = lo_ieee_nan_value (); |
2871
|
98 |
4455
|
99 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
100 if (rows () > 0 && columns () > 0) |
|
101 { |
|
102 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
103 if (Vwarn_fortran_indexing) |
|
104 gripe_implicit_conversion ("bool matrix", "real scalar"); |
|
105 |
|
106 retval = matrix (0, 0); |
|
107 } |
2871
|
108 else |
|
109 gripe_invalid_conversion ("bool matrix", "real scalar"); |
|
110 |
|
111 return retval; |
|
112 } |
|
113 |
|
114 Complex |
|
115 octave_bool_matrix::complex_value (bool) const |
|
116 { |
4102
|
117 double tmp = lo_ieee_nan_value (); |
|
118 |
|
119 Complex retval (tmp, tmp); |
2871
|
120 |
4455
|
121 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
122 if (rows () > 0 && columns () > 0) |
|
123 { |
|
124 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
125 if (Vwarn_fortran_indexing) |
|
126 gripe_implicit_conversion ("bool matrix", "complex scalar"); |
|
127 |
|
128 retval = matrix (0, 0); |
|
129 } |
2871
|
130 else |
|
131 gripe_invalid_conversion ("bool matrix", "complex scalar"); |
|
132 |
|
133 return retval; |
|
134 } |
|
135 |
4457
|
136 octave_value |
|
137 octave_bool_matrix::convert_to_str_internal (bool pad, bool force) const |
|
138 { |
|
139 octave_value tmp = octave_value (matrix_value ()); |
|
140 return tmp.convert_to_str (pad, force); |
|
141 } |
|
142 |
4643
|
143 void |
|
144 octave_bool_matrix::print_raw (std::ostream& os, |
|
145 bool pr_as_read_syntax) const |
|
146 { |
|
147 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
148 current_print_indent_level ()); |
|
149 } |
|
150 |
2871
|
151 /* |
|
152 ;;; Local Variables: *** |
|
153 ;;; mode: C++ *** |
|
154 ;;; End: *** |
|
155 */ |