2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 |
2376
|
33 #include "lo-ieee.h" |
|
34 #include "mx-base.h" |
|
35 |
|
36 #include "ov-ch-mat.h" |
|
37 #include "gripes.h" |
|
38 #include "pr-output.h" |
|
39 |
2477
|
40 octave_allocator |
|
41 octave_char_matrix::allocator (sizeof (octave_char_matrix)); |
2376
|
42 |
2477
|
43 int |
|
44 octave_char_matrix::t_id (-1); |
|
45 |
|
46 const string |
|
47 octave_char_matrix::t_name ("char matrix"); |
2376
|
48 |
|
49 bool |
|
50 octave_char_matrix::valid_as_scalar_index (void) const |
|
51 { |
3136
|
52 bool retval = false; |
|
53 error ("octave_char_matrix::valid_as_scalar_index(): not implemented"); |
|
54 return retval; |
2376
|
55 } |
|
56 |
|
57 bool |
|
58 octave_char_matrix::valid_as_zero_index (void) const |
|
59 { |
3136
|
60 bool retval = false; |
|
61 error ("octave_char_matrix::valid_as_zero_index(): not implemented"); |
|
62 return retval; |
2376
|
63 } |
|
64 |
|
65 bool |
|
66 octave_char_matrix::is_true (void) const |
|
67 { |
3136
|
68 bool retval = false; |
|
69 |
|
70 if (rows () == 0 || columns () == 0) |
|
71 { |
|
72 int flag = Vpropagate_empty_matrices; |
|
73 |
|
74 if (flag < 0) |
|
75 warning ("empty matrix used in conditional expression"); |
|
76 else if (flag == 0) |
|
77 error ("empty matrix used in conditional expression"); |
|
78 } |
|
79 else |
|
80 { |
|
81 Matrix m = (matrix.all ()) . all (); |
|
82 |
|
83 retval = (m.rows () == 1 && m.columns () == 1 && m (0, 0) != 0.0); |
|
84 } |
|
85 |
|
86 return retval; |
2376
|
87 } |
|
88 |
|
89 double |
|
90 octave_char_matrix::double_value (bool) const |
|
91 { |
|
92 double retval = octave_NaN; |
|
93 |
|
94 if ((rows () == 1 && columns () == 1) |
|
95 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
96 retval = matrix (0, 0); |
|
97 else |
|
98 gripe_invalid_conversion ("character matrix", "real scalar"); |
|
99 |
|
100 return retval; |
|
101 } |
|
102 |
|
103 Complex |
|
104 octave_char_matrix::complex_value (bool) const |
|
105 { |
|
106 Complex retval (octave_NaN, octave_NaN); |
|
107 |
|
108 if ((rows () == 1 && columns () == 1) |
|
109 || (Vdo_fortran_indexing && rows () > 0 && columns () > 0)) |
|
110 retval = matrix (0, 0); |
|
111 else |
|
112 gripe_invalid_conversion ("character matrix", "complex scalar"); |
|
113 |
|
114 return retval; |
|
115 } |
|
116 |
|
117 void |
2901
|
118 octave_char_matrix::print (ostream& os, bool pr_as_read_syntax) const |
|
119 { |
|
120 print_raw (os, pr_as_read_syntax); |
|
121 newline (os); |
|
122 } |
|
123 |
|
124 void |
|
125 octave_char_matrix::print_raw (ostream& os, bool pr_as_read_syntax) const |
|
126 { |
|
127 octave_print_internal (os, matrix, pr_as_read_syntax, false, |
|
128 current_print_indent_level ()); |
|
129 } |
|
130 |
|
131 bool |
|
132 octave_char_matrix::print_name_tag (ostream& os, const string& name) const |
2376
|
133 { |
2901
|
134 bool retval = false; |
|
135 |
|
136 int nr = rows (); |
|
137 int nc = columns (); |
|
138 |
|
139 indent (os); |
|
140 |
|
141 if (nr == 1 && nc == 1 || (nr == 0 || nc == 0)) |
|
142 os << name << " = "; |
|
143 else |
|
144 { |
|
145 os << name << " ="; |
|
146 newline (os); |
|
147 newline (os); |
|
148 retval = true; |
|
149 } |
|
150 |
|
151 return retval; |
2376
|
152 } |
|
153 |
|
154 /* |
|
155 ;;; Local Variables: *** |
|
156 ;;; mode: C++ *** |
|
157 ;;; End: *** |
|
158 */ |