From 3f23fbdeab8d4115c199f5d545b2533ced9a496b Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Thu, 10 Jul 2014 08:27:08 +0000 Subject: [PATCH] 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. --- src/libiir++/000_TopSource.cc | 1 + src/libiir++/100_Coeff.cc | 18 ++++++++++++++++++ src/libiir++/100_Coeff.h | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/src/libiir++/000_TopSource.cc b/src/libiir++/000_TopSource.cc index f6b2040..bd47320 100644 --- a/src/libiir++/000_TopSource.cc +++ b/src/libiir++/000_TopSource.cc @@ -16,6 +16,7 @@ #include "iir++.h" // Below are all the includes used throughout the library. +#include #include namespace IIR { diff --git a/src/libiir++/100_Coeff.cc b/src/libiir++/100_Coeff.cc index 1b58089..7036c2c 100644 --- a/src/libiir++/100_Coeff.cc +++ b/src/libiir++/100_Coeff.cc @@ -14,6 +14,24 @@ Coeff::Coeff(int nc, const double* c, int nd, const double* d) +Coeff::Coeff(const std::vector& c, const std::vector& d) +{ + int nc, nd; + double* ac, * ad; + + nc = c.size(); + ac = static_cast(alloca(nc * sizeof(double))); + for(int i = 0; i < nc; ++i) ac[i] = c[i]; + + nd = d.size(); + ad = static_cast(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) { cc_ = iir_coeff_copy(cc); diff --git a/src/libiir++/100_Coeff.h b/src/libiir++/100_Coeff.h index 64f37d5..8a3dbf0 100644 --- a/src/libiir++/100_Coeff.h +++ b/src/libiir++/100_Coeff.h @@ -39,6 +39,14 @@ public: */ 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& c, const std::vector& d); + /*! \brief Constructor from C library object. \param cc Pointer to existing coefficient object.