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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2376
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
2901
|
29 |
2376
|
30 #include "lo-ieee.h" |
|
31 #include "mx-base.h" |
|
32 |
3219
|
33 #include "ov-base.h" |
|
34 #include "ov-base-mat.h" |
|
35 #include "ov-base-mat.cc" |
2376
|
36 #include "ov-ch-mat.h" |
|
37 #include "gripes.h" |
|
38 #include "pr-output.h" |
|
39 |
4513
|
40 template class octave_base_matrix<charNDArray>; |
2376
|
41 |
3219
|
42 DEFINE_OCTAVE_ALLOCATOR (octave_char_matrix); |
2477
|
43 |
4612
|
44 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_char_matrix, |
|
45 "char matrix", "int8"); |
2376
|
46 |
|
47 bool |
|
48 octave_char_matrix::valid_as_scalar_index (void) const |
|
49 { |
3136
|
50 bool retval = false; |
|
51 error ("octave_char_matrix::valid_as_scalar_index(): not implemented"); |
|
52 return retval; |
2376
|
53 } |
|
54 |
|
55 double |
|
56 octave_char_matrix::double_value (bool) const |
|
57 { |
4102
|
58 double retval = lo_ieee_nan_value (); |
2376
|
59 |
4455
|
60 if (rows () > 0 && columns () > 0) |
|
61 { |
5781
|
62 gripe_implicit_conversion ("Octave:array-as-scalar", |
|
63 "character matrix", "real scalar"); |
4455
|
64 |
|
65 retval = matrix (0, 0); |
|
66 } |
2376
|
67 else |
|
68 gripe_invalid_conversion ("character matrix", "real scalar"); |
|
69 |
|
70 return retval; |
|
71 } |
|
72 |
|
73 Complex |
|
74 octave_char_matrix::complex_value (bool) const |
|
75 { |
4102
|
76 double tmp = lo_ieee_nan_value (); |
|
77 |
|
78 Complex retval (tmp, tmp); |
2376
|
79 |
4455
|
80 if (rows () > 0 && columns () > 0) |
|
81 { |
5781
|
82 gripe_implicit_conversion ("Octave:array-as-scalar", |
|
83 "character matrix", "complex scalar"); |
4455
|
84 |
|
85 retval = matrix (0, 0); |
|
86 } |
2376
|
87 else |
|
88 gripe_invalid_conversion ("character matrix", "complex scalar"); |
|
89 |
|
90 return retval; |
|
91 } |
|
92 |
4643
|
93 void |
|
94 octave_char_matrix::print_raw (std::ostream& os, |
|
95 bool pr_as_read_syntax) const |
|
96 { |
|
97 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
98 current_print_indent_level ()); |
|
99 } |
|
100 |
5900
|
101 mxArray * |
|
102 octave_char_matrix::as_mxArray (void) const |
|
103 { |
|
104 mxArray *retval = new mxArray (mxCHAR_CLASS, dims (), mxREAL); |
|
105 |
|
106 mxChar *pr = static_cast<mxChar *> (retval->get_data ()); |
|
107 |
|
108 int nel = numel (); |
|
109 |
|
110 const char *p = matrix.data (); |
|
111 |
|
112 for (int i = 0; i < nel; i++) |
|
113 pr[i] = p[i]; |
|
114 |
|
115 return retval; |
|
116 } |
|
117 |
2376
|
118 /* |
|
119 ;;; Local Variables: *** |
|
120 ;;; mode: C++ *** |
|
121 ;;; End: *** |
|
122 */ |