Mercurial > hg > octave-lyh
annotate src/ov-base.h @ 7489:8e4592e49fa7
don't clear locked functions
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 18 Feb 2008 14:54:10 -0500 |
parents | 2467639bd8c0 |
children | 8c32f95c2639 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
4 2006, 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 #if !defined (octave_base_value_h) | |
25 #define octave_base_value_h 1 | |
26 | |
27 #include <cstdlib> | |
28 | |
3503 | 29 #include <iostream> |
5759 | 30 #include <list> |
2376 | 31 #include <string> |
32 | |
5759 | 33 #if defined (HAVE_HDF5) |
34 #include <hdf5.h> | |
35 #endif | |
36 | |
37 #include "Range.h" | |
5828 | 38 #include "data-conv.h" |
5900 | 39 #include "mxarray.h" |
2376 | 40 #include "mx-base.h" |
41 #include "str-vec.h" | |
42 | |
43 #include "error.h" | |
44 | |
3351 | 45 class Cell; |
5759 | 46 class streamoff_array; |
2376 | 47 class Octave_map; |
5759 | 48 class octave_value; |
2376 | 49 class octave_value_list; |
5759 | 50 class octave_stream; |
51 class octave_streamoff; | |
52 class octave_function; | |
53 class octave_user_function; | |
54 class octave_fcn_handle; | |
55 class octave_fcn_inline; | |
56 class octave_value_list; | |
57 class octave_lvalue; | |
2376 | 58 |
59 class tree_walker; | |
60 | |
5759 | 61 // T_ID is the type id of struct objects, set by register_type(). |
62 // T_NAME is the type name of struct objects. | |
7067 | 63 |
5759 | 64 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \ |
7066 | 65 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2 (OCTAVE_EMPTY_CPP_ARG) |
5759 | 66 |
67 #define DECLARE_OV_BASE_TYPEID_FUNCTIONS_AND_DATA \ | |
68 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(virtual) | |
69 | |
70 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(VIRTUAL) \ | |
71 public: \ | |
72 VIRTUAL int type_id (void) const { return t_id; } \ | |
73 VIRTUAL std::string type_name (void) const { return t_name; } \ | |
74 VIRTUAL std::string class_name (void) const { return c_name; } \ | |
75 static int static_type_id (void) { return t_id; } \ | |
76 static std::string static_type_name (void) { return t_name; } \ | |
77 static std::string static_class_name (void) { return c_name; } \ | |
78 static void register_type (void); \ | |
79 \ | |
80 private: \ | |
81 static int t_id; \ | |
82 static const std::string t_name; \ | |
83 static const std::string c_name; | |
84 | |
85 | |
86 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \ | |
87 int t::t_id (-1); \ | |
88 const std::string t::t_name (n); \ | |
89 const std::string t::c_name (c); \ | |
90 void t::register_type (void) \ | |
91 { \ | |
92 t_id = octave_value_typeinfo::register_type (t::t_name, \ | |
93 t::c_name, \ | |
94 octave_value (new t ())); \ | |
95 } | |
96 | |
2477 | 97 // A base value type, so that derived types only have to redefine what |
98 // they need (if they are derived from octave_base_value instead of | |
99 // octave_value). | |
2376 | 100 |
101 class | |
6109 | 102 OCTINTERP_API |
5759 | 103 octave_base_value |
2376 | 104 { |
105 public: | |
106 | |
5759 | 107 typedef octave_base_value * (*type_conv_fcn) (const octave_base_value&); |
108 | |
109 friend class octave_value; | |
2376 | 110 |
5759 | 111 octave_base_value (void) : count (1) { } |
112 | |
113 octave_base_value (const octave_base_value&) { } | |
2376 | 114 |
5759 | 115 virtual ~octave_base_value (void) { } |
116 | |
117 virtual octave_base_value * | |
118 clone (void) const { return new octave_base_value (*this); } | |
2376 | 119 |
5759 | 120 virtual octave_base_value * |
121 empty_clone (void) const { return new octave_base_value (); } | |
2376 | 122 |
5759 | 123 virtual type_conv_fcn |
124 numeric_conversion_function (void) const | |
2800 | 125 { return static_cast<type_conv_fcn> (0); } |
2410 | 126 |
5759 | 127 virtual octave_value squeeze (void) const; |
128 | |
129 virtual octave_base_value *try_narrowing_conversion (void) { return 0; } | |
4532 | 130 |
5759 | 131 virtual octave_value |
132 subsref (const std::string& type, | |
133 const std::list<octave_value_list>& idx); | |
3933 | 134 |
5759 | 135 virtual octave_value_list |
136 subsref (const std::string& type, | |
137 const std::list<octave_value_list>& idx, | |
138 int nargout); | |
3933 | 139 |
5759 | 140 virtual octave_value |
5885 | 141 do_index_op (const octave_value_list& idx, bool resize_ok = false); |
2974 | 142 |
5759 | 143 virtual octave_value_list |
3544 | 144 do_multi_index_op (int nargout, const octave_value_list& idx); |
2376 | 145 |
5759 | 146 virtual octave_value |
147 subsasgn (const std::string& type, | |
148 const std::list<octave_value_list>& idx, | |
149 const octave_value& rhs); | |
2376 | 150 |
5759 | 151 virtual idx_vector index_vector (void) const; |
2376 | 152 |
5759 | 153 virtual dim_vector dims (void) const { return dim_vector (-1, -1); } |
4559 | 154 |
5759 | 155 octave_idx_type rows (void) const |
156 { | |
157 dim_vector dv = dims (); | |
5164 | 158 |
5759 | 159 return (dv.length () > 0) ? dv(0) : -1; |
160 } | |
4791 | 161 |
5759 | 162 octave_idx_type columns (void) const |
163 { | |
164 dim_vector dv = dims (); | |
5602 | 165 |
5759 | 166 return (dv.length () > 1) ? dv(1) : -1; |
167 } | |
5604 | 168 |
5759 | 169 virtual int ndims (void) const; |
4567 | 170 |
5759 | 171 virtual octave_idx_type numel (void) const { return dims ().numel (); } |
4593 | 172 |
5759 | 173 virtual octave_idx_type capacity (void) const { return numel (); } |
174 | |
175 virtual size_t byte_size (void) const { return 0; } | |
4915 | 176 |
5759 | 177 virtual octave_idx_type nnz (void) const; |
2376 | 178 |
5759 | 179 virtual octave_idx_type nzmax (void) const; |
180 | |
5900 | 181 virtual octave_idx_type nfields (void) const; |
182 | |
5759 | 183 virtual octave_value reshape (const dim_vector&) const; |
3351 | 184 |
5759 | 185 virtual octave_value permute (const Array<int>& vec, bool = false) const; |
2376 | 186 |
5759 | 187 virtual octave_value resize (const dim_vector&, bool fill = false) const; |
2376 | 188 |
5785 | 189 virtual MatrixType matrix_type (void) const; |
190 | |
191 virtual MatrixType matrix_type (const MatrixType& typ) const; | |
192 | |
5759 | 193 virtual bool is_defined (void) const { return false; } |
4505 | 194 |
5759 | 195 bool is_empty (void) const { return numel () == 0; } |
2376 | 196 |
5759 | 197 virtual bool is_cell (void) const { return false; } |
2376 | 198 |
6116 | 199 virtual bool is_cellstr (void) const { return false; } |
200 | |
5759 | 201 virtual bool is_real_scalar (void) const { return false; } |
4587 | 202 |
5759 | 203 virtual bool is_real_matrix (void) const { return false; } |
204 | |
205 virtual bool is_real_nd_array (void) const { return false; } | |
2376 | 206 |
5759 | 207 virtual bool is_complex_scalar (void) const { return false; } |
2376 | 208 |
5759 | 209 virtual bool is_complex_matrix (void) const { return false; } |
210 | |
5881 | 211 virtual bool is_bool_scalar (void) const { return false; } |
212 | |
5759 | 213 virtual bool is_bool_matrix (void) const { return false; } |
5279 | 214 |
5759 | 215 virtual bool is_char_matrix (void) const { return false; } |
2376 | 216 |
5759 | 217 virtual bool is_string (void) const { return false; } |
2376 | 218 |
5759 | 219 virtual bool is_sq_string (void) const { return false; } |
4643 | 220 |
5759 | 221 virtual bool is_range (void) const { return false; } |
3977 | 222 |
5759 | 223 virtual bool is_map (void) const { return false; } |
224 | |
7336 | 225 virtual bool is_object (void) const { return false; } |
226 | |
5759 | 227 virtual bool is_streamoff (void) const { return false; } |
2882 | 228 |
5759 | 229 virtual bool is_cs_list (void) const { return false; } |
2376 | 230 |
5759 | 231 virtual bool is_list (void) const { return false; } |
232 | |
233 virtual bool is_magic_colon (void) const { return false; } | |
2376 | 234 |
5759 | 235 virtual bool is_all_va_args (void) const { return false; } |
2376 | 236 |
5759 | 237 virtual octave_value all (int = 0) const; |
238 | |
239 virtual octave_value any (int = 0) const; | |
2376 | 240 |
5895 | 241 virtual bool is_double_type (void) const { return false; } |
242 | |
243 virtual bool is_single_type (void) const { return false; } | |
244 | |
245 virtual bool is_int8_type (void) const { return false; } | |
246 | |
247 virtual bool is_int16_type (void) const { return false; } | |
248 | |
249 virtual bool is_int32_type (void) const { return false; } | |
250 | |
251 virtual bool is_int64_type (void) const { return false; } | |
252 | |
253 virtual bool is_uint8_type (void) const { return false; } | |
254 | |
255 virtual bool is_uint16_type (void) const { return false; } | |
256 | |
257 virtual bool is_uint32_type (void) const { return false; } | |
258 | |
259 virtual bool is_uint64_type (void) const { return false; } | |
260 | |
5759 | 261 virtual bool is_bool_type (void) const { return false; } |
3209 | 262 |
6223 | 263 virtual bool is_integer_type (void) const { return false; } |
264 | |
5759 | 265 virtual bool is_real_type (void) const { return false; } |
2376 | 266 |
5759 | 267 virtual bool is_complex_type (void) const { return false; } |
2376 | 268 |
269 // Would be nice to get rid of the next four functions: | |
270 | |
5759 | 271 virtual bool is_scalar_type (void) const { return false; } |
2376 | 272 |
5759 | 273 virtual bool is_matrix_type (void) const { return false; } |
2376 | 274 |
5759 | 275 virtual bool is_numeric_type (void) const { return false; } |
2376 | 276 |
5759 | 277 virtual bool is_sparse_type (void) const { return false; } |
5631 | 278 |
5759 | 279 virtual bool valid_as_scalar_index (void) const { return false; } |
2376 | 280 |
5759 | 281 virtual bool valid_as_zero_index (void) const { return false; } |
2376 | 282 |
5759 | 283 virtual bool is_true (void) const { return false; } |
284 | |
285 virtual bool is_constant (void) const { return false; } | |
2376 | 286 |
5759 | 287 virtual bool is_function_handle (void) const { return false; } |
2376 | 288 |
5759 | 289 virtual bool is_inline_function (void) const { return false; } |
2974 | 290 |
5759 | 291 virtual bool is_function (void) const { return false; } |
4954 | 292 |
7336 | 293 virtual bool is_user_script (void) const { return false; } |
294 | |
295 virtual bool is_user_function (void) const { return false; } | |
296 | |
5759 | 297 virtual bool is_builtin_function (void) const { return false; } |
2974 | 298 |
5759 | 299 virtual bool is_dld_function (void) const { return false; } |
3325 | 300 |
5864 | 301 virtual bool is_mex_function (void) const { return false; } |
302 | |
5759 | 303 virtual short int short_value (bool = false, bool = false) const; |
4254 | 304 |
5759 | 305 virtual unsigned short int ushort_value (bool = false, bool = false) const; |
4254 | 306 |
5759 | 307 virtual int int_value (bool = false, bool = false) const; |
3202 | 308 |
5759 | 309 virtual unsigned int uint_value (bool = false, bool = false) const; |
4254 | 310 |
5759 | 311 virtual int nint_value (bool = false) const; |
3202 | 312 |
5759 | 313 virtual long int long_value (bool = false, bool = false) const; |
4254 | 314 |
5759 | 315 virtual unsigned long int ulong_value (bool = false, bool = false) const; |
4254 | 316 |
5759 | 317 virtual double double_value (bool = false) const; |
2376 | 318 |
5759 | 319 virtual double scalar_value (bool frc_str_conv = false) const |
3145 | 320 { return double_value (frc_str_conv); } |
2376 | 321 |
5759 | 322 virtual Cell cell_value (void) const; |
3351 | 323 |
5759 | 324 virtual Matrix matrix_value (bool = false) const; |
3145 | 325 |
5759 | 326 virtual NDArray array_value (bool = false) const; |
4505 | 327 |
5759 | 328 virtual Complex complex_value (bool = false) const; |
2376 | 329 |
5759 | 330 virtual ComplexMatrix complex_matrix_value (bool = false) const; |
2376 | 331 |
5759 | 332 virtual ComplexNDArray complex_array_value (bool = false) const; |
4550 | 333 |
5943 | 334 virtual bool bool_value (bool = false) const; |
4550 | 335 |
5943 | 336 virtual boolMatrix bool_matrix_value (bool = false) const; |
4550 | 337 |
5943 | 338 virtual boolNDArray bool_array_value (bool = false) const; |
4550 | 339 |
5759 | 340 virtual charMatrix char_matrix_value (bool force = false) const; |
341 | |
342 virtual charNDArray char_array_value (bool = false) const; | |
2376 | 343 |
5759 | 344 virtual SparseMatrix sparse_matrix_value (bool = false) const; |
4550 | 345 |
5759 | 346 virtual SparseComplexMatrix sparse_complex_matrix_value (bool = false) const; |
5164 | 347 |
5759 | 348 virtual SparseBoolMatrix sparse_bool_matrix_value (bool = false) const; |
5164 | 349 |
5759 | 350 virtual octave_int8 int8_scalar_value (void) const; |
5164 | 351 |
5759 | 352 virtual octave_int16 int16_scalar_value (void) const; |
4910 | 353 |
5759 | 354 virtual octave_int32 int32_scalar_value (void) const; |
355 | |
356 virtual octave_int64 int64_scalar_value (void) const; | |
4910 | 357 |
5759 | 358 virtual octave_uint8 uint8_scalar_value (void) const; |
4910 | 359 |
5759 | 360 virtual octave_uint16 uint16_scalar_value (void) const; |
4910 | 361 |
5759 | 362 virtual octave_uint32 uint32_scalar_value (void) const; |
4910 | 363 |
5759 | 364 virtual octave_uint64 uint64_scalar_value (void) const; |
4910 | 365 |
5759 | 366 virtual int8NDArray int8_array_value (void) const; |
4910 | 367 |
5759 | 368 virtual int16NDArray int16_array_value (void) const; |
4910 | 369 |
5759 | 370 virtual int32NDArray int32_array_value (void) const; |
4906 | 371 |
5759 | 372 virtual int64NDArray int64_array_value (void) const; |
4906 | 373 |
5759 | 374 virtual uint8NDArray uint8_array_value (void) const; |
4906 | 375 |
5759 | 376 virtual uint16NDArray uint16_array_value (void) const; |
4906 | 377 |
5759 | 378 virtual uint32NDArray uint32_array_value (void) const; |
4906 | 379 |
5759 | 380 virtual uint64NDArray uint64_array_value (void) const; |
4906 | 381 |
5759 | 382 virtual string_vector all_strings (bool pad = false) const; |
4906 | 383 |
5759 | 384 virtual std::string string_value (bool force = false) const; |
4906 | 385 |
5759 | 386 virtual Range range_value (void) const; |
2376 | 387 |
5759 | 388 virtual Octave_map map_value (void) const; |
2376 | 389 |
5759 | 390 virtual string_vector map_keys (void) const; |
2376 | 391 |
5759 | 392 virtual std::streamoff streamoff_value (void) const; |
2376 | 393 |
5759 | 394 virtual streamoff_array streamoff_array_value (void) const; |
395 | |
396 virtual octave_function *function_value (bool silent = false); | |
3933 | 397 |
5759 | 398 virtual octave_user_function *user_function_value (bool silent = false); |
4645 | 399 |
5759 | 400 virtual octave_fcn_handle *fcn_handle_value (bool silent = false); |
4643 | 401 |
5759 | 402 virtual octave_fcn_inline *fcn_inline_value (bool silent = false); |
2974 | 403 |
5759 | 404 virtual octave_value_list list_value (void) const; |
4343 | 405 |
5759 | 406 virtual octave_value convert_to_str (bool pad = false, bool force = false, |
407 char type = '"') const; | |
408 virtual octave_value | |
409 convert_to_str_internal (bool pad, bool force, char type) const; | |
4933 | 410 |
5759 | 411 virtual void convert_to_row_or_column_vector (void); |
2882 | 412 |
5759 | 413 virtual bool print_as_scalar (void) const { return false; } |
2376 | 414 |
5759 | 415 virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2376 | 416 |
5759 | 417 virtual void |
418 print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; | |
4604 | 419 |
5759 | 420 virtual bool |
421 print_name_tag (std::ostream& os, const std::string& name) const; | |
2901 | 422 |
5759 | 423 virtual void |
424 print_with_name (std::ostream& output_buf, const std::string& name, | |
425 bool print_padding = true) const; | |
2376 | 426 |
5759 | 427 virtual void print_info (std::ostream& os, const std::string& prefix) const; |
3933 | 428 |
6974 | 429 virtual bool save_ascii (std::ostream& os); |
4687 | 430 |
5759 | 431 virtual bool load_ascii (std::istream& is); |
4687 | 432 |
5759 | 433 virtual bool save_binary (std::ostream& os, bool& save_as_floats); |
4687 | 434 |
5759 | 435 virtual bool load_binary (std::istream& is, bool swap, |
436 oct_mach_info::float_format fmt); | |
4687 | 437 |
438 #if defined (HAVE_HDF5) | |
5759 | 439 virtual bool |
440 save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
4687 | 441 |
5759 | 442 virtual bool |
443 load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); | |
4687 | 444 #endif |
445 | |
5759 | 446 virtual int |
447 write (octave_stream& os, int block_size, | |
448 oct_data_conv::data_type output_type, int skip, | |
449 oct_mach_info::float_format flt_fmt) const; | |
450 | |
5900 | 451 virtual void *mex_get_data (void) const { return 0; } |
452 | |
453 virtual octave_idx_type *mex_get_ir (void) const { return 0; } | |
454 | |
455 virtual octave_idx_type *mex_get_jc (void) const { return 0; } | |
456 | |
457 virtual mxArray *as_mxArray (void) const; | |
458 | |
7433 | 459 virtual octave_value sort (octave_idx_type dim = 0, |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
460 sortmode mode = ASCENDING) const; |
7433 | 461 virtual octave_value sort (Array<octave_idx_type> &sidx, |
462 octave_idx_type dim = 0, | |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
463 sortmode mode = ASCENDING) const; |
7433 | 464 |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7463
diff
changeset
|
465 virtual void lock (void); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7463
diff
changeset
|
466 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7463
diff
changeset
|
467 virtual void unlock (void); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7463
diff
changeset
|
468 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7463
diff
changeset
|
469 virtual bool islocked (void) const { return false; } |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7463
diff
changeset
|
470 |
5759 | 471 protected: |
472 | |
473 // This should only be called for derived types. | |
474 | |
475 octave_value numeric_assign (const std::string& type, | |
476 const std::list<octave_value_list>& idx, | |
477 const octave_value& rhs); | |
478 | |
479 void reset_indent_level (void) const | |
480 { curr_print_indent_level = 0; } | |
481 | |
482 void increment_indent_level (void) const | |
483 { curr_print_indent_level += 2; } | |
484 | |
485 void decrement_indent_level (void) const | |
486 { curr_print_indent_level -= 2; } | |
487 | |
488 int current_print_indent_level (void) const | |
489 { return curr_print_indent_level; } | |
490 | |
491 void indent (std::ostream& os) const; | |
492 | |
493 void newline (std::ostream& os) const; | |
494 | |
495 void reset (void) const; | |
496 | |
497 // A reference count. | |
498 int count; | |
4944 | 499 |
2376 | 500 private: |
501 | |
5759 | 502 static int curr_print_indent_level; |
503 static bool beginning_of_line; | |
504 | |
505 DECLARE_OV_BASE_TYPEID_FUNCTIONS_AND_DATA | |
2376 | 506 }; |
507 | |
7336 | 508 // If TRUE, turn off printing of results in functions (as if a |
509 // semicolon has been appended to each statement). | |
510 extern bool Vsilent_functions; | |
511 | |
7193 | 512 // TRUE means to perform automatic sparse to real mutation if there |
513 // is memory to be saved | |
514 extern bool Vsparse_auto_mutate; | |
515 | |
2376 | 516 #endif |
517 | |
518 /* | |
519 ;;; Local Variables: *** | |
520 ;;; mode: C++ *** | |
521 ;;; End: *** | |
522 */ |