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