comparison src/octave-value/ov-base.h @ 15057:46b19589b593

maint: Partition src/ directory with more code in subdirs. Create new octave-value dir for ov* code. Create new parse-tre dir for pt* code. Move OPERATORS and TEMPLATE-INST directories to lowercase names * octave-value/module.mk: Hook code in octave-value dir into build system. * octave-value/ov-base-diag.cc, octave-value/ov-base-diag.h, octave-value/ov-base-int.cc, octave-value/ov-base-int.h, octave-value/ov-base-mat.cc, octave-value/ov-base-mat.h, octave-value/ov-base-scalar.cc, octave-value/ov-base-scalar.h, octave-value/ov-base-sparse.cc, octave-value/ov-base-sparse.h, octave-value/ov-base.cc, octave-value/ov-base.h, octave-value/ov-bool-mat.cc, octave-value/ov-bool-mat.h, octave-value/ov-bool-sparse.cc, octave-value/ov-bool-sparse.h, octave-value/ov-bool.cc, octave-value/ov-bool.h, octave-value/ov-builtin.cc, octave-value/ov-builtin.h, octave-value/ov-cell.cc, octave-value/ov-cell.h, octave-value/ov-ch-mat.cc, octave-value/ov-ch-mat.h, octave-value/ov-class.cc, octave-value/ov-class.h, octave-value/ov-colon.cc, octave-value/ov-colon.h, octave-value/ov-complex.cc, octave-value/ov-complex.h, octave-value/ov-cs-list.cc, octave-value/ov-cs-list.h, octave-value/ov-cx-diag.cc, octave-value/ov-cx-diag.h, octave-value/ov-cx-mat.cc, octave-value/ov-cx-mat.h, octave-value/ov-cx-sparse.cc, octave-value/ov-cx-sparse.h, octave-value/ov-dld-fcn.cc, octave-value/ov-dld-fcn.h, octave-value/ov-fcn-handle.cc, octave-value/ov-fcn-handle.h, octave-value/ov-fcn-inline.cc, octave-value/ov-fcn-inline.h, octave-value/ov-fcn.cc, octave-value/ov-fcn.h, octave-value/ov-float.cc, octave-value/ov-float.h, octave-value/ov-flt-complex.cc, octave-value/ov-flt-complex.h, octave-value/ov-flt-cx-diag.cc, octave-value/ov-flt-cx-diag.h, octave-value/ov-flt-cx-mat.cc, octave-value/ov-flt-cx-mat.h, octave-value/ov-flt-re-diag.cc, octave-value/ov-flt-re-diag.h, octave-value/ov-flt-re-mat.cc, octave-value/ov-flt-re-mat.h, octave-value/ov-int-traits.h, octave-value/ov-int16.cc, octave-value/ov-int16.h, octave-value/ov-int32.cc, octave-value/ov-int32.h, octave-value/ov-int64.cc, octave-value/ov-int64.h, octave-value/ov-int8.cc, octave-value/ov-int8.h, octave-value/ov-intx.h, octave-value/ov-lazy-idx.cc, octave-value/ov-lazy-idx.h, octave-value/ov-mex-fcn.cc, octave-value/ov-mex-fcn.h, octave-value/ov-null-mat.cc, octave-value/ov-null-mat.h, octave-value/ov-oncleanup.cc, octave-value/ov-oncleanup.h, octave-value/ov-perm.cc, octave-value/ov-perm.h, octave-value/ov-range.cc, octave-value/ov-range.h, octave-value/ov-re-diag.cc, octave-value/ov-re-diag.h, octave-value/ov-re-mat.cc, octave-value/ov-re-mat.h, octave-value/ov-re-sparse.cc, octave-value/ov-re-sparse.h, octave-value/ov-scalar.cc, octave-value/ov-scalar.h, octave-value/ov-str-mat.cc, octave-value/ov-str-mat.h, octave-value/ov-struct.cc, octave-value/ov-struct.h, octave-value/ov-type-conv.h, octave-value/ov-typeinfo.cc, octave-value/ov-typeinfo.h, octave-value/ov-uint16.cc, octave-value/ov-uint16.h, octave-value/ov-uint32.cc, octave-value/ov-uint32.h, octave-value/ov-uint64.cc, octave-value/ov-uint64.h, octave-value/ov-uint8.cc, octave-value/ov-uint8.h, octave-value/ov-usr-fcn.cc, octave-value/ov-usr-fcn.h, octave-value/ov.cc, octave-value/ov.h: Moved from src/ dir to octave-value dir. * operators/module.mk, operators/op-b-b.cc, operators/op-b-bm.cc, operators/op-b-sbm.cc, operators/op-bm-b.cc, operators/op-bm-bm.cc, operators/op-bm-sbm.cc, operators/op-cdm-cdm.cc, operators/op-cdm-cm.cc, operators/op-cdm-cs.cc, operators/op-cdm-dm.cc, operators/op-cdm-m.cc, operators/op-cdm-s.cc, operators/op-cell.cc, operators/op-chm.cc, operators/op-class.cc, operators/op-cm-cdm.cc, operators/op-cm-cm.cc, operators/op-cm-cs.cc, operators/op-cm-dm.cc, operators/op-cm-m.cc, operators/op-cm-pm.cc, operators/op-cm-s.cc, operators/op-cm-scm.cc, operators/op-cm-sm.cc, operators/op-cs-cm.cc, operators/op-cs-cs.cc, operators/op-cs-m.cc, operators/op-cs-s.cc, operators/op-cs-scm.cc, operators/op-cs-sm.cc, operators/op-dm-cdm.cc, operators/op-dm-cm.cc, operators/op-dm-cs.cc, operators/op-dm-dm.cc, operators/op-dm-m.cc, operators/op-dm-s.cc, operators/op-dm-scm.cc, operators/op-dm-sm.cc, operators/op-dm-template.cc, operators/op-dms-template.cc, operators/op-double-conv.cc, operators/op-fcdm-fcdm.cc, operators/op-fcdm-fcm.cc, operators/op-fcdm-fcs.cc, operators/op-fcdm-fdm.cc, operators/op-fcdm-fm.cc, operators/op-fcdm-fs.cc, operators/op-fcm-fcdm.cc, operators/op-fcm-fcm.cc, operators/op-fcm-fcs.cc, operators/op-fcm-fdm.cc, operators/op-fcm-fm.cc, operators/op-fcm-fs.cc, operators/op-fcm-pm.cc, operators/op-fcn.cc, operators/op-fcs-fcm.cc, operators/op-fcs-fcs.cc, operators/op-fcs-fm.cc, operators/op-fcs-fs.cc, operators/op-fdm-fcdm.cc, operators/op-fdm-fcm.cc, operators/op-fdm-fcs.cc, operators/op-fdm-fdm.cc, operators/op-fdm-fm.cc, operators/op-fdm-fs.cc, operators/op-float-conv.cc, operators/op-fm-fcdm.cc, operators/op-fm-fcm.cc, operators/op-fm-fcs.cc, operators/op-fm-fdm.cc, operators/op-fm-fm.cc, operators/op-fm-fs.cc, operators/op-fm-pm.cc, operators/op-fs-fcm.cc, operators/op-fs-fcs.cc, operators/op-fs-fm.cc, operators/op-fs-fs.cc, operators/op-i16-i16.cc, operators/op-i32-i32.cc, operators/op-i64-i64.cc, operators/op-i8-i8.cc, operators/op-int-concat.cc, operators/op-int-conv.cc, operators/op-int.h, operators/op-m-cdm.cc, operators/op-m-cm.cc, operators/op-m-cs.cc, operators/op-m-dm.cc, operators/op-m-m.cc, operators/op-m-pm.cc, operators/op-m-s.cc, operators/op-m-scm.cc, operators/op-m-sm.cc, operators/op-pm-cm.cc, operators/op-pm-fcm.cc, operators/op-pm-fm.cc, operators/op-pm-m.cc, operators/op-pm-pm.cc, operators/op-pm-scm.cc, operators/op-pm-sm.cc, operators/op-pm-template.cc, operators/op-range.cc, operators/op-s-cm.cc, operators/op-s-cs.cc, operators/op-s-m.cc, operators/op-s-s.cc, operators/op-s-scm.cc, operators/op-s-sm.cc, operators/op-sbm-b.cc, operators/op-sbm-bm.cc, operators/op-sbm-sbm.cc, operators/op-scm-cm.cc, operators/op-scm-cs.cc, operators/op-scm-m.cc, operators/op-scm-s.cc, operators/op-scm-scm.cc, operators/op-scm-sm.cc, operators/op-sm-cm.cc, operators/op-sm-cs.cc, operators/op-sm-m.cc, operators/op-sm-s.cc, operators/op-sm-scm.cc, operators/op-sm-sm.cc, operators/op-str-m.cc, operators/op-str-s.cc, operators/op-str-str.cc, operators/op-struct.cc, operators/op-ui16-ui16.cc, operators/op-ui32-ui32.cc, operators/op-ui64-ui64.cc, operators/op-ui8-ui8.cc: Moved from OPERATORS/ dir to operators/ directory. * mkops: Correctly print comment in generated file ops.cc that it is made by mkops. Change sed expression for OPERATORS/ to operators/. * parse-tree/module.mk: Hook code in parse-tree dir into build system. * parse-tree/pt-all.h, parse-tree/pt-arg-list.cc, parse-tree/pt-arg-list.h, parse-tree/pt-assign.cc, parse-tree/pt-assign.h, parse-tree/pt-binop.cc, parse-tree/pt-binop.h, parse-tree/pt-bp.cc, parse-tree/pt-bp.h, parse-tree/pt-cbinop.cc, parse-tree/pt-cbinop.h, parse-tree/pt-cell.cc, parse-tree/pt-cell.h, parse-tree/pt-check.cc, parse-tree/pt-check.h, parse-tree/pt-cmd.cc, parse-tree/pt-cmd.h, parse-tree/pt-colon.cc, parse-tree/pt-colon.h, parse-tree/pt-const.cc, parse-tree/pt-const.h, parse-tree/pt-decl.cc, parse-tree/pt-decl.h, parse-tree/pt-eval.cc, parse-tree/pt-eval.h, parse-tree/pt-except.cc, parse-tree/pt-except.h, parse-tree/pt-exp.cc, parse-tree/pt-exp.h, parse-tree/pt-fcn-handle.cc, parse-tree/pt-fcn-handle.h, parse-tree/pt-id.cc, parse-tree/pt-id.h, parse-tree/pt-idx.cc, parse-tree/pt-idx.h, parse-tree/pt-jump.cc, parse-tree/pt-jump.h, parse-tree/pt-loop.cc, parse-tree/pt-loop.h, parse-tree/pt-mat.cc, parse-tree/pt-mat.h, parse-tree/pt-misc.cc, parse-tree/pt-misc.h, parse-tree/pt-pr-code.cc, parse-tree/pt-pr-code.h, parse-tree/pt-select.cc, parse-tree/pt-select.h, parse-tree/pt-stmt.cc, parse-tree/pt-stmt.h, parse-tree/pt-unop.cc, parse-tree/pt-unop.h, parse-tree/pt-walk.h, parse-tree/pt.cc, parse-tree/pt.h: Moved from src/ dir to parse-tree dir. * template-inst/Array-jit.cc, template-inst/Array-os.cc, template-inst/Array-sym.cc, template-inst/Array-tc.cc, template-inst/module.mk: Moved from TEMPLATE-INST dir to template-inst/ directory. * src/Makefile.am: Add new directories to build system. * corefcn/module.mk: Use COREFCN_SRC with all capitals to indicate it is not an Automake special target.
author Rik <rik@octave.org>
date Mon, 30 Jul 2012 15:29:19 -0700
parents src/ov-base.h@466cb8673653
children 62a35ae7d6a2
comparison
equal deleted inserted replaced
15056:bc32288f4a42 15057:46b19589b593
1 /*
2
3 Copyright (C) 1996-2012 John W. Eaton
4 Copyright (C) 2009-2010 VZLU Prague
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
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
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
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21
22 */
23
24 #if !defined (octave_base_value_h)
25 #define octave_base_value_h 1
26
27 #include <cstdlib>
28
29 #include <iosfwd>
30 #include <list>
31 #include <string>
32
33 #include "Range.h"
34 #include "data-conv.h"
35 #include "mxarray.h"
36 #include "mx-base.h"
37 #include "str-vec.h"
38
39 #include "error.h"
40 #include "oct-hdf5.h"
41
42 class Cell;
43 class octave_map;
44 class octave_scalar_map;
45 class octave_value;
46 class octave_value_list;
47 class octave_stream;
48 class octave_function;
49 class octave_user_function;
50 class octave_user_script;
51 class octave_user_code;
52 class octave_fcn_handle;
53 class octave_fcn_inline;
54 class octave_value_list;
55 class octave_lvalue;
56
57 class tree_walker;
58
59 enum builtin_type_t
60 {
61 btyp_double,
62 btyp_float,
63 btyp_complex,
64 btyp_float_complex,
65 btyp_int8,
66 btyp_int16,
67 btyp_int32,
68 btyp_int64,
69 btyp_uint8,
70 btyp_uint16,
71 btyp_uint32,
72 btyp_uint64,
73 btyp_bool,
74 btyp_char,
75 btyp_struct,
76 btyp_cell,
77 btyp_func_handle,
78 btyp_unknown,
79 btyp_num_types = btyp_unknown
80 };
81
82 extern OCTINTERP_API std::string
83 btyp_class_name [btyp_num_types];
84
85 extern OCTINTERP_API string_vector
86 get_builtin_classes (void);
87
88 inline bool btyp_isnumeric (builtin_type_t btyp)
89 { return btyp <= btyp_uint64; }
90
91 inline bool btyp_isinteger (builtin_type_t btyp)
92 { return btyp >= btyp_int8 && btyp <= btyp_uint64; }
93
94 inline bool btyp_isfloat (builtin_type_t btyp)
95 { return btyp <= btyp_float_complex; }
96
97 inline bool btyp_isarray (builtin_type_t btyp)
98 { return btyp <= btyp_char; }
99
100 // Compute a numeric type for a possibly mixed-type operation, using these rules:
101 // bool -> double
102 // single + double -> single
103 // real + complex -> complex
104 // integer + real -> integer
105 // uint + uint -> uint (the bigger one)
106 // sint + sint -> sint (the bigger one)
107 //
108 // failing otherwise.
109
110 extern OCTINTERP_API
111 builtin_type_t btyp_mixed_numeric (builtin_type_t x, builtin_type_t y);
112
113 template <class T>
114 struct class_to_btyp
115 {
116 static const builtin_type_t btyp = btyp_unknown;
117 };
118
119 #define DEF_CLASS_TO_BTYP(CLASS,BTYP) \
120 template <> \
121 struct class_to_btyp<CLASS> \
122 { static const builtin_type_t btyp = BTYP; }
123
124 DEF_CLASS_TO_BTYP (double, btyp_double);
125 DEF_CLASS_TO_BTYP (float, btyp_float);
126 DEF_CLASS_TO_BTYP (Complex, btyp_complex);
127 DEF_CLASS_TO_BTYP (FloatComplex, btyp_float_complex);
128 DEF_CLASS_TO_BTYP (octave_int8, btyp_int8);
129 DEF_CLASS_TO_BTYP (octave_int16, btyp_int16);
130 DEF_CLASS_TO_BTYP (octave_int32, btyp_int32);
131 DEF_CLASS_TO_BTYP (octave_int64, btyp_int64);
132 DEF_CLASS_TO_BTYP (octave_uint8, btyp_uint8);
133 DEF_CLASS_TO_BTYP (octave_uint16, btyp_uint16);
134 DEF_CLASS_TO_BTYP (octave_uint32, btyp_uint32);
135 DEF_CLASS_TO_BTYP (octave_uint64, btyp_uint64);
136 DEF_CLASS_TO_BTYP (bool, btyp_bool);
137 DEF_CLASS_TO_BTYP (char, btyp_char);
138
139 // T_ID is the type id of struct objects, set by register_type().
140 // T_NAME is the type name of struct objects.
141
142 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \
143 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2 (OCTAVE_EMPTY_CPP_ARG)
144
145 #define DECLARE_OV_BASE_TYPEID_FUNCTIONS_AND_DATA \
146 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(virtual)
147
148 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(VIRTUAL) \
149 public: \
150 VIRTUAL int type_id (void) const { return t_id; } \
151 VIRTUAL std::string type_name (void) const { return t_name; } \
152 VIRTUAL std::string class_name (void) const { return c_name; } \
153 static int static_type_id (void) { return t_id; } \
154 static std::string static_type_name (void) { return t_name; } \
155 static std::string static_class_name (void) { return c_name; } \
156 static void register_type (void); \
157 \
158 private: \
159 static int t_id; \
160 static const std::string t_name; \
161 static const std::string c_name;
162
163
164 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \
165 int t::t_id (-1); \
166 const std::string t::t_name (n); \
167 const std::string t::c_name (c); \
168 void t::register_type (void) \
169 { \
170 static t exemplar; \
171 octave_value v (&exemplar, true); \
172 t_id = octave_value_typeinfo::register_type (t::t_name, t::c_name, v); \
173 }
174
175 // A base value type, so that derived types only have to redefine what
176 // they need (if they are derived from octave_base_value instead of
177 // octave_value).
178
179 class
180 OCTINTERP_API
181 octave_base_value
182 {
183 public:
184
185 typedef octave_base_value * (*type_conv_fcn) (const octave_base_value&);
186
187 // type conversion, including result type information
188 class type_conv_info
189 {
190 public:
191 type_conv_info (type_conv_fcn f = 0, int t = -1) : _fcn (f), _type_id (t) { }
192
193 operator type_conv_fcn (void) const { return _fcn; }
194
195 octave_base_value * operator () (const octave_base_value &v) const
196 { return (*_fcn) (v); }
197
198 int type_id (void) const { return _type_id; }
199
200 private:
201 type_conv_fcn _fcn;
202 int _type_id;
203 };
204
205 friend class octave_value;
206
207 octave_base_value (void) : count (1) { }
208
209 octave_base_value (const octave_base_value&) : count (1) { }
210
211 virtual ~octave_base_value (void) { }
212
213 // Unconditional clone. Always clones.
214 virtual octave_base_value *
215 clone (void) const { return new octave_base_value (*this); }
216
217 // Empty clone.
218 virtual octave_base_value *
219 empty_clone (void) const;
220
221 // Unique clone. Usually clones, but may be overriden to fake the
222 // cloning when sharing copies is to be controlled from within an
223 // instance (see octave_class).
224 virtual octave_base_value *
225 unique_clone (void) { return clone (); }
226
227 virtual type_conv_info
228 numeric_conversion_function (void) const
229 { return type_conv_info (); }
230
231 virtual type_conv_info
232 numeric_demotion_function (void) const
233 { return type_conv_info (); }
234
235 virtual octave_value squeeze (void) const;
236
237 virtual octave_value full_value (void) const;
238
239 virtual octave_base_value *try_narrowing_conversion (void) { return 0; }
240
241 virtual void maybe_economize (void) { }
242
243 virtual Matrix size (void);
244
245 virtual octave_idx_type numel (const octave_value_list&);
246
247 virtual octave_value
248 subsref (const std::string& type,
249 const std::list<octave_value_list>& idx);
250
251 virtual octave_value_list
252 subsref (const std::string& type,
253 const std::list<octave_value_list>& idx,
254 int nargout);
255
256 virtual octave_value
257 subsref (const std::string& type,
258 const std::list<octave_value_list>& idx,
259 bool auto_add);
260
261 virtual octave_value_list
262 subsref (const std::string& type,
263 const std::list<octave_value_list>& idx,
264 int nargout,
265 const std::list<octave_lvalue> *lvalue_list);
266
267 virtual octave_value
268 do_index_op (const octave_value_list& idx, bool resize_ok = false);
269
270 virtual octave_value_list
271 do_multi_index_op (int nargout, const octave_value_list& idx);
272
273 virtual octave_value_list
274 do_multi_index_op (int nargout, const octave_value_list& idx,
275 const std::list<octave_lvalue> *lvalue_list);
276
277 virtual void assign (const std::string&, const octave_value&) { }
278
279 virtual octave_value
280 subsasgn (const std::string& type,
281 const std::list<octave_value_list>& idx,
282 const octave_value& rhs);
283
284 virtual octave_value
285 undef_subsasgn (const std::string& type,
286 const std::list<octave_value_list>& idx,
287 const octave_value& rhs);
288
289 virtual idx_vector index_vector (void) const;
290
291 virtual dim_vector dims (void) const { return dim_vector (); }
292
293 octave_idx_type rows (void) const
294 {
295 const dim_vector dv = dims ();
296
297 return dv(0);
298 }
299
300 octave_idx_type columns (void) const
301 {
302 const dim_vector dv = dims ();
303
304 return dv(1);
305 }
306
307 virtual int ndims (void) const
308 { return dims ().length (); }
309
310 virtual octave_idx_type numel (void) const { return dims ().numel (); }
311
312 virtual octave_idx_type capacity (void) const { return numel (); }
313
314 virtual size_t byte_size (void) const { return 0; }
315
316 virtual octave_idx_type nnz (void) const;
317
318 virtual octave_idx_type nzmax (void) const;
319
320 virtual octave_idx_type nfields (void) const;
321
322 virtual octave_value reshape (const dim_vector&) const;
323
324 virtual octave_value permute (const Array<int>& vec, bool = false) const;
325
326 virtual octave_value resize (const dim_vector&, bool fill = false) const;
327
328 virtual MatrixType matrix_type (void) const;
329
330 virtual MatrixType matrix_type (const MatrixType& typ) const;
331
332 virtual bool is_defined (void) const { return false; }
333
334 bool is_empty (void) const { return numel () == 0; }
335
336 virtual bool is_cell (void) const { return false; }
337
338 virtual bool is_cellstr (void) const { return false; }
339
340 virtual bool is_real_scalar (void) const { return false; }
341
342 virtual bool is_real_matrix (void) const { return false; }
343
344 virtual bool is_real_nd_array (void) const { return false; }
345
346 virtual bool is_complex_scalar (void) const { return false; }
347
348 virtual bool is_complex_matrix (void) const { return false; }
349
350 virtual bool is_bool_scalar (void) const { return false; }
351
352 virtual bool is_bool_matrix (void) const { return false; }
353
354 virtual bool is_char_matrix (void) const { return false; }
355
356 virtual bool is_diag_matrix (void) const { return false; }
357
358 virtual bool is_perm_matrix (void) const { return false; }
359
360 virtual bool is_string (void) const { return false; }
361
362 virtual bool is_sq_string (void) const { return false; }
363
364 virtual bool is_range (void) const { return false; }
365
366 virtual bool is_map (void) const { return false; }
367
368 virtual bool is_object (void) const { return false; }
369
370 virtual bool is_cs_list (void) const { return false; }
371
372 virtual bool is_magic_colon (void) const { return false; }
373
374 virtual bool is_all_va_args (void) const { return false; }
375
376 virtual octave_value all (int = 0) const;
377
378 virtual octave_value any (int = 0) const;
379
380 virtual builtin_type_t builtin_type (void) const { return btyp_unknown; }
381
382 virtual bool is_double_type (void) const { return false; }
383
384 virtual bool is_single_type (void) const { return false; }
385
386 virtual bool is_float_type (void) const { return false; }
387
388 virtual bool is_int8_type (void) const { return false; }
389
390 virtual bool is_int16_type (void) const { return false; }
391
392 virtual bool is_int32_type (void) const { return false; }
393
394 virtual bool is_int64_type (void) const { return false; }
395
396 virtual bool is_uint8_type (void) const { return false; }
397
398 virtual bool is_uint16_type (void) const { return false; }
399
400 virtual bool is_uint32_type (void) const { return false; }
401
402 virtual bool is_uint64_type (void) const { return false; }
403
404 virtual bool is_bool_type (void) const { return false; }
405
406 virtual bool is_integer_type (void) const { return false; }
407
408 virtual bool is_real_type (void) const { return false; }
409
410 virtual bool is_complex_type (void) const { return false; }
411
412 // Would be nice to get rid of the next four functions:
413
414 virtual bool is_scalar_type (void) const { return false; }
415
416 virtual bool is_matrix_type (void) const { return false; }
417
418 virtual bool is_numeric_type (void) const { return false; }
419
420 virtual bool is_sparse_type (void) const { return false; }
421
422 virtual bool is_true (void) const { return false; }
423
424 virtual bool is_null_value (void) const { return false; }
425
426 virtual bool is_constant (void) const { return false; }
427
428 virtual bool is_function_handle (void) const { return false; }
429
430 virtual bool is_anonymous_function (void) const { return false; }
431
432 virtual bool is_inline_function (void) const { return false; }
433
434 virtual bool is_function (void) const { return false; }
435
436 virtual bool is_user_script (void) const { return false; }
437
438 virtual bool is_user_function (void) const { return false; }
439
440 virtual bool is_user_code (void) const { return false; }
441
442 virtual bool is_builtin_function (void) const { return false; }
443
444 virtual bool is_dld_function (void) const { return false; }
445
446 virtual bool is_mex_function (void) const { return false; }
447
448 virtual void erase_subfunctions (void) { }
449
450 virtual short int short_value (bool = false, bool = false) const;
451
452 virtual unsigned short int ushort_value (bool = false, bool = false) const;
453
454 virtual int int_value (bool = false, bool = false) const;
455
456 virtual unsigned int uint_value (bool = false, bool = false) const;
457
458 virtual int nint_value (bool = false) const;
459
460 virtual long int long_value (bool = false, bool = false) const;
461
462 virtual unsigned long int ulong_value (bool = false, bool = false) const;
463
464 virtual double double_value (bool = false) const;
465
466 virtual float float_value (bool = false) const;
467
468 virtual double scalar_value (bool frc_str_conv = false) const
469 { return double_value (frc_str_conv); }
470
471 virtual float float_scalar_value (bool frc_str_conv = false) const
472 { return float_value (frc_str_conv); }
473
474 virtual Cell cell_value (void) const;
475
476 virtual Matrix matrix_value (bool = false) const;
477
478 virtual FloatMatrix float_matrix_value (bool = false) const;
479
480 virtual NDArray array_value (bool = false) const;
481
482 virtual FloatNDArray float_array_value (bool = false) const;
483
484 virtual Complex complex_value (bool = false) const;
485
486 virtual FloatComplex float_complex_value (bool = false) const;
487
488 virtual ComplexMatrix complex_matrix_value (bool = false) const;
489
490 virtual FloatComplexMatrix float_complex_matrix_value (bool = false) const;
491
492 virtual ComplexNDArray complex_array_value (bool = false) const;
493
494 virtual FloatComplexNDArray float_complex_array_value (bool = false) const;
495
496 virtual bool bool_value (bool = false) const;
497
498 virtual boolMatrix bool_matrix_value (bool = false) const;
499
500 virtual boolNDArray bool_array_value (bool = false) const;
501
502 virtual charMatrix char_matrix_value (bool force = false) const;
503
504 virtual charNDArray char_array_value (bool = false) const;
505
506 virtual SparseMatrix sparse_matrix_value (bool = false) const;
507
508 virtual SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
509
510 virtual SparseBoolMatrix sparse_bool_matrix_value (bool = false) const;
511
512 virtual DiagMatrix diag_matrix_value (bool = false) const;
513
514 virtual FloatDiagMatrix float_diag_matrix_value (bool = false) const;
515
516 virtual ComplexDiagMatrix complex_diag_matrix_value (bool = false) const;
517
518 virtual FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const;
519
520 virtual PermMatrix perm_matrix_value (void) const;
521
522 virtual octave_int8 int8_scalar_value (void) const;
523
524 virtual octave_int16 int16_scalar_value (void) const;
525
526 virtual octave_int32 int32_scalar_value (void) const;
527
528 virtual octave_int64 int64_scalar_value (void) const;
529
530 virtual octave_uint8 uint8_scalar_value (void) const;
531
532 virtual octave_uint16 uint16_scalar_value (void) const;
533
534 virtual octave_uint32 uint32_scalar_value (void) const;
535
536 virtual octave_uint64 uint64_scalar_value (void) const;
537
538 virtual int8NDArray int8_array_value (void) const;
539
540 virtual int16NDArray int16_array_value (void) const;
541
542 virtual int32NDArray int32_array_value (void) const;
543
544 virtual int64NDArray int64_array_value (void) const;
545
546 virtual uint8NDArray uint8_array_value (void) const;
547
548 virtual uint16NDArray uint16_array_value (void) const;
549
550 virtual uint32NDArray uint32_array_value (void) const;
551
552 virtual uint64NDArray uint64_array_value (void) const;
553
554 virtual string_vector all_strings (bool pad = false) const;
555
556 virtual std::string string_value (bool force = false) const;
557
558 virtual Array<std::string> cellstr_value (void) const;
559
560 virtual Range range_value (void) const;
561
562 virtual octave_map map_value (void) const;
563
564 virtual octave_scalar_map scalar_map_value (void) const;
565
566 virtual string_vector map_keys (void) const;
567
568 virtual size_t nparents (void) const;
569
570 virtual std::list<std::string> parent_class_name_list (void) const;
571
572 virtual string_vector parent_class_names (void) const;
573
574 virtual octave_base_value *find_parent_class (const std::string&)
575 { return 0; }
576
577 virtual octave_base_value *unique_parent_class (const std::string&)
578 { return 0; }
579
580 virtual octave_function *function_value (bool silent = false);
581
582 virtual octave_user_function *user_function_value (bool silent = false);
583
584 virtual octave_user_script *user_script_value (bool silent = false);
585
586 virtual octave_user_code *user_code_value (bool silent = false);
587
588 virtual octave_fcn_handle *fcn_handle_value (bool silent = false);
589
590 virtual octave_fcn_inline *fcn_inline_value (bool silent = false);
591
592 virtual octave_value_list list_value (void) const;
593
594 virtual octave_value convert_to_str (bool pad = false, bool force = false,
595 char type = '\'') const;
596 virtual octave_value
597 convert_to_str_internal (bool pad, bool force, char type) const;
598
599 virtual void convert_to_row_or_column_vector (void);
600
601 virtual bool print_as_scalar (void) const { return false; }
602
603 virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const;
604
605 virtual void
606 print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
607
608 virtual bool
609 print_name_tag (std::ostream& os, const std::string& name) const;
610
611 virtual void
612 print_with_name (std::ostream& output_buf, const std::string& name,
613 bool print_padding = true);
614
615 virtual void print_info (std::ostream& os, const std::string& prefix) const;
616
617 virtual bool save_ascii (std::ostream& os);
618
619 virtual bool load_ascii (std::istream& is);
620
621 virtual bool save_binary (std::ostream& os, bool& save_as_floats);
622
623 virtual bool load_binary (std::istream& is, bool swap,
624 oct_mach_info::float_format fmt);
625
626 #if defined (HAVE_HDF5)
627 virtual bool
628 save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
629
630 virtual bool
631 load_hdf5 (hid_t loc_id, const char *name);
632 #endif
633
634 virtual int
635 write (octave_stream& os, int block_size,
636 oct_data_conv::data_type output_type, int skip,
637 oct_mach_info::float_format flt_fmt) const;
638
639 virtual void *mex_get_data (void) const { return 0; }
640
641 virtual octave_idx_type *mex_get_ir (void) const { return 0; }
642
643 virtual octave_idx_type *mex_get_jc (void) const { return 0; }
644
645 virtual mxArray *as_mxArray (void) const;
646
647 virtual octave_value diag (octave_idx_type k = 0) const;
648
649 virtual octave_value diag (octave_idx_type m, octave_idx_type n) const;
650
651 virtual octave_value sort (octave_idx_type dim = 0,
652 sortmode mode = ASCENDING) const;
653 virtual octave_value sort (Array<octave_idx_type> &sidx,
654 octave_idx_type dim = 0,
655 sortmode mode = ASCENDING) const;
656
657 virtual sortmode is_sorted (sortmode mode = UNSORTED) const;
658
659 virtual Array<octave_idx_type>
660 sort_rows_idx (sortmode mode = ASCENDING) const;
661
662 virtual sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
663
664 virtual void lock (void);
665
666 virtual void unlock (void);
667
668 virtual bool islocked (void) const { return false; }
669
670 virtual void dump (std::ostream& os) const;
671
672 // Standard mappers. Register new ones here.
673 enum unary_mapper_t
674 {
675 umap_abs,
676 umap_acos,
677 umap_acosh,
678 umap_angle,
679 umap_arg,
680 umap_asin,
681 umap_asinh,
682 umap_atan,
683 umap_atanh,
684 umap_cbrt,
685 umap_ceil,
686 umap_conj,
687 umap_cos,
688 umap_cosh,
689 umap_erf,
690 umap_erfinv,
691 umap_erfcinv,
692 umap_erfc,
693 umap_erfcx,
694 umap_exp,
695 umap_expm1,
696 umap_finite,
697 umap_fix,
698 umap_floor,
699 umap_gamma,
700 umap_imag,
701 umap_isinf,
702 umap_isna,
703 umap_isnan,
704 umap_lgamma,
705 umap_log,
706 umap_log2,
707 umap_log10,
708 umap_log1p,
709 umap_real,
710 umap_round,
711 umap_roundb,
712 umap_signum,
713 umap_sin,
714 umap_sinh,
715 umap_sqrt,
716 umap_tan,
717 umap_tanh,
718 umap_xisalnum,
719 umap_xisalpha,
720 umap_xisascii,
721 umap_xiscntrl,
722 umap_xisdigit,
723 umap_xisgraph,
724 umap_xislower,
725 umap_xisprint,
726 umap_xispunct,
727 umap_xisspace,
728 umap_xisupper,
729 umap_xisxdigit,
730 umap_xtoascii,
731 umap_xtolower,
732 umap_xtoupper,
733 umap_unknown,
734 num_unary_mappers = umap_unknown
735 };
736
737 virtual octave_value map (unary_mapper_t) const;
738
739 // These are fast indexing & assignment shortcuts for extracting
740 // or inserting a single scalar from/to an array.
741
742 // Extract the n-th element, aka val(n). Result is undefined if val is not an
743 // array type or n is out of range. Never error.
744 virtual octave_value
745 fast_elem_extract (octave_idx_type n) const;
746
747 // Assign the n-th element, aka val(n) = x. Returns false if val is not an
748 // array type, x is not a matching scalar type, or n is out of range.
749 // Never error.
750 virtual bool
751 fast_elem_insert (octave_idx_type n, const octave_value& x);
752
753 // This is a helper for the above, to be overriden in scalar types. The
754 // whole point is to handle the insertion efficiently with just *two* VM
755 // calls, which is basically the theoretical minimum.
756 virtual bool
757 fast_elem_insert_self (void *where, builtin_type_t btyp) const;
758
759 // Grab the reference count. For use by jit.
760 void
761 grab (void)
762 {
763 ++count;
764 }
765
766 // Release the reference count. For use by jit.
767 void
768 release (void)
769 {
770 if (--count == 0)
771 delete this;
772 }
773
774 protected:
775
776 // This should only be called for derived types.
777
778 octave_value numeric_assign (const std::string& type,
779 const std::list<octave_value_list>& idx,
780 const octave_value& rhs);
781
782 void reset_indent_level (void) const
783 { curr_print_indent_level = 0; }
784
785 void increment_indent_level (void) const
786 { curr_print_indent_level += 2; }
787
788 void decrement_indent_level (void) const
789 { curr_print_indent_level -= 2; }
790
791 int current_print_indent_level (void) const
792 { return curr_print_indent_level; }
793
794 void indent (std::ostream& os) const;
795
796 void newline (std::ostream& os) const;
797
798 void reset (void) const;
799
800 // A reference count.
801 // NOTE: the declaration is octave_idx_type because with 64-bit indexing,
802 // it is well possible to have more than MAX_INT copies of a single value
803 // (think of an empty cell array with >2G elements).
804 octave_refcount<octave_idx_type> count;
805
806 private:
807
808 static const char *get_umap_name (unary_mapper_t);
809
810 static int curr_print_indent_level;
811 static bool beginning_of_line;
812
813 DECLARE_OV_BASE_TYPEID_FUNCTIONS_AND_DATA
814 };
815
816 // TRUE means to perform automatic sparse to real mutation if there
817 // is memory to be saved
818 extern OCTINTERP_API bool Vsparse_auto_mutate;
819
820 #endif