fixed unwrap functions to simply cast from scalars (whatever type, through mxGetScalar)
parent
443d304a7c
commit
ab218f11d2
|
@ -46,14 +46,10 @@ mxArray *scalar(mxClassID classid) {
|
||||||
return mxCreateNumericArray(1, dims, classid, mxREAL);
|
return mxCreateNumericArray(1, dims, classid, mxREAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
mxArray *vector(int m, mxClassID classid) {
|
void checkScalar(const mxArray* array, const char* str) {
|
||||||
mwSize dims[1]; dims[0]=m;
|
int m = mxGetM(array), n = mxGetN(array);
|
||||||
return mxCreateNumericArray(1, dims, classid, mxREAL);
|
if (m!=1 || n!=1)
|
||||||
}
|
mexErrMsgIdAndTxt("wrap: not a scalar in ", str);
|
||||||
|
|
||||||
mxArray *matrix(int m, int n, mxClassID classid) {
|
|
||||||
mwSize dims[2]; dims[0]=m; dims[1]=n;
|
|
||||||
return mxCreateNumericArray(2, dims, mxUINT32OR64_CLASS, mxREAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
@ -84,8 +80,7 @@ mxArray* wrap<string>(string& value) {
|
||||||
return mxCreateString(value.c_str());
|
return mxCreateString(value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialization to bool -> uint32
|
// specialization to bool
|
||||||
// Warning: might rely on sizeof(UINT32_T)==sizeof(bool)
|
|
||||||
template<>
|
template<>
|
||||||
mxArray* wrap<bool>(bool& value) {
|
mxArray* wrap<bool>(bool& value) {
|
||||||
mxArray *result = scalar(mxUINT32OR64_CLASS);
|
mxArray *result = scalar(mxUINT32OR64_CLASS);
|
||||||
|
@ -93,8 +88,7 @@ mxArray* wrap<bool>(bool& value) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialization to size_t -> uint32
|
// specialization to size_t
|
||||||
// Warning: might rely on sizeof(UINT32_T)==sizeof(size_t)
|
|
||||||
template<>
|
template<>
|
||||||
mxArray* wrap<size_t>(size_t& value) {
|
mxArray* wrap<size_t>(size_t& value) {
|
||||||
mxArray *result = scalar(mxUINT32OR64_CLASS);
|
mxArray *result = scalar(mxUINT32OR64_CLASS);
|
||||||
|
@ -102,11 +96,10 @@ mxArray* wrap<size_t>(size_t& value) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialization to int -> uint32
|
// specialization to int
|
||||||
// Warning: might rely on sizeof(INT32_T)==sizeof(int)
|
|
||||||
template<>
|
template<>
|
||||||
mxArray* wrap<int>(int& value) {
|
mxArray* wrap<int>(int& value) {
|
||||||
mxArray *result = scalar(mxINT32_CLASS);
|
mxArray *result = scalar(mxUINT32OR64_CLASS);
|
||||||
*(int*)mxGetData(result) = value;
|
*(int*)mxGetData(result) = value;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -184,34 +177,31 @@ string unwrap<string>(const mxArray* array) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialization to bool
|
// specialization to bool
|
||||||
// returns a pointer to the array data itself
|
|
||||||
// Warning: relies on sizeof(UINT32_T)==sizeof(bool)
|
|
||||||
template<>
|
template<>
|
||||||
bool unwrap<bool>(const mxArray* array) {
|
bool unwrap<bool>(const mxArray* array) {
|
||||||
return *(bool*)mxGetData(array);
|
checkScalar(array,"unwrap<bool>");
|
||||||
|
return mxGetScalar(array) != 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialization to size_t
|
// specialization to size_t
|
||||||
// returns a pointer to the array data itself
|
|
||||||
// Warning: relies on sizeof(UINT32_T)==sizeof(size_t)
|
|
||||||
template<>
|
template<>
|
||||||
size_t unwrap<size_t>(const mxArray* array) {
|
size_t unwrap<size_t>(const mxArray* array) {
|
||||||
return *(size_t*)mxGetData(array);
|
checkScalar(array,"unwrap<size_t>");
|
||||||
|
return (size_t)mxGetScalar(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialization to int
|
// specialization to int
|
||||||
// returns a pointer to the array data itself
|
|
||||||
// Warning: relies on sizeof(INT32_T)==sizeof(int)
|
|
||||||
template<>
|
template<>
|
||||||
int unwrap<int>(const mxArray* array) {
|
int unwrap<int>(const mxArray* array) {
|
||||||
return *(int*)mxGetData(array);
|
checkScalar(array,"unwrap<int>");
|
||||||
|
return (int)mxGetScalar(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialization to double
|
// specialization to double
|
||||||
// returns a pointer to the array data itself
|
|
||||||
template<>
|
template<>
|
||||||
double unwrap<double>(const mxArray* array) {
|
double unwrap<double>(const mxArray* array) {
|
||||||
return *(double*)mxGetData(array);
|
checkScalar(array,"unwrap<double>");
|
||||||
|
return (double)mxGetScalar(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialization to BOOST vector
|
// specialization to BOOST vector
|
||||||
|
|
Loading…
Reference in New Issue