ivl 679
|
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>. 00002 A C++ template library extending syntax towards mathematical notation. 00003 00004 Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr> 00005 Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr> 00006 00007 ivl is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License 00009 version 3 as published by the Free Software Foundation. 00010 00011 Alternatively, you can redistribute it and/or modify it under the terms 00012 of the GNU General Public License version 2 as published by the Free 00013 Software Foundation. 00014 00015 ivl is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 See the GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 and a copy of the GNU Lesser General Public License along 00022 with ivl. If not, see <http://www.gnu.org/licenses/>. */ 00023 00024 #ifndef IVL_MX_HPP 00025 #define IVL_MX_HPP 00026 00027 #include <string> 00028 00029 #ifdef IVL_MATLAB 00030 00031 #include "mex.h" 00032 00033 namespace ivl { 00034 00035 typedef int MX_SIZE_T; 00036 00037 namespace mx { 00038 00039 inline void error(char* s) { mexErrMsgTxt(s); } 00040 00041 inline double scalar(const mxArray* a) { return mxGetScalar(a); } 00042 00043 std::string text(const mxArray* in) 00044 { MX_SIZE_T len, status; 00045 char* out; 00046 len = (int)(mxGetM(in) * mxGetN(in)) + 1; 00047 out = (char*)mxCalloc(len, sizeof(char)); 00048 status = mxGetString(in, out, len); 00049 if(status != 0) 00050 mexWarnMsgTxt("Not enough space. String is truncated."); 00051 return std::string(out); 00052 } 00053 00054 template<class T> 00055 inline 00056 mxClassID type_class() 00057 { 00058 return mxUNKNOWN_CLASS; 00059 } 00060 00061 template<> 00062 inline 00063 mxClassID type_class<double>() 00064 { 00065 return mxDOUBLE_CLASS; 00066 } 00067 00068 template<> 00069 inline 00070 mxClassID type_class<float>() 00071 { 00072 return mxSINGLE_CLASS; 00073 } 00074 00075 template<> 00076 inline 00077 mxClassID type_class<int8_t>() 00078 { 00079 return mxINT8_CLASS; 00080 } 00081 00082 template<> 00083 inline 00084 mxClassID type_class<uint8_t>() 00085 { 00086 return mxUINT8_CLASS; 00087 } 00088 00089 template<> 00090 inline 00091 mxClassID type_class<int16_t>() 00092 { 00093 return mxINT16_CLASS; 00094 } 00095 00096 template<> 00097 inline 00098 mxClassID type_class<uint16_t>() 00099 { 00100 return mxUINT16_CLASS; 00101 } 00102 00103 template<> 00104 inline 00105 mxClassID type_class<int32_t>() 00106 { 00107 return mxINT32_CLASS; 00108 } 00109 00110 } /* namespace mx */ 00111 } /* namespace ivl */ 00112 00113 #else 00114 00115 #if 0 00116 struct mxArray { 00117 }; 00118 00119 namespace ivl { 00120 00121 typedef int MX_SIZE_T; 00122 00123 namespace mx { 00124 00125 } /* namespace mx */ 00126 } /* namespace ivl */ 00127 #endif 00128 00129 #endif 00130 00131 #endif // IVL_MX_HPP