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:
parent
d3f31a5f83
commit
3f23fbdeab
|
@ -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 {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue