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++) |
|
71 retval (i) = double (matrix(i)); |
|
72 return retval; |
|
73 } |
|
74 |
4938
|
75 idx_vector index_vector (void) const { return idx_vector (matrix); } |
|
76 |
4944
|
77 int write (octave_stream& os, int block_size, |
|
78 oct_data_conv::data_type output_type, int skip, |
|
79 oct_mach_info::float_format flt_fmt) const |
|
80 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
|
81 |
4904
|
82 private: |
|
83 |
|
84 DECLARE_OCTAVE_ALLOCATOR |
|
85 |
|
86 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
87 }; |
|
88 |
|
89 class |
|
90 OCTAVE_VALUE_INT_SCALAR_T |
|
91 : public octave_base_int_scalar<OCTAVE_INT_T> |
|
92 { |
|
93 public: |
|
94 |
|
95 OCTAVE_VALUE_INT_SCALAR_T (void) |
|
96 : octave_base_int_scalar<OCTAVE_INT_T> () { } |
|
97 |
|
98 OCTAVE_VALUE_INT_SCALAR_T (const OCTAVE_INT_T& nda) |
|
99 : octave_base_int_scalar<OCTAVE_INT_T> (nda) { } |
|
100 |
|
101 ~OCTAVE_VALUE_INT_SCALAR_T (void) { } |
|
102 |
|
103 octave_value * |
|
104 clone (void) const |
|
105 { return new OCTAVE_VALUE_INT_SCALAR_T (*this); } |
|
106 |
|
107 octave_value * |
|
108 empty_clone (void) const |
|
109 { return new OCTAVE_VALUE_INT_SCALAR_T (); } |
|
110 |
|
111 OCTAVE_INT_T |
4910
|
112 OCTAVE_VALUE_INT_SCALAR_EXTRACTOR_FUNCTION (void) const |
4904
|
113 { return scalar; } |
|
114 |
|
115 OCTAVE_INT_NDARRAY_T |
4910
|
116 OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (void) const |
|
117 { return OCTAVE_INT_NDARRAY_T (dim_vector (1, 1), scalar); } |
4904
|
118 |
4915
|
119 octave_value resize (const dim_vector& dv) const |
|
120 { OCTAVE_INT_NDARRAY_T retval (dv); if (dv.numel()) retval(0) = scalar; return retval; } |
|
121 |
|
122 NDArray |
|
123 array_value (bool = false) const |
|
124 { |
|
125 NDArray retval (dim_vector (1,1)); |
|
126 retval (0) = double (scalar); |
|
127 return retval; |
|
128 } |
|
129 |
4938
|
130 idx_vector index_vector (void) const { return idx_vector (scalar); } |
|
131 |
4944
|
132 int write (octave_stream& os, int block_size, |
|
133 oct_data_conv::data_type output_type, int skip, |
|
134 oct_mach_info::float_format flt_fmt) const |
|
135 { |
|
136 return os.write (OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (), |
|
137 block_size, output_type, skip, flt_fmt); |
|
138 } |
|
139 |
4904
|
140 private: |
|
141 |
|
142 DECLARE_OCTAVE_ALLOCATOR |
|
143 |
|
144 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
145 }; |
|
146 |
|
147 /* |
|
148 ;;; Local Variables: *** |
|
149 ;;; mode: C++ *** |
|
150 ;;; End: *** |
|
151 */ |