Audio Processing Framework (APF) version 0.5.0
Namespaces | Macros | Functions
mextools.h File Reference

Some tools for working with the MEX API for Matlab/Octave. More...

#include <mex.h>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include "apf/stringtools.h"

Go to the source code of this file.

Namespaces

namespace  apf
 Audio Processing Framework.
 
namespace  apf::mex
 Helper functions for creating MEX files.
 

Macros

#define APF_MEX_ERROR_NO_OUTPUT_SUPPORTED(name)
 
#define APF_MEX_ERROR_EXACTLY_ONE_OUTPUT(name)
 
#define APF_MEX_ERROR_ONE_OPTIONAL_OUTPUT(name)
 
#define APF_MEX_ERROR_NO_FURTHER_INPUTS(name)
 
#define APF_MEX_ERROR_FURTHER_INPUT_NEEDED(text)
 
#define APF_MEX_ERROR_NUMERIC_INPUT(text)
 
#define APF_MEX_ERROR_REAL_INPUT(text)
 
#define APF_MEX_ERROR_SAME_NUMBER_OF_ROWS(value, text)
 
#define APF_MEX_ERROR_SAME_NUMBER_OF_COLUMNS(value, text)
 

Functions

bool apf::mex::convert (const mxArray *in, std::string &out)
 Convert mxArray to std::string. More...
 
bool apf::mex::convert (const mxArray *in, double &out)
 Convert mxArray to double. More...
 
bool apf::mex::convert (const mxArray *in, int &out)
 Convert mxArray to int. More...
 
bool apf::mex::convert (const mxArray *in, long int &out)
 Convert mxArray to long int More...
 
bool apf::mex::convert (const mxArray *in, bool &out)
 Convert mxArray to bool. More...
 
bool apf::mex::convert (const mxArray *in, size_t &out)
 Convert mxArray to size_t. More...
 
bool apf::mex::convert (const mxArray *in, std::map< std::string, std::string > &out)
 Convert mxArray to a std::map of std::strings. More...
 
bool apf::mex::convert (const mxArray *in, std::vector< std::string > &out)
 Convert mxArray to a std::vector of std::strings. More...
 
template<bool optional, typename T >
bool apf::mex::internal::next_arg_helper (int &n, const mxArray **&p, T &data)
 
template<typename T >
bool apf::mex::next_arg (int &n, const mxArray **&p, T &data)
 Get next argument, converted to T. More...
 
template<typename T >
bool apf::mex::next_optarg (int &n, const mxArray **&p, T &data)
 Get next optional argument, converted to T. More...
 
template<typename T >
void apf::mex::next_arg (int &n, const mxArray **&p, T &data, const std::string &error)
 Get next argument, converted to T. More...
 
template<typename T >
void apf::mex::next_optarg (int &n, const mxArray **&p, T &data, const std::string &error)
 Get next optional argument, converted to T. More...
 

Detailed Description

Some tools for working with the MEX API for Matlab/Octave.

Definition in file mextools.h.

Macro Definition Documentation

◆ APF_MEX_ERROR_NO_OUTPUT_SUPPORTED

#define APF_MEX_ERROR_NO_OUTPUT_SUPPORTED (   name)
Value:
(void)plhs; \
if (nlhs > 0) { \
std::string msg("No output parameters are supported for " \
+ std::string(name) + "!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 41 of file mextools.h.

◆ APF_MEX_ERROR_EXACTLY_ONE_OUTPUT

#define APF_MEX_ERROR_EXACTLY_ONE_OUTPUT (   name)
Value:
(void)plhs; \
if (nlhs != 1) { \
std::string msg("Exactly one output parameter is supported for " \
+ std::string(name) + "!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 48 of file mextools.h.

◆ APF_MEX_ERROR_ONE_OPTIONAL_OUTPUT

#define APF_MEX_ERROR_ONE_OPTIONAL_OUTPUT (   name)
Value:
(void)plhs; \
if (nlhs > 1) { \
std::string msg("No more than one output parameter is supported for " \
+ std::string(name) + "!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 55 of file mextools.h.

◆ APF_MEX_ERROR_NO_FURTHER_INPUTS

#define APF_MEX_ERROR_NO_FURTHER_INPUTS (   name)
Value:
(void)prhs; \
if (nrhs > 0) { \
std::string msg("No further input parameters are supported for " \
+ std::string(name) + "!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 62 of file mextools.h.

◆ APF_MEX_ERROR_FURTHER_INPUT_NEEDED

#define APF_MEX_ERROR_FURTHER_INPUT_NEEDED (   text)
Value:
(void)prhs; \
if (nrhs < 1) { \
std::string msg(std::string(text) + " needs a further input parameter!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 69 of file mextools.h.

◆ APF_MEX_ERROR_NUMERIC_INPUT

#define APF_MEX_ERROR_NUMERIC_INPUT (   text)
Value:
(void)prhs; \
if (!mxIsNumeric(prhs[0])) { \
std::string msg(std::string(text) + " must be a numeric matrix!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 75 of file mextools.h.

◆ APF_MEX_ERROR_REAL_INPUT

#define APF_MEX_ERROR_REAL_INPUT (   text)
Value:
(void)prhs; \
APF_MEX_ERROR_NUMERIC_INPUT(text); \
if (mxIsComplex(prhs[0])) { \
std::string msg(std::string(text) + " must not be complex!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 81 of file mextools.h.

◆ APF_MEX_ERROR_SAME_NUMBER_OF_ROWS

#define APF_MEX_ERROR_SAME_NUMBER_OF_ROWS (   value,
  text 
)
Value:
(void)prhs; \
if (static_cast<mwSize>(mxGetM(prhs[0])) != (value)) { \
std::string msg("Number of rows must be the same " \
+ std::string(text) + "!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 88 of file mextools.h.

◆ APF_MEX_ERROR_SAME_NUMBER_OF_COLUMNS

#define APF_MEX_ERROR_SAME_NUMBER_OF_COLUMNS (   value,
  text 
)
Value:
(void)prhs; \
if (static_cast<mwSize>(mxGetN(prhs[0])) != (value)) { \
std::string msg("Number of columns must be the same " \
+ std::string(text) + "!"); \
mexErrMsgTxt(msg.c_str()); }

Definition at line 95 of file mextools.h.

Function Documentation

◆ next_arg_helper()

template<bool optional, typename T >
bool apf::mex::internal::next_arg_helper ( int &  n,
const mxArray **&  p,
T &  data 
)

Definition at line 243 of file mextools.h.