Mercurial > hg > octave-avbm
annotate src/ov-ch-mat.cc @ 7855:f317f14516cb
Add zoom stack facility in axes object.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Tue, 04 Mar 2008 15:34:38 +0100 |
parents | 82be108cc558 |
children | f00578b495e9 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
4 2007 John W. Eaton | |
2376 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
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 |
6720 | 47 idx_vector |
48 octave_char_matrix::index_vector (void) const | |
49 { | |
50 const char *p = matrix.data (); | |
51 if (numel () == 1 && *p == ':') | |
52 return idx_vector (':'); | |
53 else | |
54 return idx_vector (array_value (true)); | |
55 } | |
56 | |
2376 | 57 bool |
58 octave_char_matrix::valid_as_scalar_index (void) const | |
59 { | |
3136 | 60 bool retval = false; |
61 error ("octave_char_matrix::valid_as_scalar_index(): not implemented"); | |
62 return retval; | |
2376 | 63 } |
64 | |
65 double | |
66 octave_char_matrix::double_value (bool) const | |
67 { | |
4102 | 68 double retval = lo_ieee_nan_value (); |
2376 | 69 |
4455 | 70 if (rows () > 0 && columns () > 0) |
71 { | |
5781 | 72 gripe_implicit_conversion ("Octave:array-as-scalar", |
73 "character matrix", "real scalar"); | |
4455 | 74 |
75 retval = matrix (0, 0); | |
76 } | |
2376 | 77 else |
78 gripe_invalid_conversion ("character matrix", "real scalar"); | |
79 | |
80 return retval; | |
81 } | |
82 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
83 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
84 octave_char_matrix::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
85 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
86 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
87 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
88 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
89 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
90 gripe_implicit_conversion ("Octave:array-as-scalar", |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
91 "character matrix", "real scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
92 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
93 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
94 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
95 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
96 gripe_invalid_conversion ("character matrix", "real scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
97 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
98 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
99 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
100 |
2376 | 101 Complex |
102 octave_char_matrix::complex_value (bool) const | |
103 { | |
4102 | 104 double tmp = lo_ieee_nan_value (); |
105 | |
106 Complex retval (tmp, tmp); | |
2376 | 107 |
4455 | 108 if (rows () > 0 && columns () > 0) |
109 { | |
5781 | 110 gripe_implicit_conversion ("Octave:array-as-scalar", |
111 "character matrix", "complex scalar"); | |
4455 | 112 |
113 retval = matrix (0, 0); | |
114 } | |
2376 | 115 else |
116 gripe_invalid_conversion ("character matrix", "complex scalar"); | |
117 | |
118 return retval; | |
119 } | |
120 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
121 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
122 octave_char_matrix::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
124 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
127 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
128 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
129 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
130 gripe_implicit_conversion ("Octave:array-as-scalar", |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
131 "character matrix", "complex scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
132 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
133 retval = matrix (0, 0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
134 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
135 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
136 gripe_invalid_conversion ("character matrix", "complex scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
137 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
139 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
140 |
4643 | 141 void |
142 octave_char_matrix::print_raw (std::ostream& os, | |
143 bool pr_as_read_syntax) const | |
144 { | |
145 octave_print_internal (os, matrix, pr_as_read_syntax, | |
146 current_print_indent_level ()); | |
147 } | |
148 | |
5900 | 149 mxArray * |
150 octave_char_matrix::as_mxArray (void) const | |
151 { | |
152 mxArray *retval = new mxArray (mxCHAR_CLASS, dims (), mxREAL); | |
153 | |
154 mxChar *pr = static_cast<mxChar *> (retval->get_data ()); | |
155 | |
6686 | 156 mwSize nel = numel (); |
5900 | 157 |
158 const char *p = matrix.data (); | |
159 | |
6686 | 160 for (mwIndex i = 0; i < nel; i++) |
5900 | 161 pr[i] = p[i]; |
162 | |
163 return retval; | |
164 } | |
165 | |
2376 | 166 /* |
167 ;;; Local Variables: *** | |
168 ;;; mode: C++ *** | |
169 ;;; End: *** | |
170 */ |