~ubuntu-branches/ubuntu/vivid/soundscaperenderer/vivid-proposed

« back to all changes in this revision

Viewing changes to apf/apf/mextools.h

  • Committer: Package Import Robot
  • Author(s): IOhannes m zmölnig (Debian/GNU)
  • Date: 2014-09-01 11:35:32 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140901113532-svjohhyw755nkxef
Tags: 0.4.2~dfsg-1
* Imported Upstream version 0.4.2~dfsg

* Refreshed patches.
* Removed patches applied upstream.
* Install upstream's NEWS as changelog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
      + std::string(name) + "!"); \
49
49
  mexErrMsgTxt(msg.c_str()); }
50
50
 
 
51
#define APF_MEX_ERROR_ONE_OPTIONAL_OUTPUT(name) \
 
52
(void)plhs; \
 
53
if (nlhs > 1) { \
 
54
  std::string msg("No more than one output parameter is supported for " \
 
55
      + std::string(name) + "!"); \
 
56
  mexErrMsgTxt(msg.c_str()); }
 
57
 
51
58
#define APF_MEX_ERROR_NO_FURTHER_INPUTS(name) \
52
59
(void)prhs; \
53
60
if (nrhs > 0) { \
90
97
 
91
98
namespace apf
92
99
{
 
100
/// Helper functions for creating MEX files
93
101
namespace mex
94
102
{
95
103
 
96
104
// TODO: check if (and how) user-specified overloads of convert() work
97
105
// TODO: use a traits class, if necessary
98
106
 
 
107
/// Convert @c mxArray to @c std::string
99
108
bool convert(const mxArray* in, std::string& out)
100
109
{
101
110
  if (!mxIsChar(in)) return false;
107
116
  return true;
108
117
}
109
118
 
 
119
/// Convert @c mxArray to @c double
110
120
bool convert(const mxArray* in, double& out)
111
121
{
112
122
  if (!mxIsDouble(in) || mxIsComplex(in)) return false;
115
125
  return true;
116
126
}
117
127
 
 
128
/// Convert @c mxArray to @c int
118
129
bool convert(const mxArray* in, int& out)
119
130
{
120
131
  if (!mxIsDouble(in) || mxIsComplex(in)) return false;
125
136
  return true;
126
137
}
127
138
 
 
139
/// Convert @c mxArray to @c size_t
128
140
bool convert(const mxArray* in, size_t& out)
129
141
{
130
142
  if (!mxIsDouble(in) || mxIsComplex(in)) return false;
135
147
  return true;
136
148
}
137
149
 
 
150
/// Convert @c mxArray to a @c std::map of @c std::string%s.
 
151
/// This expects a scalar structure!
 
152
/// Values must be real scalar numbers or strings!
 
153
/// @warning In case of a conversion error, the map may be partially filled!
138
154
// TODO: allow wstring?
139
 
// This expects a scalar structure!
140
 
// Values must be real scalar numbers or strings!
141
 
// WARNING: In case of a conversion error, the map may be partly filled!
142
155
bool convert(const mxArray* in, std::map<std::string, std::string>& out)
143
156
{
144
157
  if (!mxIsStruct(in)) return false;
185
198
 
186
199
}  // namespace internal
187
200
 
 
201
/// Get next argument, converted to @p T.
 
202
/// @param n Number of arguments, typically @c nrhs
 
203
/// @param p Pointer to arguments, typically @c prhs
 
204
/// @return @b true if argument was available and if conversion was successful
 
205
/// @post @p n is decremented, @p p is incremented
188
206
template<typename T>
189
207
bool next_arg(int& n, const mxArray**& p, T& data)
190
208
{
191
209
  return internal::next_arg_helper<false>(n, p, data);
192
210
}
193
211
 
 
212
/// Get next optional argument, converted to @p T.
 
213
/// @return @b true if no argument available or if conversion was successful
 
214
/// @see next_arg()
194
215
template<typename T>
195
216
bool next_optarg(int& n, const mxArray**& p, T& data)
196
217
{
197
218
  return internal::next_arg_helper<true>(n, p, data);
198
219
}
199
220
 
 
221
/// Get next argument, converted to @p T.
 
222
/// @see next_arg()
 
223
/// @param error Message to be displayed on error
200
224
template<typename T>
201
225
void next_arg(int& n, const mxArray**& p, T& data, const std::string& error)
202
226
{
203
227
  if (!next_arg(n, p, data)) mexErrMsgTxt(error.c_str());
204
228
}
205
229
 
 
230
/// Get next optional argument, converted to @p T.
 
231
/// @see next_optarg()
 
232
/// @param error Message to be displayed on error
206
233
template<typename T>
207
234
void next_optarg(int& n, const mxArray**& p, T& data, const std::string& error)
208
235
{