libiir++: add further std::vector<> interfaces

In addition to C-style pointer-to-array and size arguments, allow for
C++-style std::vector<> interfaces. This also integrates nicely with
swig and allows the Python bindings to use native lists/tuples.
This commit is contained in:
Laurence Withers 2014-07-10 08:27:08 +00:00
parent d3f31a5f83
commit 3f23fbdeab
3 changed files with 27 additions and 0 deletions

View File

@ -16,6 +16,7 @@
#include "iir++.h" #include "iir++.h"
// Below are all the includes used throughout the library. // Below are all the includes used throughout the library.
#include <alloca.h>
#include <stdlib.h> #include <stdlib.h>
namespace IIR { namespace IIR {

View File

@ -14,6 +14,24 @@ Coeff::Coeff(int nc, const double* c, int nd, const double* d)
Coeff::Coeff(const std::vector<double>& c, const std::vector<double>& d)
{
int nc, nd;
double* ac, * ad;
nc = c.size();
ac = static_cast<double*>(alloca(nc * sizeof(double)));
for(int i = 0; i < nc; ++i) ac[i] = c[i];
nd = d.size();
ad = static_cast<double*>(alloca(nd * sizeof(double)));
for(int i = 0; i < nd; ++i) ad[i] = d[i];
cc_ = iir_coeff_new(nc, ac, nd, ad);
}
Coeff::Coeff(const struct iir_coeff_t* cc) Coeff::Coeff(const struct iir_coeff_t* cc)
{ {
cc_ = iir_coeff_copy(cc); cc_ = iir_coeff_copy(cc);

View File

@ -39,6 +39,14 @@ public:
*/ */
Coeff(int nc, const double* c, int nd, const double* d); Coeff(int nc, const double* c, int nd, const double* d);
/*! \brief Constructor with raw coefficients.
\param c Array of \a c coefficients, size 1.
\param d Array of \a d coefficients, size 1.
*/
Coeff(const std::vector<double>& c, const std::vector<double>& d);
/*! \brief Constructor from C library object. /*! \brief Constructor from C library object.
\param cc Pointer to existing coefficient object. \param cc Pointer to existing coefficient object.