mexproto.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2006-2012 Paul Kienzle
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 /*
00024 
00025 This code was originally distributed as part of Octave Forge under
00026 the following terms:
00027 
00028 Author: Paul Kienzle
00029 I grant this code to the public domain.
00030 2001-03-22
00031 
00032 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00033 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00034 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00035 ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00036 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00037 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00038 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00039 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00040 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00041 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00042 SUCH DAMAGE.
00043 
00044 */
00045 
00046 /* mex.h is for use in C-programs only; do NOT include it in mex.cc */
00047 
00048 #if ! defined (MEXPROTO_H)
00049 #define MEXPROTO_H
00050 
00051 #if defined (__cplusplus)
00052 #include <cstdlib>
00053 extern "C" {
00054 #else
00055 #include <stdlib.h>
00056 #endif
00057 
00058 /* The definition of OCTINTERP_API is normally provided by Octave's
00059    config.h file.  This is provided for the case of mex.h included by
00060    user programs that don't use Octave's config.h.  */
00061 #if ! defined (OCTINTERP_API)
00062 #if defined (_MSC_VER)
00063 #define OCTINTERP_API __declspec(dllimport)
00064 #else
00065 /* All other compilers, at least for now.  */
00066 #define OCTINTERP_API
00067 #endif
00068 #endif
00069 
00070 #define MXARRAY_TYPEDEFS_ONLY
00071 #include "mxarray.h"
00072 #undef MXARRAY_TYPEDEFS_ONLY
00073 
00074 /* Interface to the interpreter.  */
00075 extern OCTINTERP_API const char *mexFunctionName (void);
00076 
00077 extern OCTINTERP_API int mexCallMATLAB (int nargout, mxArray *argout[], int nargin, mxArray *argin[], const char *fname);
00078 
00079 extern OCTINTERP_API void mexSetTrapFlag (int flag);
00080 extern OCTINTERP_API int mexEvalString (const char *s);
00081 extern OCTINTERP_API void mexErrMsgTxt (const char *s);
00082 extern OCTINTERP_API void mexErrMsgIdAndTxt (const char *id, const char *s, ...);
00083 extern OCTINTERP_API void mexWarnMsgTxt (const char *s);
00084 extern OCTINTERP_API void mexWarnMsgIdAndTxt (const char *id, const char *s, ...);
00085 extern OCTINTERP_API int mexPrintf (const char *fmt, ...);
00086 
00087 extern OCTINTERP_API mxArray *mexGetVariable (const char *space, const char *name);
00088 extern OCTINTERP_API const mxArray *mexGetVariablePtr (const char *space, const char *name);
00089 
00090 extern OCTINTERP_API int mexPutVariable (const char *space, const char *name, mxArray *ptr);
00091 
00092 extern OCTINTERP_API void mexMakeArrayPersistent (mxArray *ptr);
00093 extern OCTINTERP_API void mexMakeMemoryPersistent (void *ptr);
00094 
00095 extern OCTINTERP_API int mexAtExit (void (*f) (void));
00096 extern OCTINTERP_API const mxArray *mexGet (double handle, const char *property);
00097 extern OCTINTERP_API int mexIsGlobal (const mxArray *ptr);
00098 extern OCTINTERP_API int mexIsLocked (void);
00099 extern OCTINTERP_API void mexLock (void);
00100 extern OCTINTERP_API int mexSet (double handle, const char *property, mxArray *val);
00101 extern OCTINTERP_API void mexUnlock (void);
00102 
00103 /* Floating point predicates.  */
00104 extern OCTINTERP_API int mxIsFinite (double v);
00105 extern OCTINTERP_API int mxIsInf (double v);
00106 extern OCTINTERP_API int mxIsNaN (double v);
00107 
00108 /* Floating point values.  */
00109 extern OCTINTERP_API double mxGetEps (void);
00110 extern OCTINTERP_API double mxGetInf (void);
00111 extern OCTINTERP_API double mxGetNaN (void);
00112 
00113 /* Memory management.  */
00114 extern OCTINTERP_API void *mxCalloc (size_t n, size_t size);
00115 extern OCTINTERP_API void *mxMalloc (size_t n);
00116 extern OCTINTERP_API void *mxRealloc (void *ptr, size_t size);
00117 extern OCTINTERP_API void mxFree (void *ptr);
00118 
00119 /* Constructors.  */
00120 extern OCTINTERP_API mxArray *mxCreateCellArray (mwSize ndims, const mwSize *dims);
00121 extern OCTINTERP_API mxArray *mxCreateCellMatrix (mwSize m, mwSize n);
00122 extern OCTINTERP_API mxArray *mxCreateCharArray (mwSize ndims, const mwSize *dims);
00123 extern OCTINTERP_API mxArray *mxCreateCharMatrixFromStrings (mwSize m, const char **str);
00124 extern OCTINTERP_API mxArray *mxCreateDoubleMatrix (mwSize nr, mwSize nc, mxComplexity flag);
00125 extern OCTINTERP_API mxArray *mxCreateDoubleScalar (double val);
00126 extern OCTINTERP_API mxArray *mxCreateLogicalArray (mwSize ndims, const mwSize *dims);
00127 extern OCTINTERP_API mxArray *mxCreateLogicalMatrix (mwSize m, mwSize n);
00128 extern OCTINTERP_API mxArray *mxCreateLogicalScalar (mxLogical val);
00129 extern OCTINTERP_API mxArray *mxCreateNumericArray (mwSize ndims, const mwSize *dims, mxClassID class_id, mxComplexity flag);
00130 extern OCTINTERP_API mxArray *mxCreateNumericMatrix (mwSize m, mwSize n, mxClassID class_id, mxComplexity flag);
00131 extern OCTINTERP_API mxArray *mxCreateSparse (mwSize m, mwSize n, mwSize nzmax, mxComplexity flag);
00132 extern OCTINTERP_API mxArray *mxCreateSparseLogicalMatrix (mwSize m, mwSize n, mwSize nzmax);
00133 extern OCTINTERP_API mxArray *mxCreateString (const char *str);
00134 extern OCTINTERP_API mxArray *mxCreateStructArray (mwSize ndims, const mwSize *dims, int num_keys, const char **keys);
00135 extern OCTINTERP_API mxArray *mxCreateStructMatrix (mwSize rows, mwSize cols, int num_keys, const char **keys);
00136 
00137 /* Copy constructor.  */
00138 extern OCTINTERP_API mxArray *mxDuplicateArray (const mxArray *v);
00139 
00140 /* Destructor.  */
00141 extern OCTINTERP_API void mxDestroyArray (mxArray *v);
00142 
00143 /* Type Predicates.  */
00144 extern OCTINTERP_API int mxIsCell (const mxArray *ptr);
00145 extern OCTINTERP_API int mxIsChar (const mxArray *ptr);
00146 extern OCTINTERP_API int mxIsClass (const mxArray *ptr, const char *name);
00147 extern OCTINTERP_API int mxIsComplex (const mxArray *ptr);
00148 extern OCTINTERP_API int mxIsDouble (const mxArray *ptr);
00149 extern OCTINTERP_API int mxIsFunctionHandle (const mxArray *ptr);
00150 extern OCTINTERP_API int mxIsInt16 (const mxArray *ptr);
00151 extern OCTINTERP_API int mxIsInt32 (const mxArray *ptr);
00152 extern OCTINTERP_API int mxIsInt64 (const mxArray *ptr);
00153 extern OCTINTERP_API int mxIsInt8 (const mxArray *ptr);
00154 extern OCTINTERP_API int mxIsLogical (const mxArray *ptr);
00155 extern OCTINTERP_API int mxIsNumeric (const mxArray *ptr);
00156 extern OCTINTERP_API int mxIsSingle (const mxArray *ptr);
00157 extern OCTINTERP_API int mxIsSparse (const mxArray *ptr);
00158 extern OCTINTERP_API int mxIsStruct (const mxArray *ptr);
00159 extern OCTINTERP_API int mxIsUint16 (const mxArray *ptr);
00160 extern OCTINTERP_API int mxIsUint32 (const mxArray *ptr);
00161 extern OCTINTERP_API int mxIsUint64 (const mxArray *ptr);
00162 extern OCTINTERP_API int mxIsUint8 (const mxArray *ptr);
00163 
00164 /* Odd type+size predicate.  */
00165 extern OCTINTERP_API int mxIsLogicalScalar (const mxArray *ptr);
00166 
00167 /* Odd type+size+value predicate.  */
00168 extern OCTINTERP_API int mxIsLogicalScalarTrue (const mxArray *ptr);
00169 
00170 /* Size predicate.  */
00171 extern OCTINTERP_API int mxIsEmpty (const mxArray *ptr);
00172 
00173 /* Just plain odd thing to ask of a value.  */
00174 extern OCTINTERP_API int mxIsFromGlobalWS (const mxArray *ptr);
00175 
00176 /* Dimension extractors.  */
00177 extern OCTINTERP_API size_t mxGetM (const mxArray *ptr);
00178 extern OCTINTERP_API size_t mxGetN (const mxArray *ptr);
00179 extern OCTINTERP_API mwSize *mxGetDimensions (const mxArray *ptr);
00180 extern OCTINTERP_API mwSize mxGetNumberOfDimensions (const mxArray *ptr);
00181 extern OCTINTERP_API size_t mxGetNumberOfElements (const mxArray *ptr);
00182 
00183 /* Dimension setters.  */
00184 extern OCTINTERP_API void mxSetM (mxArray *ptr, mwSize M);
00185 extern OCTINTERP_API void mxSetN (mxArray *ptr, mwSize N);
00186 extern OCTINTERP_API void mxSetDimensions (mxArray *ptr, const mwSize *dims, mwSize ndims);
00187 
00188 /* Data extractors.  */
00189 extern OCTINTERP_API double *mxGetPi (const mxArray *ptr);
00190 extern OCTINTERP_API double *mxGetPr (const mxArray *ptr);
00191 extern OCTINTERP_API double mxGetScalar (const mxArray *ptr);
00192 extern OCTINTERP_API mxChar *mxGetChars (const mxArray *ptr);
00193 extern OCTINTERP_API mxLogical *mxGetLogicals (const mxArray *ptr);
00194 extern OCTINTERP_API void *mxGetData (const mxArray *ptr);
00195 extern OCTINTERP_API void *mxGetImagData (const mxArray *ptr);
00196 
00197 /* Data setters.  */
00198 extern OCTINTERP_API void mxSetPr (mxArray *ptr, double *pr);
00199 extern OCTINTERP_API void mxSetPi (mxArray *ptr, double *pi);
00200 extern OCTINTERP_API void mxSetData (mxArray *ptr, void *data);
00201 extern OCTINTERP_API void mxSetImagData (mxArray *ptr, void *pi);
00202 
00203 /* Classes.  */
00204 extern OCTINTERP_API mxClassID mxGetClassID (const mxArray *ptr);
00205 extern OCTINTERP_API const char *mxGetClassName (const mxArray *ptr);
00206 
00207 extern OCTINTERP_API void mxSetClassName (mxArray *ptr, const char *name);
00208 
00209 /* Cell support.  */
00210 extern OCTINTERP_API mxArray *mxGetCell (const mxArray *ptr, mwIndex idx);
00211 
00212 extern OCTINTERP_API void mxSetCell (mxArray *ptr, mwIndex idx, mxArray *val);
00213 
00214 /* Sparse support.  */
00215 extern OCTINTERP_API mwIndex *mxGetIr (const mxArray *ptr);
00216 extern OCTINTERP_API mwIndex *mxGetJc (const mxArray *ptr);
00217 extern OCTINTERP_API mwSize mxGetNzmax (const mxArray *ptr);
00218 
00219 extern OCTINTERP_API void mxSetIr (mxArray *ptr, mwIndex *ir);
00220 extern OCTINTERP_API void mxSetJc (mxArray *ptr, mwIndex *jc);
00221 extern OCTINTERP_API void mxSetNzmax (mxArray *ptr, mwSize nzmax);
00222 
00223 /* Structure support.  */
00224 extern OCTINTERP_API int mxAddField (mxArray *ptr, const char *key);
00225 
00226 extern OCTINTERP_API void mxRemoveField (mxArray *ptr, int key_num);
00227 
00228 extern OCTINTERP_API mxArray *mxGetField (const mxArray *ptr, mwIndex index, const char *key);
00229 extern OCTINTERP_API mxArray *mxGetFieldByNumber (const mxArray *ptr, mwIndex index, int key_num);
00230 
00231 extern OCTINTERP_API void mxSetField (mxArray *ptr, mwIndex index, const char *key, mxArray *val);
00232 extern OCTINTERP_API void mxSetFieldByNumber (mxArray *ptr, mwIndex index, int key_num, mxArray *val);
00233 
00234 extern OCTINTERP_API int mxGetNumberOfFields (const mxArray *ptr);
00235 
00236 extern OCTINTERP_API const char *mxGetFieldNameByNumber (const mxArray *ptr, int key_num);
00237 extern OCTINTERP_API int mxGetFieldNumber (const mxArray *ptr, const char *key);
00238 
00239 extern OCTINTERP_API int mxGetString (const mxArray *ptr, char *buf, mwSize buflen);
00240 extern OCTINTERP_API char *mxArrayToString (const mxArray *ptr);
00241 
00242 /* Miscellaneous.  */
00243 #ifdef NDEBUG
00244 #define mxAssert(expr, msg) \
00245   do \
00246     { \
00247       if (! expr) \
00248         { \
00249           mexPrintf ("Assertion failed: %s, at line %d of file \"%s\".\n%s\n", \
00250                      #expr, __LINE__, __FILE__, msg); \
00251         } \
00252     } \
00253   while (0)
00254 
00255 #define mxAssertS(expr, msg) \
00256   do \
00257     { \
00258       if (! expr) \
00259         { \
00260           mexPrintf ("Assertion failed at line %d of file \"%s\".\n%s\n", \
00261                      __LINE__, __FILE__, msg); \
00262           abort (); \
00263         } \
00264     } \
00265   while (0)
00266 #else
00267 #define mxAssert(expr, msg)
00268 #define mxAssertS(expr, msg)
00269 #endif
00270 
00271 extern OCTINTERP_API mwIndex mxCalcSingleSubscript (const mxArray *ptr, mwSize nsubs, mwIndex *subs);
00272 
00273 extern OCTINTERP_API size_t mxGetElementSize (const mxArray *ptr);
00274 
00275 #if defined (__cplusplus)
00276 }
00277 #endif
00278 
00279 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines