Mercurial > hg > audiodb
view nearestaccumulator.h @ 489:4cb6c611f812 api-inversion
Begin removing uses of audiodb_query()
audiodb_query() is actually an unsupportable interface. It requires
access to the filesystem, does not (and cannot) actually support whole
swathes of functionality, is only implementable using code that is no
longer part of the core of audioDB (reporter.h), is in the way of fixing
memory leaks in the SOAP server, and is horrible to use to boot.
So, begin converting the libtests uses of audiodb_query() to
audio_query_spec(). In the process, go through the test code and
remove useless comments, pointless variables, and commented-out bits
of shell scripts.
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 15:32:53 +0000 |
parents | 580f696c817c |
children | e21a3db643af |
line wrap: on
line source
template <class T> class NearestAccumulator : public Accumulator { public: NearestAccumulator(); ~NearestAccumulator(); void add_point(adb_result_t *r); adb_query_results_t *get_points(); private: std::set< adb_result_t, adb_result_triple_lt > *set; std::set< adb_result_t, adb_result_qpos_lt > *points; }; template <class T> NearestAccumulator<T>::NearestAccumulator() : set(0), points(0) { set = new std::set< adb_result_t, adb_result_triple_lt >; points = new std::set< adb_result_t, adb_result_qpos_lt >; } template <class T> NearestAccumulator<T>::~NearestAccumulator() { if(set) { delete set; } if(points) { delete points; } } template <class T> void NearestAccumulator<T>::add_point(adb_result_t *r) { if(!isnan(r->dist)) { if(set->find(*r) == set->end()) { set->insert(*r); std::set< adb_result_t, adb_result_qpos_lt >::iterator it; it = points->find(*r); if(it == points->end()) { points->insert(*r); } else if(T()(*(const adb_result_t *)r,(*it))) { points->erase(it); points->insert(*r); } } } } template <class T> adb_query_results_t *NearestAccumulator<T>::get_points() { unsigned int nresults = points->size(); adb_query_results_t *r = (adb_query_results_t *) malloc(sizeof(adb_query_results_t)); adb_result_t *rs = (adb_result_t *) calloc(nresults, sizeof(adb_result_t)); r->nresults = nresults; r->results = rs; std::set< adb_result_t, adb_result_qpos_lt >::iterator it; unsigned int k = 0; for(it = points->begin(); it != points->end(); it++) { rs[k++] = *it; } return r; }