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_value_h)
00025 #define octave_value_h 1
00026
00027 #include <cstdlib>
00028
00029 #include <iosfwd>
00030 #include <string>
00031 #include <list>
00032
00033 #include "Range.h"
00034 #include "data-conv.h"
00035 #include "idx-vector.h"
00036 #include "mach-info.h"
00037 #include "mxarray.h"
00038 #include "mx-base.h"
00039 #include "oct-alloc.h"
00040 #include "oct-time.h"
00041 #include "str-vec.h"
00042
00043 #include "oct-hdf5.h"
00044 #include "oct-sort.h"
00045
00046 class Cell;
00047 class octave_map;
00048 class octave_scalar_map;
00049 class Octave_map;
00050 class octave_stream;
00051 class octave_function;
00052 class octave_user_function;
00053 class octave_fcn_handle;
00054 class octave_fcn_inline;
00055 class octave_value_list;
00056 class octave_lvalue;
00057
00058 #include "ov-base.h"
00059
00060
00061
00062 class octave_value;
00063
00064 class
00065 OCTINTERP_API
00066 octave_value
00067 {
00068 public:
00069
00070 enum unary_op
00071 {
00072 op_not,
00073 op_uplus,
00074 op_uminus,
00075 op_transpose,
00076 op_hermitian,
00077 op_incr,
00078 op_decr,
00079 num_unary_ops,
00080 unknown_unary_op
00081 };
00082
00083 enum binary_op
00084 {
00085 op_add,
00086 op_sub,
00087 op_mul,
00088 op_div,
00089 op_pow,
00090 op_ldiv,
00091 op_lshift,
00092 op_rshift,
00093 op_lt,
00094 op_le,
00095 op_eq,
00096 op_ge,
00097 op_gt,
00098 op_ne,
00099 op_el_mul,
00100 op_el_div,
00101 op_el_pow,
00102 op_el_ldiv,
00103 op_el_and,
00104 op_el_or,
00105 op_struct_ref,
00106 num_binary_ops,
00107 unknown_binary_op
00108 };
00109
00110 enum compound_binary_op
00111 {
00112
00113 op_trans_mul,
00114 op_mul_trans,
00115 op_herm_mul,
00116 op_mul_herm,
00117 op_trans_ldiv,
00118 op_herm_ldiv,
00119 op_el_not_and,
00120 op_el_not_or,
00121 op_el_and_not,
00122 op_el_or_not,
00123 num_compound_binary_ops,
00124 unknown_compound_binary_op
00125 };
00126
00127 enum assign_op
00128 {
00129 op_asn_eq,
00130 op_add_eq,
00131 op_sub_eq,
00132 op_mul_eq,
00133 op_div_eq,
00134 op_ldiv_eq,
00135 op_pow_eq,
00136 op_lshift_eq,
00137 op_rshift_eq,
00138 op_el_mul_eq,
00139 op_el_div_eq,
00140 op_el_ldiv_eq,
00141 op_el_pow_eq,
00142 op_el_and_eq,
00143 op_el_or_eq,
00144 num_assign_ops,
00145 unknown_assign_op
00146 };
00147
00148 static assign_op binary_op_to_assign_op (binary_op);
00149
00150 static std::string unary_op_as_string (unary_op);
00151 static std::string unary_op_fcn_name (unary_op);
00152
00153 static std::string binary_op_as_string (binary_op);
00154 static std::string binary_op_fcn_name (binary_op);
00155
00156 static std::string binary_op_fcn_name (compound_binary_op);
00157
00158 static std::string assign_op_as_string (assign_op);
00159
00160 static octave_value empty_conv (const std::string& type,
00161 const octave_value& rhs = octave_value ());
00162
00163 enum magic_colon { magic_colon_t };
00164
00165 octave_value (void)
00166 {
00167 static octave_base_value nil_rep;
00168 rep = &nil_rep;
00169 rep->count++;
00170 }
00171
00172 octave_value (short int i);
00173 octave_value (unsigned short int i);
00174 octave_value (int i);
00175 octave_value (unsigned int i);
00176 octave_value (long int i);
00177 octave_value (unsigned long int i);
00178
00179
00180
00181
00182
00183
00184
00185 #if defined (HAVE_LONG_LONG_INT)
00186 octave_value (long long int i);
00187 #endif
00188 #if defined (HAVE_UNSIGNED_LONG_LONG_INT)
00189 octave_value (unsigned long long int i);
00190 #endif
00191
00192 octave_value (octave_time t);
00193 octave_value (double d);
00194 octave_value (float d);
00195 octave_value (const Array<octave_value>& a, bool is_cs_list = false);
00196 octave_value (const Cell& c, bool is_cs_list = false);
00197 octave_value (const Matrix& m, const MatrixType& t = MatrixType());
00198 octave_value (const FloatMatrix& m, const MatrixType& t = MatrixType());
00199 octave_value (const NDArray& nda);
00200 octave_value (const FloatNDArray& nda);
00201 octave_value (const Array<double>& m);
00202 octave_value (const Array<float>& m);
00203 octave_value (const DiagMatrix& d);
00204 octave_value (const FloatDiagMatrix& d);
00205 octave_value (const RowVector& v);
00206 octave_value (const FloatRowVector& v);
00207 octave_value (const ColumnVector& v);
00208 octave_value (const FloatColumnVector& v);
00209 octave_value (const Complex& C);
00210 octave_value (const FloatComplex& C);
00211 octave_value (const ComplexMatrix& m, const MatrixType& t = MatrixType());
00212 octave_value (const FloatComplexMatrix& m, const MatrixType& t = MatrixType());
00213 octave_value (const ComplexNDArray& cnda);
00214 octave_value (const FloatComplexNDArray& cnda);
00215 octave_value (const Array<Complex>& m);
00216 octave_value (const Array<FloatComplex>& m);
00217 octave_value (const ComplexDiagMatrix& d);
00218 octave_value (const FloatComplexDiagMatrix& d);
00219 octave_value (const ComplexRowVector& v);
00220 octave_value (const FloatComplexRowVector& v);
00221 octave_value (const ComplexColumnVector& v);
00222 octave_value (const FloatComplexColumnVector& v);
00223 octave_value (const PermMatrix& p);
00224 octave_value (bool b);
00225 octave_value (const boolMatrix& bm, const MatrixType& t = MatrixType());
00226 octave_value (const boolNDArray& bnda);
00227 octave_value (const Array<bool>& bnda);
00228 octave_value (char c, char type = '\'');
00229 octave_value (const char *s, char type = '\'');
00230 octave_value (const std::string& s, char type = '\'');
00231 octave_value (const string_vector& s, char type = '\'');
00232 octave_value (const charMatrix& chm, char type = '\'');
00233 octave_value (const charNDArray& chnda, char type = '\'');
00234 octave_value (const Array<char>& chnda, char type = '\'');
00235 octave_value (const charMatrix& chm, bool is_string,
00236 char type = '\'') GCC_ATTR_DEPRECATED;
00237 octave_value (const charNDArray& chnda, bool is_string,
00238 char type = '\'') GCC_ATTR_DEPRECATED;
00239 octave_value (const Array<char>& chnda, bool is_string,
00240 char type = '\'') GCC_ATTR_DEPRECATED;
00241 octave_value (const SparseMatrix& m, const MatrixType& t = MatrixType ());
00242 octave_value (const Sparse<double>& m, const MatrixType& t = MatrixType ());
00243 octave_value (const SparseComplexMatrix& m,
00244 const MatrixType& t = MatrixType ());
00245 octave_value (const Sparse<Complex>& m, const MatrixType& t = MatrixType ());
00246 octave_value (const SparseBoolMatrix& bm,
00247 const MatrixType& t = MatrixType ());
00248 octave_value (const Sparse<bool>& m, const MatrixType& t = MatrixType ());
00249 octave_value (const octave_int8& i);
00250 octave_value (const octave_int16& i);
00251 octave_value (const octave_int32& i);
00252 octave_value (const octave_int64& i);
00253 octave_value (const octave_uint8& i);
00254 octave_value (const octave_uint16& i);
00255 octave_value (const octave_uint32& i);
00256 octave_value (const octave_uint64& i);
00257 octave_value (const int8NDArray& inda);
00258 octave_value (const Array<octave_int8>& inda);
00259 octave_value (const int16NDArray& inda);
00260 octave_value (const Array<octave_int16>& inda);
00261 octave_value (const int32NDArray& inda);
00262 octave_value (const Array<octave_int32>& inda);
00263 octave_value (const int64NDArray& inda);
00264 octave_value (const Array<octave_int64>& inda);
00265 octave_value (const uint8NDArray& inda);
00266 octave_value (const Array<octave_uint8>& inda);
00267 octave_value (const uint16NDArray& inda);
00268 octave_value (const Array<octave_uint16>& inda);
00269 octave_value (const uint32NDArray& inda);
00270 octave_value (const Array<octave_uint32>& inda);
00271 octave_value (const uint64NDArray& inda);
00272 octave_value (const Array<octave_uint64>& inda);
00273 octave_value (const Array<octave_idx_type>& inda,
00274 bool zero_based = false, bool cache_index = false);
00275 octave_value (const Array<std::string>& cellstr);
00276 octave_value (const idx_vector& idx, bool lazy = true);
00277 octave_value (double base, double limit, double inc);
00278 octave_value (const Range& r);
00279 octave_value (const octave_map& m);
00280 octave_value (const octave_scalar_map& m);
00281 octave_value (const Octave_map& m);
00282 octave_value (const Octave_map& m, const std::string& id);
00283 octave_value (const octave_value_list& m, bool = false);
00284 octave_value (octave_value::magic_colon);
00285
00286 octave_value (octave_base_value *new_rep, bool borrow = false);
00287 octave_value (octave_base_value *new_rep, int xcount) GCC_ATTR_DEPRECATED;
00288
00289
00290
00291 octave_value (const octave_value& a)
00292 {
00293 rep = a.rep;
00294 rep->count++;
00295 }
00296
00297
00298
00299 octave_base_value *clone (void) const;
00300
00301 octave_base_value *empty_clone (void) const
00302 { return rep->empty_clone (); }
00303
00304
00305
00306
00307 ~octave_value (void)
00308 {
00309 if (--rep->count == 0)
00310 delete rep;
00311 }
00312
00313 void make_unique (void)
00314 {
00315 if (rep->count > 1)
00316 {
00317 --rep->count;
00318 rep = rep->unique_clone ();
00319 }
00320 }
00321
00322
00323
00324
00325 void make_unique (int obsolete_copies)
00326 {
00327 if (rep->count > obsolete_copies + 1)
00328 {
00329 --rep->count;
00330 rep = rep->unique_clone ();
00331 }
00332 }
00333
00334
00335
00336 octave_value& operator = (const octave_value& a)
00337 {
00338 if (rep != a.rep)
00339 {
00340 if (--rep->count == 0)
00341 delete rep;
00342
00343 rep = a.rep;
00344 rep->count++;
00345 }
00346
00347 return *this;
00348 }
00349
00350 octave_idx_type get_count (void) const { return rep->count; }
00351
00352 octave_base_value::type_conv_info numeric_conversion_function (void) const
00353 { return rep->numeric_conversion_function (); }
00354
00355 octave_base_value::type_conv_info numeric_demotion_function (void) const
00356 { return rep->numeric_demotion_function (); }
00357
00358 void maybe_mutate (void);
00359
00360 octave_value squeeze (void) const
00361 { return rep->squeeze (); }
00362
00363
00364 octave_value full_value (void) const
00365 { return rep->full_value (); }
00366
00367 octave_base_value *try_narrowing_conversion (void)
00368 { return rep->try_narrowing_conversion (); }
00369
00370
00371 Matrix size (void)
00372 { return rep->size (); }
00373
00374 octave_idx_type numel (const octave_value_list& idx)
00375 { return rep->numel (idx); }
00376
00377 octave_value single_subsref (const std::string& type,
00378 const octave_value_list& idx);
00379
00380 octave_value subsref (const std::string& type,
00381 const std::list<octave_value_list>& idx)
00382 { return rep->subsref (type, idx); }
00383
00384 octave_value subsref (const std::string& type,
00385 const std::list<octave_value_list>& idx,
00386 bool auto_add)
00387 { return rep->subsref (type, idx, auto_add); }
00388
00389 octave_value_list subsref (const std::string& type,
00390 const std::list<octave_value_list>& idx,
00391 int nargout);
00392
00393 octave_value_list subsref (const std::string& type,
00394 const std::list<octave_value_list>& idx,
00395 int nargout,
00396 const std::list<octave_lvalue> *lvalue_list);
00397
00398 octave_value next_subsref (const std::string& type, const
00399 std::list<octave_value_list>& idx,
00400 size_t skip = 1);
00401
00402 octave_value_list next_subsref (int nargout,
00403 const std::string& type, const
00404 std::list<octave_value_list>& idx,
00405 size_t skip = 1);
00406
00407 octave_value next_subsref (bool auto_add, const std::string& type, const
00408 std::list<octave_value_list>& idx,
00409 size_t skip = 1);
00410
00411 octave_value do_index_op (const octave_value_list& idx,
00412 bool resize_ok = false)
00413 { return rep->do_index_op (idx, resize_ok); }
00414
00415 octave_value_list
00416 do_multi_index_op (int nargout, const octave_value_list& idx);
00417
00418 octave_value_list
00419 do_multi_index_op (int nargout, const octave_value_list& idx,
00420 const std::list<octave_lvalue> *lvalue_list);
00421
00422 octave_value subsasgn (const std::string& type,
00423 const std::list<octave_value_list>& idx,
00424 const octave_value& rhs);
00425
00426 octave_value undef_subsasgn (const std::string& type,
00427 const std::list<octave_value_list>& idx,
00428 const octave_value& rhs);
00429
00430 octave_value& assign (assign_op op, const std::string& type,
00431 const std::list<octave_value_list>& idx,
00432 const octave_value& rhs);
00433
00434 octave_value& assign (assign_op, const octave_value& rhs);
00435
00436 idx_vector index_vector (void) const
00437 { return rep->index_vector (); }
00438
00439
00440
00441 dim_vector dims (void) const
00442 { return rep->dims (); }
00443
00444 octave_idx_type rows (void) const { return rep->rows (); }
00445
00446 octave_idx_type columns (void) const { return rep->columns (); }
00447
00448 octave_idx_type length (void) const;
00449
00450 int ndims (void) const { return rep->ndims (); }
00451
00452 bool all_zero_dims (void) const { return dims().all_zero (); }
00453
00454 octave_idx_type numel (void) const
00455 { return rep->numel (); }
00456
00457 octave_idx_type capacity (void) const
00458 { return rep->capacity (); }
00459
00460 size_t byte_size (void) const
00461 { return rep->byte_size (); }
00462
00463 octave_idx_type nnz (void) const { return rep->nnz (); }
00464
00465 octave_idx_type nzmax (void) const { return rep->nzmax (); }
00466
00467 octave_idx_type nfields (void) const { return rep->nfields (); }
00468
00469 octave_value reshape (const dim_vector& dv) const
00470 { return rep->reshape (dv); }
00471
00472 octave_value permute (const Array<int>& vec, bool inv = false) const
00473 { return rep->permute (vec, inv); }
00474
00475 octave_value ipermute (const Array<int>& vec) const
00476 { return rep->permute (vec, true); }
00477
00478 octave_value resize (const dim_vector& dv, bool fill = false) const
00479 { return rep->resize (dv, fill);}
00480
00481 MatrixType matrix_type (void) const
00482 { return rep->matrix_type (); }
00483
00484 MatrixType matrix_type (const MatrixType& typ) const
00485 { return rep->matrix_type (typ); }
00486
00487
00488
00489
00490
00491 bool is_defined (void) const
00492 { return rep->is_defined (); }
00493
00494 bool is_undefined (void) const
00495 { return ! is_defined (); }
00496
00497 bool is_empty (void) const
00498 { return rep->is_empty (); }
00499
00500 bool is_cell (void) const
00501 { return rep->is_cell (); }
00502
00503 bool is_cellstr (void) const
00504 { return rep->is_cellstr (); }
00505
00506 bool is_real_scalar (void) const
00507 { return rep->is_real_scalar (); }
00508
00509 bool is_real_matrix (void) const
00510 { return rep->is_real_matrix (); }
00511
00512 bool is_real_nd_array (void) const
00513 { return rep->is_real_nd_array (); }
00514
00515 bool is_complex_scalar (void) const
00516 { return rep->is_complex_scalar (); }
00517
00518 bool is_complex_matrix (void) const
00519 { return rep->is_complex_matrix (); }
00520
00521 bool is_bool_scalar (void) const
00522 { return rep->is_bool_scalar (); }
00523
00524 bool is_bool_matrix (void) const
00525 { return rep->is_bool_matrix (); }
00526
00527 bool is_char_matrix (void) const
00528 { return rep->is_char_matrix (); }
00529
00530 bool is_diag_matrix (void) const
00531 { return rep->is_diag_matrix (); }
00532
00533 bool is_perm_matrix (void) const
00534 { return rep->is_perm_matrix (); }
00535
00536 bool is_string (void) const
00537 { return rep->is_string (); }
00538
00539 bool is_sq_string (void) const
00540 { return rep->is_sq_string (); }
00541
00542 bool is_dq_string (void) const
00543 { return rep->is_string () && ! rep->is_sq_string (); }
00544
00545 bool is_range (void) const
00546 { return rep->is_range (); }
00547
00548 bool is_map (void) const
00549 { return rep->is_map (); }
00550
00551 bool is_object (void) const
00552 { return rep->is_object (); }
00553
00554 bool is_cs_list (void) const
00555 { return rep->is_cs_list (); }
00556
00557 bool is_magic_colon (void) const
00558 { return rep->is_magic_colon (); }
00559
00560 bool is_null_value (void) const
00561 { return rep->is_null_value (); }
00562
00563
00564
00565 octave_value all (int dim = 0) const
00566 { return rep->all (dim); }
00567
00568 octave_value any (int dim = 0) const
00569 { return rep->any (dim); }
00570
00571 builtin_type_t builtin_type (void) const
00572 { return rep->builtin_type (); }
00573
00574
00575
00576 bool is_double_type (void) const
00577 { return rep->is_double_type (); }
00578
00579 bool is_single_type (void) const
00580 { return rep->is_single_type (); }
00581
00582 bool is_float_type (void) const
00583 { return rep->is_float_type (); }
00584
00585
00586
00587 bool is_int8_type (void) const
00588 { return rep->is_int8_type (); }
00589
00590 bool is_int16_type (void) const
00591 { return rep->is_int16_type (); }
00592
00593 bool is_int32_type (void) const
00594 { return rep->is_int32_type (); }
00595
00596 bool is_int64_type (void) const
00597 { return rep->is_int64_type (); }
00598
00599 bool is_uint8_type (void) const
00600 { return rep->is_uint8_type (); }
00601
00602 bool is_uint16_type (void) const
00603 { return rep->is_uint16_type (); }
00604
00605 bool is_uint32_type (void) const
00606 { return rep->is_uint32_type (); }
00607
00608 bool is_uint64_type (void) const
00609 { return rep->is_uint64_type (); }
00610
00611
00612
00613 bool is_bool_type (void) const
00614 { return rep->is_bool_type (); }
00615
00616 bool is_integer_type (void) const
00617 { return rep->is_integer_type (); }
00618
00619 bool is_real_type (void) const
00620 { return rep->is_real_type (); }
00621
00622 bool is_complex_type (void) const
00623 { return rep->is_complex_type (); }
00624
00625 bool is_scalar_type (void) const
00626 { return rep->is_scalar_type (); }
00627
00628 bool is_matrix_type (void) const
00629 { return rep->is_matrix_type (); }
00630
00631 bool is_numeric_type (void) const
00632 { return rep->is_numeric_type (); }
00633
00634 bool is_sparse_type (void) const
00635 { return rep->is_sparse_type (); }
00636
00637
00638
00639 bool is_true (void) const
00640 { return rep->is_true (); }
00641
00642
00643
00644 bool is_equal (const octave_value&) const;
00645
00646
00647
00648 bool is_zero_by_zero (void) const
00649 { return (rows () == 0 && columns () == 0); }
00650
00651 bool is_constant (void) const
00652 { return rep->is_constant (); }
00653
00654 bool is_function_handle (void) const
00655 { return rep->is_function_handle (); }
00656
00657 bool is_inline_function (void) const
00658 { return rep->is_inline_function (); }
00659
00660 bool is_function (void) const
00661 { return rep->is_function (); }
00662
00663 bool is_user_script (void) const
00664 { return rep->is_user_script (); }
00665
00666 bool is_user_function (void) const
00667 { return rep->is_user_function (); }
00668
00669 bool is_user_code (void) const
00670 { return rep->is_user_code (); }
00671
00672 bool is_builtin_function (void) const
00673 { return rep->is_builtin_function (); }
00674
00675 bool is_dld_function (void) const
00676 { return rep->is_dld_function (); }
00677
00678 bool is_mex_function (void) const
00679 { return rep->is_mex_function (); }
00680
00681 void erase_subfunctions (void) { rep->erase_subfunctions (); }
00682
00683
00684
00685 octave_value eval (void) { return *this; }
00686
00687 short int
00688 short_value (bool req_int = false, bool frc_str_conv = false) const
00689 { return rep->short_value (req_int, frc_str_conv); }
00690
00691 unsigned short int
00692 ushort_value (bool req_int = false, bool frc_str_conv = false) const
00693 { return rep->ushort_value (req_int, frc_str_conv); }
00694
00695 int int_value (bool req_int = false, bool frc_str_conv = false) const
00696 { return rep->int_value (req_int, frc_str_conv); }
00697
00698 unsigned int
00699 uint_value (bool req_int = false, bool frc_str_conv = false) const
00700 { return rep->uint_value (req_int, frc_str_conv); }
00701
00702 int nint_value (bool frc_str_conv = false) const
00703 { return rep->nint_value (frc_str_conv); }
00704
00705 long int
00706 long_value (bool req_int = false, bool frc_str_conv = false) const
00707 { return rep->long_value (req_int, frc_str_conv); }
00708
00709 unsigned long int
00710 ulong_value (bool req_int = false, bool frc_str_conv = false) const
00711 { return rep->ulong_value (req_int, frc_str_conv); }
00712
00713 octave_idx_type
00714 idx_type_value (bool req_int = false, bool frc_str_conv = false) const;
00715
00716 double double_value (bool frc_str_conv = false) const
00717 { return rep->double_value (frc_str_conv); }
00718
00719 float float_value (bool frc_str_conv = false) const
00720 { return rep->float_value (frc_str_conv); }
00721
00722 double scalar_value (bool frc_str_conv = false) const
00723 { return rep->scalar_value (frc_str_conv); }
00724
00725 float float_scalar_value (bool frc_str_conv = false) const
00726 { return rep->float_scalar_value (frc_str_conv); }
00727
00728 Cell cell_value (void) const;
00729
00730 Matrix matrix_value (bool frc_str_conv = false) const
00731 { return rep->matrix_value (frc_str_conv); }
00732
00733 FloatMatrix float_matrix_value (bool frc_str_conv = false) const
00734 { return rep->float_matrix_value (frc_str_conv); }
00735
00736 NDArray array_value (bool frc_str_conv = false) const
00737 { return rep->array_value (frc_str_conv); }
00738
00739 FloatNDArray float_array_value (bool frc_str_conv = false) const
00740 { return rep->float_array_value (frc_str_conv); }
00741
00742 Complex complex_value (bool frc_str_conv = false) const
00743 { return rep->complex_value (frc_str_conv); }
00744
00745 FloatComplex float_complex_value (bool frc_str_conv = false) const
00746 { return rep->float_complex_value (frc_str_conv); }
00747
00748 ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const
00749 { return rep->complex_matrix_value (frc_str_conv); }
00750
00751 FloatComplexMatrix float_complex_matrix_value (bool frc_str_conv = false) const
00752 { return rep->float_complex_matrix_value (frc_str_conv); }
00753
00754 ComplexNDArray complex_array_value (bool frc_str_conv = false) const
00755 { return rep->complex_array_value (frc_str_conv); }
00756
00757 FloatComplexNDArray float_complex_array_value (bool frc_str_conv = false) const
00758 { return rep->float_complex_array_value (frc_str_conv); }
00759
00760 bool bool_value (bool warn = false) const
00761 { return rep->bool_value (warn); }
00762
00763 boolMatrix bool_matrix_value (bool warn = false) const
00764 { return rep->bool_matrix_value (warn); }
00765
00766 boolNDArray bool_array_value (bool warn = false) const
00767 { return rep->bool_array_value (warn); }
00768
00769 charMatrix char_matrix_value (bool frc_str_conv = false) const
00770 { return rep->char_matrix_value (frc_str_conv); }
00771
00772 charNDArray char_array_value (bool frc_str_conv = false) const
00773 { return rep->char_array_value (frc_str_conv); }
00774
00775 SparseMatrix sparse_matrix_value (bool frc_str_conv = false) const
00776 { return rep->sparse_matrix_value (frc_str_conv); }
00777
00778 SparseComplexMatrix sparse_complex_matrix_value (bool frc_str_conv = false) const
00779 { return rep->sparse_complex_matrix_value (frc_str_conv); }
00780
00781 SparseBoolMatrix sparse_bool_matrix_value (bool warn = false) const
00782 { return rep->sparse_bool_matrix_value (warn); }
00783
00784 DiagMatrix diag_matrix_value (bool force = false) const
00785 { return rep->diag_matrix_value (force); }
00786
00787 FloatDiagMatrix float_diag_matrix_value (bool force = false) const
00788 { return rep->float_diag_matrix_value (force); }
00789
00790 ComplexDiagMatrix complex_diag_matrix_value (bool force = false) const
00791 { return rep->complex_diag_matrix_value (force); }
00792
00793 FloatComplexDiagMatrix float_complex_diag_matrix_value (bool force = false) const
00794 { return rep->float_complex_diag_matrix_value (force); }
00795
00796 PermMatrix perm_matrix_value (void) const
00797 { return rep->perm_matrix_value (); }
00798
00799 octave_int8 int8_scalar_value (void) const
00800 { return rep->int8_scalar_value (); }
00801
00802 octave_int16 int16_scalar_value (void) const
00803 { return rep->int16_scalar_value (); }
00804
00805 octave_int32 int32_scalar_value (void) const
00806 { return rep->int32_scalar_value (); }
00807
00808 octave_int64 int64_scalar_value (void) const
00809 { return rep->int64_scalar_value (); }
00810
00811 octave_uint8 uint8_scalar_value (void) const
00812 { return rep->uint8_scalar_value (); }
00813
00814 octave_uint16 uint16_scalar_value (void) const
00815 { return rep->uint16_scalar_value (); }
00816
00817 octave_uint32 uint32_scalar_value (void) const
00818 { return rep->uint32_scalar_value (); }
00819
00820 octave_uint64 uint64_scalar_value (void) const
00821 { return rep->uint64_scalar_value (); }
00822
00823 int8NDArray int8_array_value (void) const
00824 { return rep->int8_array_value (); }
00825
00826 int16NDArray int16_array_value (void) const
00827 { return rep->int16_array_value (); }
00828
00829 int32NDArray int32_array_value (void) const
00830 { return rep->int32_array_value (); }
00831
00832 int64NDArray int64_array_value (void) const
00833 { return rep->int64_array_value (); }
00834
00835 uint8NDArray uint8_array_value (void) const
00836 { return rep->uint8_array_value (); }
00837
00838 uint16NDArray uint16_array_value (void) const
00839 { return rep->uint16_array_value (); }
00840
00841 uint32NDArray uint32_array_value (void) const
00842 { return rep->uint32_array_value (); }
00843
00844 uint64NDArray uint64_array_value (void) const
00845 { return rep->uint64_array_value (); }
00846
00847 string_vector all_strings (bool pad = false) const
00848 { return rep->all_strings (pad); }
00849
00850 std::string string_value (bool force = false) const
00851 { return rep->string_value (force); }
00852
00853 Array<std::string> cellstr_value (void) const
00854 { return rep->cellstr_value (); }
00855
00856 Range range_value (void) const
00857 { return rep->range_value (); }
00858
00859 octave_map map_value (void) const;
00860
00861 octave_scalar_map scalar_map_value (void) const;
00862
00863 string_vector map_keys (void) const
00864 { return rep->map_keys (); }
00865
00866 size_t nparents (void) const
00867 { return rep->nparents (); }
00868
00869 std::list<std::string> parent_class_name_list (void) const
00870 { return rep->parent_class_name_list (); }
00871
00872 string_vector parent_class_names (void) const
00873 { return rep->parent_class_names (); }
00874
00875 octave_base_value *
00876 find_parent_class (const std::string& parent_class_name)
00877 { return rep->find_parent_class (parent_class_name); }
00878
00879 octave_function *function_value (bool silent = false) const;
00880
00881 octave_user_function *user_function_value (bool silent = false) const;
00882
00883 octave_user_script *user_script_value (bool silent = false) const;
00884
00885 octave_user_code *user_code_value (bool silent = false) const;
00886
00887 octave_fcn_handle *fcn_handle_value (bool silent = false) const;
00888
00889 octave_fcn_inline *fcn_inline_value (bool silent = false) const;
00890
00891 octave_value_list list_value (void) const;
00892
00893 ColumnVector column_vector_value (bool frc_str_conv = false,
00894 bool frc_vec_conv = false) const;
00895
00896 ComplexColumnVector
00897 complex_column_vector_value (bool frc_str_conv = false,
00898 bool frc_vec_conv = false) const;
00899
00900 RowVector row_vector_value (bool frc_str_conv = false,
00901 bool frc_vec_conv = false) const;
00902
00903 ComplexRowVector
00904 complex_row_vector_value (bool frc_str_conv = false,
00905 bool frc_vec_conv = false) const;
00906
00907
00908 FloatColumnVector float_column_vector_value (bool frc_str_conv = false,
00909 bool frc_vec_conv = false) const;
00910
00911 FloatComplexColumnVector
00912 float_complex_column_vector_value (bool frc_str_conv = false,
00913 bool frc_vec_conv = false) const;
00914
00915 FloatRowVector float_row_vector_value (bool frc_str_conv = false,
00916 bool frc_vec_conv = false) const;
00917
00918 FloatComplexRowVector
00919 float_complex_row_vector_value (bool frc_str_conv = false,
00920 bool frc_vec_conv = false) const;
00921
00922
00923
00924
00925 Array<int> int_vector_value (bool req_int = false,
00926 bool frc_str_conv = false,
00927 bool frc_vec_conv = false) const;
00928
00929 Array<octave_idx_type>
00930 octave_idx_type_vector_value (bool req_int = false,
00931 bool frc_str_conv = false,
00932 bool frc_vec_conv = false) const;
00933
00934 Array<double> vector_value (bool frc_str_conv = false,
00935 bool frc_vec_conv = false) const;
00936
00937 Array<Complex> complex_vector_value (bool frc_str_conv = false,
00938 bool frc_vec_conv = false) const;
00939
00940 Array<float> float_vector_value (bool frc_str_conv = false,
00941 bool frc_vec_conv = false) const;
00942
00943 Array<FloatComplex> float_complex_vector_value (bool frc_str_conv = false,
00944 bool frc_vec_conv = false) const;
00945
00946
00947
00948 void maybe_economize (void)
00949 { rep->maybe_economize (); }
00950
00951
00952
00953
00954
00955 octave_value storable_value (void) const;
00956
00957
00958
00959
00960 void make_storable_value (void);
00961
00962
00963
00964
00965
00966 octave_value convert_to_str (bool pad = false, bool force = false,
00967 char type = '\'') const
00968 { return rep->convert_to_str (pad, force, type); }
00969
00970 octave_value
00971 convert_to_str_internal (bool pad, bool force, char type) const
00972 { return rep->convert_to_str_internal (pad, force, type); }
00973
00974 void convert_to_row_or_column_vector (void)
00975 { rep->convert_to_row_or_column_vector (); }
00976
00977 bool print_as_scalar (void) const
00978 { return rep->print_as_scalar (); }
00979
00980 void print (std::ostream& os, bool pr_as_read_syntax = false) const
00981 { rep->print (os, pr_as_read_syntax); }
00982
00983 void print_raw (std::ostream& os,
00984 bool pr_as_read_syntax = false) const
00985 { rep->print_raw (os, pr_as_read_syntax); }
00986
00987 bool print_name_tag (std::ostream& os, const std::string& name) const
00988 { return rep->print_name_tag (os, name); }
00989
00990 void print_with_name (std::ostream& os, const std::string& name,
00991 bool print_padding = true) const
00992 { rep->print_with_name (os, name, print_padding); }
00993
00994 int type_id (void) const { return rep->type_id (); }
00995
00996 std::string type_name (void) const { return rep->type_name (); }
00997
00998 std::string class_name (void) const { return rep->class_name (); }
00999
01000
01001
01002 friend OCTINTERP_API octave_value do_unary_op (unary_op op,
01003 const octave_value& a);
01004
01005 octave_value& do_non_const_unary_op (unary_op op);
01006
01007 octave_value& do_non_const_unary_op (unary_op op, const std::string& type,
01008 const std::list<octave_value_list>& idx);
01009
01010 friend OCTINTERP_API octave_value do_binary_op (binary_op op,
01011 const octave_value& a,
01012 const octave_value& b);
01013
01014 friend OCTINTERP_API octave_value do_binary_op (compound_binary_op op,
01015 const octave_value& a,
01016 const octave_value& b);
01017
01018 friend OCTINTERP_API octave_value do_cat_op (const octave_value& a,
01019 const octave_value& b,
01020 const Array<octave_idx_type>& ra_idx);
01021
01022 const octave_base_value& get_rep (void) const { return *rep; }
01023
01024 bool is_copy_of (const octave_value &val) const { return rep == val.rep; }
01025
01026 void print_info (std::ostream& os,
01027 const std::string& prefix = std::string ()) const;
01028
01029 bool save_ascii (std::ostream& os) { return rep->save_ascii (os); }
01030
01031 bool load_ascii (std::istream& is) { return rep->load_ascii (is); }
01032
01033 bool save_binary (std::ostream& os, bool& save_as_floats)
01034 { return rep->save_binary (os, save_as_floats); }
01035
01036 bool load_binary (std::istream& is, bool swap,
01037 oct_mach_info::float_format fmt)
01038 { return rep->load_binary (is, swap, fmt); }
01039
01040 #if defined (HAVE_HDF5)
01041 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
01042 { return rep->save_hdf5 (loc_id, name, save_as_floats); }
01043
01044 bool load_hdf5 (hid_t loc_id, const char *name)
01045 { return rep->load_hdf5 (loc_id, name); }
01046 #endif
01047
01048 int write (octave_stream& os, int block_size,
01049 oct_data_conv::data_type output_type, int skip,
01050 oct_mach_info::float_format flt_fmt) const;
01051
01052 octave_base_value *internal_rep (void) const { return rep; }
01053
01054
01055
01056 void *mex_get_data (void) const { return rep->mex_get_data (); }
01057
01058 octave_idx_type *mex_get_ir (void) const { return rep->mex_get_ir (); }
01059
01060 octave_idx_type *mex_get_jc (void) const { return rep->mex_get_jc (); }
01061
01062 mxArray *as_mxArray (void) const { return rep->as_mxArray (); }
01063
01064 octave_value diag (octave_idx_type k = 0) const
01065 { return rep->diag (k); }
01066
01067 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
01068 { return rep->sort (dim, mode); }
01069 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
01070 sortmode mode = ASCENDING) const
01071 { return rep->sort (sidx, dim, mode); }
01072
01073 sortmode is_sorted (sortmode mode = UNSORTED) const
01074 { return rep->is_sorted (mode); }
01075
01076 Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
01077 { return rep->sort_rows_idx (mode); }
01078
01079 sortmode is_sorted_rows (sortmode mode = UNSORTED) const
01080 { return rep->is_sorted_rows (mode); }
01081
01082 void lock (void) { rep->lock (); }
01083
01084 void unlock (void) { rep->unlock (); }
01085
01086 bool islocked (void) const { return rep->islocked (); }
01087
01088 void dump (std::ostream& os) const { rep->dump (os); }
01089
01090 #define MAPPER_FORWARD(F) \
01091 octave_value F (void) const { return rep->map (octave_base_value::umap_ ## F); }
01092
01093 MAPPER_FORWARD (abs)
01094 MAPPER_FORWARD (acos)
01095 MAPPER_FORWARD (acosh)
01096 MAPPER_FORWARD (angle)
01097 MAPPER_FORWARD (arg)
01098 MAPPER_FORWARD (asin)
01099 MAPPER_FORWARD (asinh)
01100 MAPPER_FORWARD (atan)
01101 MAPPER_FORWARD (atanh)
01102 MAPPER_FORWARD (cbrt)
01103 MAPPER_FORWARD (ceil)
01104 MAPPER_FORWARD (conj)
01105 MAPPER_FORWARD (cos)
01106 MAPPER_FORWARD (cosh)
01107 MAPPER_FORWARD (erf)
01108 MAPPER_FORWARD (erfinv)
01109 MAPPER_FORWARD (erfc)
01110 MAPPER_FORWARD (erfcx)
01111 MAPPER_FORWARD (exp)
01112 MAPPER_FORWARD (expm1)
01113 MAPPER_FORWARD (finite)
01114 MAPPER_FORWARD (fix)
01115 MAPPER_FORWARD (floor)
01116 MAPPER_FORWARD (gamma)
01117 MAPPER_FORWARD (imag)
01118 MAPPER_FORWARD (isinf)
01119 MAPPER_FORWARD (isna)
01120 MAPPER_FORWARD (isnan)
01121 MAPPER_FORWARD (lgamma)
01122 MAPPER_FORWARD (log)
01123 MAPPER_FORWARD (log2)
01124 MAPPER_FORWARD (log10)
01125 MAPPER_FORWARD (log1p)
01126 MAPPER_FORWARD (real)
01127 MAPPER_FORWARD (round)
01128 MAPPER_FORWARD (roundb)
01129 MAPPER_FORWARD (signum)
01130 MAPPER_FORWARD (sin)
01131 MAPPER_FORWARD (sinh)
01132 MAPPER_FORWARD (sqrt)
01133 MAPPER_FORWARD (tan)
01134 MAPPER_FORWARD (tanh)
01135
01136
01137
01138
01139 MAPPER_FORWARD (xisalnum)
01140 MAPPER_FORWARD (xisalpha)
01141 MAPPER_FORWARD (xisascii)
01142 MAPPER_FORWARD (xiscntrl)
01143 MAPPER_FORWARD (xisdigit)
01144 MAPPER_FORWARD (xisgraph)
01145 MAPPER_FORWARD (xislower)
01146 MAPPER_FORWARD (xisprint)
01147 MAPPER_FORWARD (xispunct)
01148 MAPPER_FORWARD (xisspace)
01149 MAPPER_FORWARD (xisupper)
01150 MAPPER_FORWARD (xisxdigit)
01151 MAPPER_FORWARD (xtoascii)
01152 MAPPER_FORWARD (xtolower)
01153 MAPPER_FORWARD (xtoupper)
01154
01155 #undef MAPPER_FORWARD
01156
01157 octave_value map (octave_base_value::unary_mapper_t umap) const
01158 { return rep->map (umap); }
01159
01160
01161
01162 octave_value
01163 fast_elem_extract (octave_idx_type n) const
01164 { return rep->fast_elem_extract (n); }
01165
01166
01167
01168
01169 virtual bool
01170 fast_elem_insert (octave_idx_type n, const octave_value& x)
01171 {
01172 make_unique ();
01173 return rep->fast_elem_insert (n, x);
01174 }
01175
01176 protected:
01177
01178
01179 octave_base_value *rep;
01180
01181 private:
01182
01183 assign_op unary_op_to_assign_op (unary_op op);
01184
01185 binary_op op_eq_to_binary_op (assign_op op);
01186
01187
01188
01189 octave_value (const octave_base_value *);
01190
01191 DECLARE_OCTAVE_ALLOCATOR
01192 };
01193
01194
01195
01196 extern OCTINTERP_API octave_value
01197 do_unary_op (octave_value::unary_op op, const octave_value& a);
01198
01199 extern OCTINTERP_API octave_value
01200 do_binary_op (octave_value::binary_op op,
01201 const octave_value& a, const octave_value& b);
01202
01203 extern OCTINTERP_API octave_value
01204 do_binary_op (octave_value::compound_binary_op op,
01205 const octave_value& a, const octave_value& b);
01206
01207 #define OV_UNOP_FN(name) \
01208 inline octave_value \
01209 name (const octave_value& a) \
01210 { \
01211 return do_unary_op (octave_value::name, a); \
01212 }
01213
01214 #define OV_UNOP_OP(name, op) \
01215 inline octave_value \
01216 operator op (const octave_value& a) \
01217 { \
01218 return name (a); \
01219 }
01220
01221 #define OV_UNOP_FN_OP(name, op) \
01222 OV_UNOP_FN (name) \
01223 OV_UNOP_OP (name, op)
01224
01225 OV_UNOP_FN_OP (op_not, !)
01226 OV_UNOP_FN_OP (op_uplus, +)
01227 OV_UNOP_FN_OP (op_uminus, -)
01228
01229 OV_UNOP_FN (op_transpose)
01230 OV_UNOP_FN (op_hermitian)
01231
01232
01233
01234
01235
01236
01237 #define OV_BINOP_FN(name) \
01238 inline octave_value \
01239 name (const octave_value& a1, const octave_value& a2) \
01240 { \
01241 return do_binary_op (octave_value::name, a1, a2); \
01242 }
01243
01244 #define OV_BINOP_OP(name, op) \
01245 inline octave_value \
01246 operator op (const octave_value& a1, const octave_value& a2) \
01247 { \
01248 return name (a1, a2); \
01249 }
01250
01251 #define OV_BINOP_FN_OP(name, op) \
01252 OV_BINOP_FN (name) \
01253 OV_BINOP_OP (name, op)
01254
01255 OV_BINOP_FN_OP (op_add, +)
01256 OV_BINOP_FN_OP (op_sub, -)
01257 OV_BINOP_FN_OP (op_mul, *)
01258 OV_BINOP_FN_OP (op_div, /)
01259
01260 OV_BINOP_FN (op_pow)
01261 OV_BINOP_FN (op_ldiv)
01262 OV_BINOP_FN (op_lshift)
01263 OV_BINOP_FN (op_rshift)
01264
01265 OV_BINOP_FN_OP (op_lt, <)
01266 OV_BINOP_FN_OP (op_le, <=)
01267 OV_BINOP_FN_OP (op_eq, ==)
01268 OV_BINOP_FN_OP (op_ge, >=)
01269 OV_BINOP_FN_OP (op_gt, >)
01270 OV_BINOP_FN_OP (op_ne, !=)
01271
01272 OV_BINOP_FN (op_el_mul)
01273 OV_BINOP_FN (op_el_div)
01274 OV_BINOP_FN (op_el_pow)
01275 OV_BINOP_FN (op_el_ldiv)
01276 OV_BINOP_FN (op_el_and)
01277 OV_BINOP_FN (op_el_or)
01278
01279 OV_BINOP_FN (op_struct_ref)
01280
01281 #define OV_COMP_BINOP_FN(name) \
01282 inline octave_value \
01283 name (const octave_value& a1, const octave_value& a2) \
01284 { \
01285 return do_binary_op (octave_value::name, a1, a2); \
01286 }
01287
01288 OV_COMP_BINOP_FN (op_trans_mul)
01289 OV_COMP_BINOP_FN (op_mul_trans)
01290 OV_COMP_BINOP_FN (op_herm_mul)
01291 OV_COMP_BINOP_FN (op_mul_herm)
01292
01293 extern OCTINTERP_API void install_types (void);
01294
01295
01296
01297
01298
01299 #define OV_REP_TYPE octave_base_value
01300
01301
01302 template<class Value>
01303 inline Value octave_value_extract (const octave_value&)
01304 { assert (false); }
01305
01306 #define DEF_VALUE_EXTRACTOR(VALUE,MPREFIX) \
01307 template<> \
01308 inline VALUE octave_value_extract<VALUE> (const octave_value& v) \
01309 { return v.MPREFIX ## _value (); }
01310
01311 DEF_VALUE_EXTRACTOR (double, scalar)
01312 DEF_VALUE_EXTRACTOR (float, float_scalar)
01313 DEF_VALUE_EXTRACTOR (Complex, complex)
01314 DEF_VALUE_EXTRACTOR (FloatComplex, float_complex)
01315 DEF_VALUE_EXTRACTOR (bool, bool)
01316
01317 DEF_VALUE_EXTRACTOR (octave_int8, int8_scalar)
01318 DEF_VALUE_EXTRACTOR (octave_int16, int16_scalar)
01319 DEF_VALUE_EXTRACTOR (octave_int32, int32_scalar)
01320 DEF_VALUE_EXTRACTOR (octave_int64, int64_scalar)
01321 DEF_VALUE_EXTRACTOR (octave_uint8, uint8_scalar)
01322 DEF_VALUE_EXTRACTOR (octave_uint16, uint16_scalar)
01323 DEF_VALUE_EXTRACTOR (octave_uint32, uint32_scalar)
01324 DEF_VALUE_EXTRACTOR (octave_uint64, uint64_scalar)
01325
01326
01327 DEF_VALUE_EXTRACTOR (NDArray, array)
01328 DEF_VALUE_EXTRACTOR (FloatNDArray, float_array)
01329 DEF_VALUE_EXTRACTOR (ComplexNDArray, complex_array)
01330 DEF_VALUE_EXTRACTOR (FloatComplexNDArray, float_complex_array)
01331 DEF_VALUE_EXTRACTOR (boolNDArray, bool_array)
01332
01333 DEF_VALUE_EXTRACTOR (charNDArray, char_array)
01334 DEF_VALUE_EXTRACTOR (int8NDArray, int8_array)
01335 DEF_VALUE_EXTRACTOR (int16NDArray, int16_array)
01336 DEF_VALUE_EXTRACTOR (int32NDArray, int32_array)
01337 DEF_VALUE_EXTRACTOR (int64NDArray, int64_array)
01338 DEF_VALUE_EXTRACTOR (uint8NDArray, uint8_array)
01339 DEF_VALUE_EXTRACTOR (uint16NDArray, uint16_array)
01340 DEF_VALUE_EXTRACTOR (uint32NDArray, uint32_array)
01341 DEF_VALUE_EXTRACTOR (uint64NDArray, uint64_array)
01342
01343 DEF_VALUE_EXTRACTOR (Matrix, matrix)
01344 DEF_VALUE_EXTRACTOR (FloatMatrix, float_matrix)
01345 DEF_VALUE_EXTRACTOR (ComplexMatrix, complex_matrix)
01346 DEF_VALUE_EXTRACTOR (FloatComplexMatrix, float_complex_matrix)
01347 DEF_VALUE_EXTRACTOR (boolMatrix, bool_matrix)
01348
01349 DEF_VALUE_EXTRACTOR (ColumnVector, column_vector)
01350 DEF_VALUE_EXTRACTOR (FloatColumnVector, float_column_vector)
01351 DEF_VALUE_EXTRACTOR (ComplexColumnVector, complex_column_vector)
01352 DEF_VALUE_EXTRACTOR (FloatComplexColumnVector, float_complex_column_vector)
01353
01354 DEF_VALUE_EXTRACTOR (RowVector, row_vector)
01355 DEF_VALUE_EXTRACTOR (FloatRowVector, float_row_vector)
01356 DEF_VALUE_EXTRACTOR (ComplexRowVector, complex_row_vector)
01357 DEF_VALUE_EXTRACTOR (FloatComplexRowVector, float_complex_row_vector)
01358
01359 DEF_VALUE_EXTRACTOR (DiagMatrix, diag_matrix)
01360 DEF_VALUE_EXTRACTOR (FloatDiagMatrix, float_diag_matrix)
01361 DEF_VALUE_EXTRACTOR (ComplexDiagMatrix, complex_diag_matrix)
01362 DEF_VALUE_EXTRACTOR (FloatComplexDiagMatrix, float_complex_diag_matrix)
01363 DEF_VALUE_EXTRACTOR (PermMatrix, perm_matrix)
01364
01365 DEF_VALUE_EXTRACTOR (SparseMatrix, sparse_matrix)
01366 DEF_VALUE_EXTRACTOR (SparseComplexMatrix, sparse_complex_matrix)
01367 DEF_VALUE_EXTRACTOR (SparseBoolMatrix, sparse_bool_matrix)
01368 #undef DEF_VALUE_EXTRACTOR
01369
01370 #endif