00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_base_value_h)
00025 #define octave_base_value_h 1
00026
00027 #include <cstdlib>
00028
00029 #include <iosfwd>
00030 #include <list>
00031 #include <string>
00032
00033 #include "Range.h"
00034 #include "data-conv.h"
00035 #include "mxarray.h"
00036 #include "mx-base.h"
00037 #include "str-vec.h"
00038
00039 #include "error.h"
00040 #include "oct-hdf5.h"
00041
00042 class Cell;
00043 class Octave_map;
00044 class octave_value;
00045 class octave_value_list;
00046 class octave_stream;
00047 class octave_function;
00048 class octave_user_function;
00049 class octave_user_script;
00050 class octave_user_code;
00051 class octave_fcn_handle;
00052 class octave_fcn_inline;
00053 class octave_value_list;
00054 class octave_lvalue;
00055
00056 class tree_walker;
00057
00058 enum builtin_type_t
00059 {
00060 btyp_double,
00061 btyp_float,
00062 btyp_complex,
00063 btyp_float_complex,
00064 btyp_int8,
00065 btyp_int16,
00066 btyp_int32,
00067 btyp_int64,
00068 btyp_uint8,
00069 btyp_uint16,
00070 btyp_uint32,
00071 btyp_uint64,
00072 btyp_char,
00073 btyp_bool,
00074 btyp_unknown
00075 };
00076
00077 template <class T>
00078 struct class_to_btyp
00079 {
00080 static const builtin_type_t btyp = btyp_unknown;
00081 };
00082
00083 #define DEF_CLASS_TO_BTYP(CLASS,BTYP) \
00084 template <> \
00085 struct class_to_btyp<CLASS> \
00086 { static const builtin_type_t btyp = BTYP; }
00087
00088 DEF_CLASS_TO_BTYP (double, btyp_double);
00089 DEF_CLASS_TO_BTYP (float, btyp_float);
00090 DEF_CLASS_TO_BTYP (Complex, btyp_complex);
00091 DEF_CLASS_TO_BTYP (FloatComplex, btyp_float_complex);
00092 DEF_CLASS_TO_BTYP (octave_int8, btyp_int8);
00093 DEF_CLASS_TO_BTYP (octave_int16, btyp_int16);
00094 DEF_CLASS_TO_BTYP (octave_int32, btyp_int32);
00095 DEF_CLASS_TO_BTYP (octave_int64, btyp_int64);
00096 DEF_CLASS_TO_BTYP (octave_uint8, btyp_uint8);
00097 DEF_CLASS_TO_BTYP (octave_uint16, btyp_uint16);
00098 DEF_CLASS_TO_BTYP (octave_uint32, btyp_uint32);
00099 DEF_CLASS_TO_BTYP (octave_uint64, btyp_uint64);
00100 DEF_CLASS_TO_BTYP (bool, btyp_bool);
00101 DEF_CLASS_TO_BTYP (char, btyp_char);
00102
00103
00104
00105
00106 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \
00107 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2 (OCTAVE_EMPTY_CPP_ARG)
00108
00109 #define DECLARE_OV_BASE_TYPEID_FUNCTIONS_AND_DATA \
00110 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(virtual)
00111
00112 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(VIRTUAL) \
00113 public: \
00114 VIRTUAL int type_id (void) const { return t_id; } \
00115 VIRTUAL std::string type_name (void) const { return t_name; } \
00116 VIRTUAL std::string class_name (void) const { return c_name; } \
00117 static int static_type_id (void) { return t_id; } \
00118 static std::string static_type_name (void) { return t_name; } \
00119 static std::string static_class_name (void) { return c_name; } \
00120 static void register_type (void); \
00121 \
00122 private: \
00123 static int t_id; \
00124 static const std::string t_name; \
00125 static const std::string c_name;
00126
00127
00128 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \
00129 int t::t_id (-1); \
00130 const std::string t::t_name (n); \
00131 const std::string t::c_name (c); \
00132 void t::register_type (void) \
00133 { \
00134 t_id = octave_value_typeinfo::register_type (t::t_name, \
00135 t::c_name, \
00136 octave_value (new t ())); \
00137 }
00138
00139
00140
00141
00142
00143 class
00144 OCTINTERP_API
00145 octave_base_value
00146 {
00147 public:
00148
00149 typedef octave_base_value * (*type_conv_fcn) (const octave_base_value&);
00150
00151
00152 class type_conv_info
00153 {
00154 public:
00155 type_conv_info (type_conv_fcn f = 0, int t = -1) : _fcn (f), _type_id (t) { }
00156
00157 operator type_conv_fcn (void) const { return _fcn; }
00158
00159 octave_base_value * operator () (const octave_base_value &v) const
00160 { return (*_fcn) (v); }
00161
00162 int type_id (void) const { return _type_id; }
00163
00164 private:
00165 type_conv_fcn _fcn;
00166 int _type_id;
00167 };
00168
00169 friend class octave_value;
00170
00171 octave_base_value (void) : count (1) { }
00172
00173 octave_base_value (const octave_base_value&) : count (1) { }
00174
00175 virtual ~octave_base_value (void) { }
00176
00177
00178 virtual octave_base_value *
00179 clone (void) const { return new octave_base_value (*this); }
00180
00181
00182 virtual octave_base_value *
00183 empty_clone (void) const { return new octave_base_value (); }
00184
00185
00186
00187
00188 virtual octave_base_value *
00189 unique_clone (void) { return clone (); }
00190
00191 virtual type_conv_info
00192 numeric_conversion_function (void) const
00193 { return type_conv_info (); }
00194
00195 virtual type_conv_info
00196 numeric_demotion_function (void) const
00197 { return type_conv_info (); }
00198
00199 virtual octave_value squeeze (void) const;
00200
00201 virtual octave_value full_value (void) const;
00202
00203 virtual octave_base_value *try_narrowing_conversion (void) { return 0; }
00204
00205 virtual void maybe_economize (void) { }
00206
00207 virtual Matrix size (void);
00208
00209 virtual octave_idx_type numel (const octave_value_list&);
00210
00211 virtual octave_value
00212 subsref (const std::string& type,
00213 const std::list<octave_value_list>& idx);
00214
00215 virtual octave_value_list
00216 subsref (const std::string& type,
00217 const std::list<octave_value_list>& idx,
00218 int nargout);
00219
00220 virtual octave_value
00221 subsref (const std::string& type,
00222 const std::list<octave_value_list>& idx,
00223 bool auto_add);
00224
00225 virtual octave_value
00226 do_index_op (const octave_value_list& idx, bool resize_ok = false);
00227
00228 virtual octave_value_list
00229 do_multi_index_op (int nargout, const octave_value_list& idx);
00230
00231 virtual void assign (const std::string&, const octave_value&) { }
00232
00233 virtual octave_value
00234 subsasgn (const std::string& type,
00235 const std::list<octave_value_list>& idx,
00236 const octave_value& rhs);
00237
00238 virtual idx_vector index_vector (void) const;
00239
00240 virtual dim_vector dims (void) const { return dim_vector (-1, -1); }
00241
00242 octave_idx_type rows (void) const
00243 {
00244 dim_vector dv = dims ();
00245
00246 return (dv.length () > 0) ? dv(0) : -1;
00247 }
00248
00249 octave_idx_type columns (void) const
00250 {
00251 dim_vector dv = dims ();
00252
00253 return (dv.length () > 1) ? dv(1) : -1;
00254 }
00255
00256 virtual int ndims (void) const;
00257
00258 virtual octave_idx_type numel (void) const { return dims ().numel (); }
00259
00260 virtual octave_idx_type capacity (void) const { return numel (); }
00261
00262 virtual size_t byte_size (void) const { return 0; }
00263
00264 virtual octave_idx_type nnz (void) const;
00265
00266 virtual octave_idx_type nzmax (void) const;
00267
00268 virtual octave_idx_type nfields (void) const;
00269
00270 virtual octave_value reshape (const dim_vector&) const;
00271
00272 virtual octave_value permute (const Array<int>& vec, bool = false) const;
00273
00274 virtual octave_value resize (const dim_vector&, bool fill = false) const;
00275
00276 virtual MatrixType matrix_type (void) const;
00277
00278 virtual MatrixType matrix_type (const MatrixType& typ) const;
00279
00280 virtual bool is_defined (void) const { return false; }
00281
00282 bool is_empty (void) const { return numel () == 0; }
00283
00284 virtual bool is_cell (void) const { return false; }
00285
00286 virtual bool is_cellstr (void) const { return false; }
00287
00288 virtual bool is_real_scalar (void) const { return false; }
00289
00290 virtual bool is_real_matrix (void) const { return false; }
00291
00292 virtual bool is_real_nd_array (void) const { return false; }
00293
00294 virtual bool is_complex_scalar (void) const { return false; }
00295
00296 virtual bool is_complex_matrix (void) const { return false; }
00297
00298 virtual bool is_bool_scalar (void) const { return false; }
00299
00300 virtual bool is_bool_matrix (void) const { return false; }
00301
00302 virtual bool is_char_matrix (void) const { return false; }
00303
00304 virtual bool is_diag_matrix (void) const { return false; }
00305
00306 virtual bool is_perm_matrix (void) const { return false; }
00307
00308 virtual bool is_string (void) const { return false; }
00309
00310 virtual bool is_sq_string (void) const { return false; }
00311
00312 virtual bool is_range (void) const { return false; }
00313
00314 virtual bool is_map (void) const { return false; }
00315
00316 virtual bool is_object (void) const { return false; }
00317
00318 virtual bool is_cs_list (void) const { return false; }
00319
00320 virtual bool is_list (void) const { return false; }
00321
00322 virtual bool is_magic_colon (void) const { return false; }
00323
00324 virtual bool is_all_va_args (void) const { return false; }
00325
00326 virtual octave_value all (int = 0) const;
00327
00328 virtual octave_value any (int = 0) const;
00329
00330 virtual builtin_type_t builtin_type (void) const { return btyp_unknown; }
00331
00332 virtual bool is_double_type (void) const { return false; }
00333
00334 virtual bool is_single_type (void) const { return false; }
00335
00336 virtual bool is_float_type (void) const { return false; }
00337
00338 virtual bool is_int8_type (void) const { return false; }
00339
00340 virtual bool is_int16_type (void) const { return false; }
00341
00342 virtual bool is_int32_type (void) const { return false; }
00343
00344 virtual bool is_int64_type (void) const { return false; }
00345
00346 virtual bool is_uint8_type (void) const { return false; }
00347
00348 virtual bool is_uint16_type (void) const { return false; }
00349
00350 virtual bool is_uint32_type (void) const { return false; }
00351
00352 virtual bool is_uint64_type (void) const { return false; }
00353
00354 virtual bool is_bool_type (void) const { return false; }
00355
00356 virtual bool is_integer_type (void) const { return false; }
00357
00358 virtual bool is_real_type (void) const { return false; }
00359
00360 virtual bool is_complex_type (void) const { return false; }
00361
00362
00363
00364 virtual bool is_scalar_type (void) const { return false; }
00365
00366 virtual bool is_matrix_type (void) const { return false; }
00367
00368 virtual bool is_numeric_type (void) const { return false; }
00369
00370 virtual bool is_sparse_type (void) const { return false; }
00371
00372 virtual bool is_true (void) const { return false; }
00373
00374 virtual bool is_null_value (void) const { return false; }
00375
00376 virtual bool is_constant (void) const { return false; }
00377
00378 virtual bool is_function_handle (void) const { return false; }
00379
00380 virtual bool is_inline_function (void) const { return false; }
00381
00382 virtual bool is_function (void) const { return false; }
00383
00384 virtual bool is_user_script (void) const { return false; }
00385
00386 virtual bool is_user_function (void) const { return false; }
00387
00388 virtual bool is_user_code (void) const { return false; }
00389
00390 virtual bool is_builtin_function (void) const { return false; }
00391
00392 virtual bool is_dld_function (void) const { return false; }
00393
00394 virtual bool is_mex_function (void) const { return false; }
00395
00396 virtual void erase_subfunctions (void) { }
00397
00398 virtual short int short_value (bool = false, bool = false) const;
00399
00400 virtual unsigned short int ushort_value (bool = false, bool = false) const;
00401
00402 virtual int int_value (bool = false, bool = false) const;
00403
00404 virtual unsigned int uint_value (bool = false, bool = false) const;
00405
00406 virtual int nint_value (bool = false) const;
00407
00408 virtual long int long_value (bool = false, bool = false) const;
00409
00410 virtual unsigned long int ulong_value (bool = false, bool = false) const;
00411
00412 virtual double double_value (bool = false) const;
00413
00414 virtual float float_value (bool = false) const;
00415
00416 virtual double scalar_value (bool frc_str_conv = false) const
00417 { return double_value (frc_str_conv); }
00418
00419 virtual float float_scalar_value (bool frc_str_conv = false) const
00420 { return float_value (frc_str_conv); }
00421
00422 virtual Cell cell_value (void) const;
00423
00424 virtual Matrix matrix_value (bool = false) const;
00425
00426 virtual FloatMatrix float_matrix_value (bool = false) const;
00427
00428 virtual NDArray array_value (bool = false) const;
00429
00430 virtual FloatNDArray float_array_value (bool = false) const;
00431
00432 virtual Complex complex_value (bool = false) const;
00433
00434 virtual FloatComplex float_complex_value (bool = false) const;
00435
00436 virtual ComplexMatrix complex_matrix_value (bool = false) const;
00437
00438 virtual FloatComplexMatrix float_complex_matrix_value (bool = false) const;
00439
00440 virtual ComplexNDArray complex_array_value (bool = false) const;
00441
00442 virtual FloatComplexNDArray float_complex_array_value (bool = false) const;
00443
00444 virtual bool bool_value (bool = false) const;
00445
00446 virtual boolMatrix bool_matrix_value (bool = false) const;
00447
00448 virtual boolNDArray bool_array_value (bool = false) const;
00449
00450 virtual charMatrix char_matrix_value (bool force = false) const;
00451
00452 virtual charNDArray char_array_value (bool = false) const;
00453
00454 virtual SparseMatrix sparse_matrix_value (bool = false) const;
00455
00456 virtual SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
00457
00458 virtual SparseBoolMatrix sparse_bool_matrix_value (bool = false) const;
00459
00460 virtual DiagMatrix diag_matrix_value (bool = false) const;
00461
00462 virtual FloatDiagMatrix float_diag_matrix_value (bool = false) const;
00463
00464 virtual ComplexDiagMatrix complex_diag_matrix_value (bool = false) const;
00465
00466 virtual FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const;
00467
00468 virtual PermMatrix perm_matrix_value (void) const;
00469
00470 virtual octave_int8 int8_scalar_value (void) const;
00471
00472 virtual octave_int16 int16_scalar_value (void) const;
00473
00474 virtual octave_int32 int32_scalar_value (void) const;
00475
00476 virtual octave_int64 int64_scalar_value (void) const;
00477
00478 virtual octave_uint8 uint8_scalar_value (void) const;
00479
00480 virtual octave_uint16 uint16_scalar_value (void) const;
00481
00482 virtual octave_uint32 uint32_scalar_value (void) const;
00483
00484 virtual octave_uint64 uint64_scalar_value (void) const;
00485
00486 virtual int8NDArray int8_array_value (void) const;
00487
00488 virtual int16NDArray int16_array_value (void) const;
00489
00490 virtual int32NDArray int32_array_value (void) const;
00491
00492 virtual int64NDArray int64_array_value (void) const;
00493
00494 virtual uint8NDArray uint8_array_value (void) const;
00495
00496 virtual uint16NDArray uint16_array_value (void) const;
00497
00498 virtual uint32NDArray uint32_array_value (void) const;
00499
00500 virtual uint64NDArray uint64_array_value (void) const;
00501
00502 virtual string_vector all_strings (bool pad = false) const;
00503
00504 virtual std::string string_value (bool force = false) const;
00505
00506 virtual Array<std::string> cellstr_value (void) const;
00507
00508 virtual Range range_value (void) const;
00509
00510 virtual Octave_map map_value (void) const;
00511
00512 virtual string_vector map_keys (void) const;
00513
00514 virtual size_t nparents (void) const;
00515
00516 virtual std::list<std::string> parent_class_name_list (void) const;
00517
00518 virtual string_vector parent_class_names (void) const;
00519
00520 virtual octave_base_value *find_parent_class (const std::string&)
00521 { return 0; }
00522
00523 virtual octave_function *function_value (bool silent = false);
00524
00525 virtual const octave_function *function_value (bool silent = false) const;
00526
00527 virtual octave_user_function *user_function_value (bool silent = false);
00528
00529 virtual octave_user_script *user_script_value (bool silent = false);
00530
00531 virtual octave_user_code *user_code_value (bool silent = false);
00532
00533 virtual octave_fcn_handle *fcn_handle_value (bool silent = false);
00534
00535 virtual octave_fcn_inline *fcn_inline_value (bool silent = false);
00536
00537 virtual octave_value_list list_value (void) const;
00538
00539 virtual octave_value convert_to_str (bool pad = false, bool force = false,
00540 char type = '\'') const;
00541 virtual octave_value
00542 convert_to_str_internal (bool pad, bool force, char type) const;
00543
00544 virtual void convert_to_row_or_column_vector (void);
00545
00546 virtual bool print_as_scalar (void) const { return false; }
00547
00548 virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00549
00550 virtual void
00551 print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00552
00553 virtual bool
00554 print_name_tag (std::ostream& os, const std::string& name) const;
00555
00556 virtual void
00557 print_with_name (std::ostream& output_buf, const std::string& name,
00558 bool print_padding = true);
00559
00560 virtual void print_info (std::ostream& os, const std::string& prefix) const;
00561
00562 virtual bool save_ascii (std::ostream& os);
00563
00564 virtual bool load_ascii (std::istream& is);
00565
00566 virtual bool save_binary (std::ostream& os, bool& save_as_floats);
00567
00568 virtual bool load_binary (std::istream& is, bool swap,
00569 oct_mach_info::float_format fmt);
00570
00571 #if defined (HAVE_HDF5)
00572 virtual bool
00573 save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00574
00575 virtual bool
00576 load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug);
00577 #endif
00578
00579 virtual int
00580 write (octave_stream& os, int block_size,
00581 oct_data_conv::data_type output_type, int skip,
00582 oct_mach_info::float_format flt_fmt) const;
00583
00584 virtual void *mex_get_data (void) const { return 0; }
00585
00586 virtual octave_idx_type *mex_get_ir (void) const { return 0; }
00587
00588 virtual octave_idx_type *mex_get_jc (void) const { return 0; }
00589
00590 virtual mxArray *as_mxArray (void) const;
00591
00592 virtual octave_value diag (octave_idx_type k = 0) const;
00593
00594 virtual octave_value sort (octave_idx_type dim = 0,
00595 sortmode mode = ASCENDING) const;
00596 virtual octave_value sort (Array<octave_idx_type> &sidx,
00597 octave_idx_type dim = 0,
00598 sortmode mode = ASCENDING) const;
00599
00600 virtual sortmode is_sorted (sortmode mode = UNSORTED) const;
00601
00602 virtual Array<octave_idx_type>
00603 sort_rows_idx (sortmode mode = ASCENDING) const;
00604
00605 virtual sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
00606
00607 virtual void lock (void);
00608
00609 virtual void unlock (void);
00610
00611 virtual bool islocked (void) const { return false; }
00612
00613 virtual void dump (std::ostream& os) const;
00614
00615 virtual octave_value abs (void) const;
00616 virtual octave_value acos (void) const;
00617 virtual octave_value acosh (void) const;
00618 virtual octave_value angle (void) const;
00619 virtual octave_value arg (void) const;
00620 virtual octave_value asin (void) const;
00621 virtual octave_value asinh (void) const;
00622 virtual octave_value atan (void) const;
00623 virtual octave_value atanh (void) const;
00624 virtual octave_value ceil (void) const;
00625 virtual octave_value conj (void) const;
00626 virtual octave_value cos (void) const;
00627 virtual octave_value cosh (void) const;
00628 virtual octave_value erf (void) const;
00629 virtual octave_value erfc (void) const;
00630 virtual octave_value exp (void) const;
00631 virtual octave_value expm1 (void) const;
00632 virtual octave_value finite (void) const;
00633 virtual octave_value fix (void) const;
00634 virtual octave_value floor (void) const;
00635 virtual octave_value gamma (void) const;
00636 virtual octave_value imag (void) const;
00637 virtual octave_value isinf (void) const;
00638 virtual octave_value isna (void) const;
00639 virtual octave_value isnan (void) const;
00640 virtual octave_value lgamma (void) const;
00641 virtual octave_value log (void) const;
00642 virtual octave_value log2 (void) const;
00643 virtual octave_value log10 (void) const;
00644 virtual octave_value log1p (void) const;
00645 virtual octave_value real (void) const;
00646 virtual octave_value round (void) const;
00647 virtual octave_value roundb (void) const;
00648 virtual octave_value signum (void) const;
00649 virtual octave_value sin (void) const;
00650 virtual octave_value sinh (void) const;
00651 virtual octave_value sqrt (void) const;
00652 virtual octave_value tan (void) const;
00653 virtual octave_value tanh (void) const;
00654
00655
00656
00657
00658 virtual octave_value xisalnum (void) const;
00659 virtual octave_value xisalpha (void) const;
00660 virtual octave_value xisascii (void) const;
00661 virtual octave_value xiscntrl (void) const;
00662 virtual octave_value xisdigit (void) const;
00663 virtual octave_value xisgraph (void) const;
00664 virtual octave_value xislower (void) const;
00665 virtual octave_value xisprint (void) const;
00666 virtual octave_value xispunct (void) const;
00667 virtual octave_value xisspace (void) const;
00668 virtual octave_value xisupper (void) const;
00669 virtual octave_value xisxdigit (void) const;
00670 virtual octave_value xtoascii (void) const;
00671 virtual octave_value xtolower (void) const;
00672 virtual octave_value xtoupper (void) const;
00673
00674 protected:
00675
00676
00677
00678 octave_value numeric_assign (const std::string& type,
00679 const std::list<octave_value_list>& idx,
00680 const octave_value& rhs);
00681
00682 void reset_indent_level (void) const
00683 { curr_print_indent_level = 0; }
00684
00685 void increment_indent_level (void) const
00686 { curr_print_indent_level += 2; }
00687
00688 void decrement_indent_level (void) const
00689 { curr_print_indent_level -= 2; }
00690
00691 int current_print_indent_level (void) const
00692 { return curr_print_indent_level; }
00693
00694 void indent (std::ostream& os) const;
00695
00696 void newline (std::ostream& os) const;
00697
00698 void reset (void) const;
00699
00700
00701
00702
00703
00704 octave_idx_type count;
00705
00706 private:
00707
00708 static int curr_print_indent_level;
00709 static bool beginning_of_line;
00710
00711 DECLARE_OV_BASE_TYPEID_FUNCTIONS_AND_DATA
00712 };
00713
00714
00715
00716 extern bool Vsparse_auto_mutate;
00717
00718 #endif
00719
00720
00721
00722
00723
00724