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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2376
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2376
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
3503
|
27 #include <iostream> |
2901
|
28 |
2376
|
29 #include "lo-ieee.h" |
|
30 #include "mx-base.h" |
|
31 |
3219
|
32 #include "ov-base.h" |
|
33 #include "ov-base-mat.h" |
|
34 #include "ov-base-mat.cc" |
2376
|
35 #include "ov-ch-mat.h" |
|
36 #include "gripes.h" |
|
37 #include "pr-output.h" |
|
38 |
4513
|
39 template class octave_base_matrix<charNDArray>; |
2376
|
40 |
3219
|
41 DEFINE_OCTAVE_ALLOCATOR (octave_char_matrix); |
2477
|
42 |
4612
|
43 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_char_matrix, |
|
44 "char matrix", "int8"); |
2376
|
45 |
6720
|
46 idx_vector |
|
47 octave_char_matrix::index_vector (void) const |
|
48 { |
|
49 const char *p = matrix.data (); |
|
50 if (numel () == 1 && *p == ':') |
|
51 return idx_vector (':'); |
|
52 else |
|
53 return idx_vector (array_value (true)); |
|
54 } |
|
55 |
2376
|
56 bool |
|
57 octave_char_matrix::valid_as_scalar_index (void) const |
|
58 { |
3136
|
59 bool retval = false; |
|
60 error ("octave_char_matrix::valid_as_scalar_index(): not implemented"); |
|
61 return retval; |
2376
|
62 } |
|
63 |
|
64 double |
|
65 octave_char_matrix::double_value (bool) const |
|
66 { |
4102
|
67 double retval = lo_ieee_nan_value (); |
2376
|
68 |
4455
|
69 if (rows () > 0 && columns () > 0) |
|
70 { |
5781
|
71 gripe_implicit_conversion ("Octave:array-as-scalar", |
|
72 "character matrix", "real scalar"); |
4455
|
73 |
|
74 retval = matrix (0, 0); |
|
75 } |
2376
|
76 else |
|
77 gripe_invalid_conversion ("character matrix", "real scalar"); |
|
78 |
|
79 return retval; |
|
80 } |
|
81 |
|
82 Complex |
|
83 octave_char_matrix::complex_value (bool) const |
|
84 { |
4102
|
85 double tmp = lo_ieee_nan_value (); |
|
86 |
|
87 Complex retval (tmp, tmp); |
2376
|
88 |
4455
|
89 if (rows () > 0 && columns () > 0) |
|
90 { |
5781
|
91 gripe_implicit_conversion ("Octave:array-as-scalar", |
|
92 "character matrix", "complex scalar"); |
4455
|
93 |
|
94 retval = matrix (0, 0); |
|
95 } |
2376
|
96 else |
|
97 gripe_invalid_conversion ("character matrix", "complex scalar"); |
|
98 |
|
99 return retval; |
|
100 } |
|
101 |
4643
|
102 void |
|
103 octave_char_matrix::print_raw (std::ostream& os, |
|
104 bool pr_as_read_syntax) const |
|
105 { |
|
106 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
107 current_print_indent_level ()); |
|
108 } |
|
109 |
5900
|
110 mxArray * |
|
111 octave_char_matrix::as_mxArray (void) const |
|
112 { |
|
113 mxArray *retval = new mxArray (mxCHAR_CLASS, dims (), mxREAL); |
|
114 |
|
115 mxChar *pr = static_cast<mxChar *> (retval->get_data ()); |
|
116 |
6686
|
117 mwSize nel = numel (); |
5900
|
118 |
|
119 const char *p = matrix.data (); |
|
120 |
6686
|
121 for (mwIndex i = 0; i < nel; i++) |
5900
|
122 pr[i] = p[i]; |
|
123 |
|
124 return retval; |
|
125 } |
|
126 |
2376
|
127 /* |
|
128 ;;; Local Variables: *** |
|
129 ;;; mode: C++ *** |
|
130 ;;; End: *** |
|
131 */ |