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 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
2901
|
31 #include <iostream.h> |
|
32 |
2871
|
33 #include "mx-base.h" |
|
34 |
|
35 #include "gripes.h" |
|
36 #include "oct-obj.h" |
|
37 #include "ops.h" |
|
38 #include "ov-bool.h" |
3223
|
39 #include "ov-base.h" |
|
40 #include "ov-base-scalar.h" |
|
41 #include "ov-base-scalar.cc" |
2871
|
42 #include "ov-re-mat.h" |
|
43 #include "ov-scalar.h" |
|
44 #include "pr-output.h" |
|
45 |
3223
|
46 template class octave_base_scalar<bool>; |
|
47 |
3219
|
48 DEFINE_OCTAVE_ALLOCATOR (octave_bool); |
2871
|
49 |
3219
|
50 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_bool, "bool"); |
2871
|
51 |
|
52 static octave_value * |
|
53 default_numeric_conversion_function (const octave_value& a) |
|
54 { |
|
55 CAST_CONV_ARG (const octave_bool&); |
|
56 |
|
57 return new octave_scalar (v.bool_value ()); |
|
58 } |
|
59 |
|
60 type_conv_fcn |
|
61 octave_bool::numeric_conversion_function (void) const |
|
62 { |
|
63 return default_numeric_conversion_function; |
|
64 } |
|
65 |
|
66 static inline bool |
|
67 valid_scalar_indices (const octave_value_list& args) |
|
68 { |
|
69 int nargin = args.length (); |
|
70 |
|
71 for (int i = 0; i < nargin; i++) |
|
72 if (! args(i).valid_as_scalar_index ()) |
|
73 return false; |
|
74 |
|
75 return true; |
|
76 } |
|
77 |
|
78 octave_value |
2974
|
79 octave_bool::do_index_op (const octave_value_list& idx) |
2871
|
80 { |
|
81 octave_value retval; |
|
82 |
|
83 if (valid_scalar_indices (idx)) |
|
84 retval = scalar; |
|
85 else |
|
86 { |
|
87 // XXX FIXME XXX -- this doesn't solve the problem of |
|
88 // |
|
89 // a = 1; a([1,1], [1,1], [1,1]) |
|
90 // |
|
91 // and similar constructions. Hmm... |
|
92 |
|
93 // XXX FIXME XXX -- using this constructor avoids narrowing the |
|
94 // 1x1 matrix back to a scalar value. Need a better solution |
|
95 // to this problem. |
|
96 |
|
97 octave_value tmp (new octave_matrix (matrix_value ())); |
|
98 |
2962
|
99 retval = tmp.do_index_op (idx); |
2871
|
100 } |
|
101 |
|
102 return retval; |
|
103 } |
|
104 |
|
105 octave_value |
|
106 octave_bool::convert_to_str (void) const |
|
107 { |
|
108 char s[2]; |
|
109 s[0] = (char) scalar; |
|
110 s[1] = '\0'; |
|
111 |
|
112 return octave_value (s); |
|
113 } |
|
114 |
|
115 /* |
|
116 ;;; Local Variables: *** |
|
117 ;;; mode: C++ *** |
|
118 ;;; End: *** |
|
119 */ |