00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #if ! defined (MXARRAY_H)
00047 #define MXARRAY_H
00048
00049 typedef enum
00050 {
00051 mxREAL = 0,
00052 mxCOMPLEX = 1
00053 }
00054 mxComplexity;
00055
00056 typedef enum
00057 {
00058 mxUNKNOWN_CLASS = 0,
00059 mxCELL_CLASS,
00060 mxSTRUCT_CLASS,
00061 mxLOGICAL_CLASS,
00062 mxCHAR_CLASS,
00063 mxUNUSED_CLASS,
00064 mxDOUBLE_CLASS,
00065 mxSINGLE_CLASS,
00066 mxINT8_CLASS,
00067 mxUINT8_CLASS,
00068 mxINT16_CLASS,
00069 mxUINT16_CLASS,
00070 mxINT32_CLASS,
00071 mxUINT32_CLASS,
00072 mxINT64_CLASS,
00073 mxUINT64_CLASS,
00074 mxFUNCTION_CLASS
00075 }
00076 mxClassID;
00077
00078 typedef unsigned char mxLogical;
00079
00080
00081 typedef char mxChar;
00082
00083
00084
00085
00086
00087
00088 typedef int mwSize;
00089 typedef int mwIndex;
00090
00091 #if ! defined (MXARRAY_TYPEDEFS_ONLY)
00092
00093 #include <cstring>
00094
00095 class octave_value;
00096
00097 #define DO_MUTABLE_METHOD(RET_T, METHOD_CALL) \
00098 RET_T retval = rep->METHOD_CALL; \
00099 \
00100 if (rep->mutation_needed ()) \
00101 { \
00102 maybe_mutate (); \
00103 retval = rep->METHOD_CALL; \
00104 } \
00105 \
00106 return retval
00107
00108 #define DO_VOID_MUTABLE_METHOD(METHOD_CALL) \
00109 rep->METHOD_CALL; \
00110 \
00111 if (rep->mutation_needed ()) \
00112 { \
00113 maybe_mutate (); \
00114 rep->METHOD_CALL; \
00115 }
00116
00117
00118
00119
00120 struct
00121 xmxArray
00122 {
00123 xmxArray (void) { }
00124 };
00125
00126
00127
00128
00129
00130 class mxArray
00131 {
00132 public:
00133
00134 mxArray (const octave_value& ov);
00135
00136 mxArray (mxClassID id, mwSize ndims, const mwSize *dims,
00137 mxComplexity flag = mxREAL);
00138
00139 mxArray (mxClassID id, const dim_vector& dv, mxComplexity flag = mxREAL);
00140
00141 mxArray (mxClassID id, mwSize m, mwSize n, mxComplexity flag = mxREAL);
00142
00143 mxArray (mxClassID id, double val);
00144
00145 mxArray (mxClassID id, mxLogical val);
00146
00147 mxArray (const char *str);
00148
00149 mxArray (mwSize m, const char **str);
00150
00151 mxArray (mxClassID id, mwSize m, mwSize n, mwSize nzmax,
00152 mxComplexity flag = mxREAL);
00153
00154 mxArray (mwSize ndims, const mwSize *dims, int num_keys, const char **keys);
00155
00156 mxArray (const dim_vector& dv, int num_keys, const char **keys);
00157
00158 mxArray (mwSize m, mwSize n, int num_keys, const char **keys);
00159
00160 mxArray (mwSize ndims, const mwSize *dims);
00161
00162 mxArray (const dim_vector& dv);
00163
00164 mxArray (mwSize m, mwSize n);
00165
00166 virtual mxArray *clone (void) const
00167 {
00168 mxArray *new_rep = rep->clone ();
00169
00170 return new mxArray (new_rep, name);
00171 }
00172
00173 virtual ~mxArray (void);
00174
00175 virtual bool is_octave_value (void) const { return rep->is_octave_value (); }
00176
00177 virtual int is_cell (void) const { return rep->is_cell (); }
00178
00179 virtual int is_char (void) const { return rep->is_char (); }
00180
00181 virtual int is_class (const char *name_arg) const { return rep->is_class (name_arg); }
00182
00183 virtual int is_complex (void) const { return rep->is_complex (); }
00184
00185 virtual int is_double (void) const { return rep->is_double (); }
00186
00187 virtual int is_int16 (void) const { return rep->is_int16 (); }
00188
00189 virtual int is_int32 (void) const { return rep->is_int32 (); }
00190
00191 virtual int is_int64 (void) const { return rep->is_int64 (); }
00192
00193 virtual int is_int8 (void) const { return rep->is_int8 (); }
00194
00195 virtual int is_logical (void) const { return rep->is_logical (); }
00196
00197 virtual int is_numeric (void) const { return rep->is_numeric (); }
00198
00199 virtual int is_single (void) const { return rep->is_single (); }
00200
00201 virtual int is_sparse (void) const { return rep->is_sparse (); }
00202
00203 virtual int is_struct (void) const { return rep->is_struct (); }
00204
00205 virtual int is_uint16 (void) const { return rep->is_uint16 (); }
00206
00207 virtual int is_uint32 (void) const { return rep->is_uint32 (); }
00208
00209 virtual int is_uint64 (void) const { return rep->is_uint64 (); }
00210
00211 virtual int is_uint8 (void) const { return rep->is_uint8 (); }
00212
00213 virtual int is_logical_scalar (void) const { return rep->is_logical_scalar (); }
00214
00215 virtual int is_logical_scalar_true (void) const { return rep->is_logical_scalar_true (); }
00216
00217 virtual mwSize get_m (void) const { return rep->get_m (); }
00218
00219 virtual mwSize get_n (void) const { return rep->get_n (); }
00220
00221 virtual mwSize *get_dimensions (void) const { return rep->get_dimensions (); }
00222
00223 virtual mwSize get_number_of_dimensions (void) const { return rep->get_number_of_dimensions (); }
00224
00225 virtual void set_m (mwSize m) { DO_VOID_MUTABLE_METHOD (set_m (m)); }
00226
00227 virtual void set_n (mwSize n) { DO_VOID_MUTABLE_METHOD (set_n (n)); }
00228
00229 virtual void set_dimensions (mwSize *dims_arg, mwSize ndims_arg) { DO_VOID_MUTABLE_METHOD (set_dimensions (dims_arg, ndims_arg)); }
00230
00231 virtual mwSize get_number_of_elements (void) const { return rep->get_number_of_elements (); }
00232
00233 virtual int is_empty (void) const { return get_number_of_elements () == 0; }
00234
00235 const char *get_name (void) const { return name; }
00236
00237 void set_name (const char *name_arg);
00238
00239 virtual mxClassID get_class_id (void) const { return rep->get_class_id (); }
00240
00241 virtual const char *get_class_name (void) const { return rep->get_class_name (); }
00242
00243 virtual void set_class_name (const char *name_arg) { DO_VOID_MUTABLE_METHOD (set_class_name (name_arg)); }
00244
00245 virtual mxArray *get_cell (mwIndex idx) const { DO_MUTABLE_METHOD (mxArray *, get_cell (idx)); }
00246
00247 virtual void set_cell (mwIndex idx, mxArray *val) { DO_VOID_MUTABLE_METHOD (set_cell (idx, val)); }
00248
00249 virtual double get_scalar (void) const { return rep->get_scalar (); }
00250
00251 virtual void *get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); }
00252
00253 virtual void *get_imag_data (void) const { DO_MUTABLE_METHOD (void *, get_imag_data ()); }
00254
00255 virtual void set_data (void *pr) { DO_VOID_MUTABLE_METHOD (set_data (pr)); }
00256
00257 virtual void set_imag_data (void *pi) { DO_VOID_MUTABLE_METHOD (set_imag_data (pi)); }
00258
00259 virtual mwIndex *get_ir (void) const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); }
00260
00261 virtual mwIndex *get_jc (void) const { DO_MUTABLE_METHOD (mwIndex *, get_jc ()); }
00262
00263 virtual mwSize get_nzmax (void) const { return rep->get_nzmax (); }
00264
00265 virtual void set_ir (mwIndex *ir) { DO_VOID_MUTABLE_METHOD (set_ir (ir)); }
00266
00267 virtual void set_jc (mwIndex *jc) { DO_VOID_MUTABLE_METHOD (set_jc (jc)); }
00268
00269 virtual void set_nzmax (mwSize nzmax) { DO_VOID_MUTABLE_METHOD (set_nzmax (nzmax)); }
00270
00271 virtual int add_field (const char *key) { DO_MUTABLE_METHOD (int, add_field (key)); }
00272
00273 virtual void remove_field (int key_num) { DO_VOID_MUTABLE_METHOD (remove_field (key_num)); }
00274
00275 virtual mxArray *get_field_by_number (mwIndex index, int key_num) const { DO_MUTABLE_METHOD (mxArray *, get_field_by_number (index, key_num)); }
00276
00277 virtual void set_field_by_number (mwIndex index, int key_num, mxArray *val) { DO_VOID_MUTABLE_METHOD (set_field_by_number (index, key_num, val)); }
00278
00279 virtual int get_number_of_fields (void) const { return rep->get_number_of_fields (); }
00280
00281 virtual const char *get_field_name_by_number (int key_num) const { DO_MUTABLE_METHOD (const char*, get_field_name_by_number (key_num)); }
00282
00283 virtual int get_field_number (const char *key) const { DO_MUTABLE_METHOD (int, get_field_number (key)); }
00284
00285 virtual int get_string (char *buf, mwSize buflen) const { return rep->get_string (buf, buflen); }
00286
00287 virtual char *array_to_string (void) const { return rep->array_to_string (); }
00288
00289 virtual mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const { return rep->calc_single_subscript (nsubs, subs); }
00290
00291 virtual size_t get_element_size (void) const { return rep->get_element_size (); }
00292
00293 virtual bool mutation_needed (void) const { return rep->mutation_needed (); }
00294
00295 virtual mxArray *mutate (void) const { return rep->mutate (); }
00296
00297 static void *malloc (size_t n);
00298
00299 static void *calloc (size_t n, size_t t);
00300
00301 static char *strsave (const char *str)
00302 {
00303 char *retval = 0;
00304
00305 if (str)
00306 {
00307 mwSize sz = sizeof (mxChar) * (strlen (str) + 1);
00308 retval = static_cast<char *> (mxArray::malloc (sz));
00309 strcpy (retval, str);
00310 }
00311
00312 return retval;
00313 }
00314
00315 static octave_value as_octave_value (mxArray *ptr);
00316
00317 protected:
00318
00319 virtual octave_value as_octave_value (void) const;
00320
00321 mxArray (const xmxArray&) : rep (0), name (0) { }
00322
00323 private:
00324
00325 mutable mxArray *rep;
00326
00327 char *name;
00328
00329 mxArray (mxArray *r, const char *n)
00330 : rep (r), name (strsave (n)) { }
00331
00332 void maybe_mutate (void) const;
00333
00334
00335
00336 mxArray (const mxArray&);
00337
00338 mxArray& operator = (const mxArray&);
00339 };
00340
00341 #undef DO_MUTABLE_METHOD
00342 #undef DO_VOID_MUTABLE_METHOD
00343
00344 #endif
00345 #endif