4904
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 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 #include <cstdlib> |
|
24 |
|
25 #include <iostream> |
|
26 #include <string> |
|
27 |
|
28 #include "mx-base.h" |
|
29 #include "oct-alloc.h" |
|
30 #include "so-array.h" |
|
31 #include "str-vec.h" |
|
32 |
|
33 #include "error.h" |
4944
|
34 #include "oct-stream.h" |
4904
|
35 #include "ov-base.h" |
|
36 #include "ov-base-int.h" |
|
37 #include "ov-typeinfo.h" |
|
38 |
|
39 class |
|
40 OCTAVE_VALUE_INT_MATRIX_T |
|
41 : public octave_base_int_matrix<OCTAVE_INT_NDARRAY_T> |
|
42 { |
|
43 public: |
|
44 |
|
45 OCTAVE_VALUE_INT_MATRIX_T (void) |
|
46 : octave_base_int_matrix<OCTAVE_INT_NDARRAY_T> () { } |
|
47 |
|
48 OCTAVE_VALUE_INT_MATRIX_T (const OCTAVE_INT_NDARRAY_T& nda) |
|
49 : octave_base_int_matrix<OCTAVE_INT_NDARRAY_T> (nda) { } |
|
50 |
|
51 ~OCTAVE_VALUE_INT_MATRIX_T (void) { } |
|
52 |
|
53 octave_value * |
|
54 clone (void) const |
|
55 { return new OCTAVE_VALUE_INT_MATRIX_T (*this); } |
|
56 |
|
57 octave_value * |
|
58 empty_clone (void) const |
|
59 { return new OCTAVE_VALUE_INT_MATRIX_T (); } |
|
60 |
|
61 OCTAVE_INT_NDARRAY_T |
4910
|
62 OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (void) const |
4904
|
63 { return matrix; } |
|
64 |
4915
|
65 NDArray |
|
66 array_value (bool = false) const |
|
67 { |
|
68 NDArray retval (matrix.dims ()); |
|
69 int nel = matrix.numel (); |
|
70 for (int i = 0; i < nel; i++) |
4963
|
71 retval(i) = double (matrix(i)); |
|
72 return retval; |
|
73 } |
|
74 |
|
75 ComplexNDArray |
|
76 complex_array_value (bool = false) const |
|
77 { |
|
78 ComplexNDArray retval (matrix.dims ()); |
|
79 int nel = matrix.numel (); |
|
80 for (int i = 0; i < nel; i++) |
|
81 retval(i) = Complex (matrix(i)); |
4915
|
82 return retval; |
|
83 } |
|
84 |
4938
|
85 idx_vector index_vector (void) const { return idx_vector (matrix); } |
|
86 |
4944
|
87 int write (octave_stream& os, int block_size, |
|
88 oct_data_conv::data_type output_type, int skip, |
|
89 oct_mach_info::float_format flt_fmt) const |
|
90 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
|
91 |
4904
|
92 private: |
|
93 |
|
94 DECLARE_OCTAVE_ALLOCATOR |
|
95 |
|
96 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
97 }; |
|
98 |
|
99 class |
|
100 OCTAVE_VALUE_INT_SCALAR_T |
|
101 : public octave_base_int_scalar<OCTAVE_INT_T> |
|
102 { |
|
103 public: |
|
104 |
|
105 OCTAVE_VALUE_INT_SCALAR_T (void) |
|
106 : octave_base_int_scalar<OCTAVE_INT_T> () { } |
|
107 |
|
108 OCTAVE_VALUE_INT_SCALAR_T (const OCTAVE_INT_T& nda) |
|
109 : octave_base_int_scalar<OCTAVE_INT_T> (nda) { } |
|
110 |
|
111 ~OCTAVE_VALUE_INT_SCALAR_T (void) { } |
|
112 |
|
113 octave_value * |
|
114 clone (void) const |
|
115 { return new OCTAVE_VALUE_INT_SCALAR_T (*this); } |
|
116 |
|
117 octave_value * |
|
118 empty_clone (void) const |
|
119 { return new OCTAVE_VALUE_INT_SCALAR_T (); } |
|
120 |
|
121 OCTAVE_INT_T |
4910
|
122 OCTAVE_VALUE_INT_SCALAR_EXTRACTOR_FUNCTION (void) const |
4904
|
123 { return scalar; } |
|
124 |
|
125 OCTAVE_INT_NDARRAY_T |
4910
|
126 OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (void) const |
|
127 { return OCTAVE_INT_NDARRAY_T (dim_vector (1, 1), scalar); } |
4904
|
128 |
4915
|
129 octave_value resize (const dim_vector& dv) const |
|
130 { OCTAVE_INT_NDARRAY_T retval (dv); if (dv.numel()) retval(0) = scalar; return retval; } |
|
131 |
|
132 NDArray |
|
133 array_value (bool = false) const |
|
134 { |
|
135 NDArray retval (dim_vector (1,1)); |
4963
|
136 retval(0) = double (scalar); |
|
137 return retval; |
|
138 } |
|
139 |
|
140 ComplexNDArray |
|
141 complex_array_value (bool = false) const |
|
142 { |
|
143 ComplexNDArray retval (dim_vector (1,1)); |
|
144 retval(0) = Complex (scalar); |
4915
|
145 return retval; |
|
146 } |
|
147 |
4938
|
148 idx_vector index_vector (void) const { return idx_vector (scalar); } |
|
149 |
4944
|
150 int write (octave_stream& os, int block_size, |
|
151 oct_data_conv::data_type output_type, int skip, |
|
152 oct_mach_info::float_format flt_fmt) const |
|
153 { |
|
154 return os.write (OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (), |
|
155 block_size, output_type, skip, flt_fmt); |
|
156 } |
|
157 |
4904
|
158 private: |
|
159 |
|
160 DECLARE_OCTAVE_ALLOCATOR |
|
161 |
|
162 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
163 }; |
|
164 |
|
165 /* |
|
166 ;;; Local Variables: *** |
|
167 ;;; mode: C++ *** |
|
168 ;;; End: *** |
|
169 */ |