Mercurial > hg > octave-nkf
changeset 6332:debb662eab07
[project @ 2007-02-20 20:41:35 by jwe]
author | jwe |
---|---|
date | Tue, 20 Feb 2007 20:41:35 +0000 |
parents | 9e3e58d914ca |
children | 4e81fe3bceff |
files | src/ChangeLog src/mex.cc src/mxarray.h |
diffstat | 3 files changed, 89 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2007-02-20 John W. Eaton <jwe@octave.org> + + * mxarray.h (mxArray::get_scalar): New function. + * mex.cc (mxArray_base::get_scalar): New pure virtual function. + (mxArray_octave_value::get_scalar, mxArray_matlab::get_scalar, + mxArray_number::get_scalar): New functions. + (mxGetScalar): Call get_scalar here. + + * mex.cc (mxArray_octave_value::get_dimensions): Cache ndims here. + (mxArray_octave_value::get_number_of_dimensions): + Call get_dimensions here to cache both ndims and dims. + 2007-02-17 John W. Eaton <jwe@octave.org> * variables.cc (symbol_out_of_date): Don't exit early if looking
--- a/src/mex.cc +++ b/src/mex.cc @@ -182,6 +182,8 @@ void set_cell (int idx, mxArray *val) = 0; + double get_scalar (void) const = 0; + void *get_data (void) const = 0; void *get_imag_data (void) const = 0; @@ -337,8 +339,7 @@ { if (! dims) { - // Force ndims to be cached. - get_number_of_dimensions (); + ndims = val.ndims (); dims = static_cast<int *> (malloc (ndims * sizeof (int))); @@ -353,8 +354,8 @@ int get_number_of_dimensions (void) const { - if (ndims < 0) - ndims = val.ndims (); + // Force dims and ndims to be cached. + get_dimensions (); return ndims; } @@ -442,6 +443,8 @@ // Not allowed. void set_cell (int /*idx*/, mxArray */*val*/) { panic_impossible (); } + double get_scalar (void) const { return val.scalar_value (true); } + void *get_data (void) const { void *retval = 0; @@ -871,6 +874,12 @@ invalid_type_error (); } + double get_scalar (void) const + { + invalid_type_error (); + return 0; + } + void *get_data (void) const { invalid_type_error (); @@ -1141,6 +1150,67 @@ int is_complex (void) const { return pi != 0; } + double get_scalar (void) const + { + double retval = 0; + + switch (get_class_id ()) + { + case mxLOGICAL_CLASS: + retval = *(static_cast<bool *> (pr)); + break; + + case mxCHAR_CLASS: + retval = *(static_cast<mxChar *> (pr)); + break; + + case mxSINGLE_CLASS: + retval = *(static_cast<float *> (pr)); + break; + + case mxDOUBLE_CLASS: + retval = *(static_cast<double *> (pr)); + break; + + case mxINT8_CLASS: + retval = *(static_cast<int8_t *> (pr)); + break; + + case mxUINT8_CLASS: + retval = *(static_cast<uint8_t *> (pr)); + break; + + case mxINT16_CLASS: + retval = *(static_cast<int16_t *> (pr)); + break; + + case mxUINT16_CLASS: + retval = *(static_cast<uint16_t *> (pr)); + break; + + case mxINT32_CLASS: + retval = *(static_cast<int32_t *> (pr)); + break; + + case mxUINT32_CLASS: + retval = *(static_cast<uint32_t *> (pr)); + break; + + case mxINT64_CLASS: + retval = *(static_cast<int64_t *> (pr)); + break; + + case mxUINT64_CLASS: + retval = *(static_cast<uint64_t *> (pr)); + break; + + default: + panic_impossible (); + } + + return retval; + } + void *get_data (void) const { return pr; } void *get_imag_data (void) const { return pi; } @@ -2665,8 +2735,7 @@ double mxGetScalar (const mxArray *ptr) { - double *d = mxGetPr (ptr); - return d[0]; + return ptr->get_scalar (); } mxChar *
--- a/src/mxarray.h +++ b/src/mxarray.h @@ -236,6 +236,8 @@ virtual void set_cell (int idx, mxArray *val) { DO_VOID_MUTABLE_METHOD (set_cell (idx, val)); } + virtual double get_scalar (void) const { return rep->get_scalar (); } + virtual void *get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); } virtual void *get_imag_data (void) const { DO_MUTABLE_METHOD (void *, get_imag_data ()); }