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