Mercurial > hg > audiodb
diff reporter.h @ 469:d3afc91d205d api-inversion
Move audioDB::query over to audioDB.cpp
At the same time, remove all the abstraction violations in
audioDB::query, which came in two flavours: use of dbH->numFiles, which
is dealt with by getting the database status instead (and is eventually
unnecessary, being only needed now because reporters are implemented in
terms of vectors indexed by ID), and use of fileTable in reporter's
report functions (dealt with by passing in the adb instead).
To actually implement reporting as of now, we continue to use stuff from
audioDB-internals.h; maybe someday we will be clean and shiny.
author | mas01cr |
---|---|
date | Wed, 31 Dec 2008 15:44:16 +0000 |
parents | 447f1cf2c276 |
children |
line wrap: on
line diff
--- a/reporter.h Wed Dec 31 15:44:12 2008 +0000 +++ b/reporter.h Wed Dec 31 15:44:16 2008 +0000 @@ -44,10 +44,9 @@ // FIXME: this interface is a bit wacky: a relic of previous, more // confused times. Really it might make sense to have separate // reporter classes for WS and for stdout, rather than passing this - // adbQueryResponse thing everywhere; the fileTable argument is - // there solely for convertion trackIDs into names. -- CSR, - // 2007-12-10. - virtual void report(char *fileTable, void* adbQueryResponse) = 0; + // adbQueryResponse thing everywhere; the adb argument is there + // solely for converting trackIDs into names. -- CSR, 2007-12-10. + virtual void report(adb_t *adb, void* adbQueryResponse) = 0; }; template <class T> class pointQueryReporter : public Reporter { @@ -55,7 +54,7 @@ pointQueryReporter(unsigned int pointNN); ~pointQueryReporter(); void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist); - void report(char *fileTable, void* adbQueryResponse); + void report(adb_t *adb, void* adbQueryResponse); private: unsigned int pointNN; std::priority_queue< NNresult, std::vector< NNresult >, T> *queue; @@ -84,7 +83,7 @@ } } -template <class T> void pointQueryReporter<T>::report(char *fileTable, void *adbQueryResponse) { +template <class T> void pointQueryReporter<T>::report(adb_t *adb, void *adbQueryResponse) { NNresult r; std::vector<NNresult> v; unsigned int size = queue->size(); @@ -98,8 +97,8 @@ if(adbQueryResponse==0) { for(rit = v.rbegin(); rit < v.rend(); rit++) { r = *rit; - if(fileTable) - std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " "; + if(adb) + std::cout << audiodb_index_key(adb, r.trackID) << " "; else std::cout << r.trackID << " "; std::cout << r.dist << " " << r.qpos << " " << r.spos << std::endl; @@ -121,8 +120,8 @@ response->result.Dist[k] = r.dist; response->result.Qpos[k] = r.qpos; response->result.Spos[k] = r.spos; - if(fileTable) - snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE); + if(adb) + snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", audiodb_index_key(adb, r.trackID)); else snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID); } @@ -134,7 +133,7 @@ trackAveragingReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles); ~trackAveragingReporter(); void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist); - void report(char *fileTable, void *adbQueryResponse); + void report(adb_t *adb, void *adbQueryResponse); protected: unsigned int pointNN; unsigned int trackNN; @@ -165,7 +164,7 @@ } } -template <class T> void trackAveragingReporter<T>::report(char *fileTable, void *adbQueryResponse) { +template <class T> void trackAveragingReporter<T>::report(adb_t *adb, void *adbQueryResponse) { std::priority_queue < NNresult, std::vector< NNresult>, T> result; for (int i = numFiles-1; i >= 0; i--) { unsigned int size = queues[i].size(); @@ -206,8 +205,8 @@ if(adbQueryResponse==0) { for(rit = v.rbegin(); rit < v.rend(); rit++) { r = *rit; - if(fileTable) - std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " "; + if(adb) + std::cout << audiodb_index_key(adb, r.trackID) << " "; else std::cout << r.trackID << " "; std::cout << r.dist << " " << r.qpos << " " << r.spos << std::endl; @@ -229,8 +228,8 @@ response->result.Dist[k] = r.dist; response->result.Qpos[k] = r.qpos; response->result.Spos[k] = r.spos; - if(fileTable) - snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE); + if(adb) + snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", audiodb_index_key(adb, r.trackID)); else snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID); } @@ -246,13 +245,13 @@ using trackAveragingReporter<T>::pointNN; public: trackSequenceQueryNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles); - void report(char *fileTable, void *adbQueryResponse); + void report(adb_t *adb, void *adbQueryResponse); }; template <class T> trackSequenceQueryNNReporter<T>::trackSequenceQueryNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles) :trackAveragingReporter<T>(pointNN, trackNN, numFiles){} -template <class T> void trackSequenceQueryNNReporter<T>::report(char *fileTable, void *adbQueryResponse) { +template <class T> void trackSequenceQueryNNReporter<T>::report(adb_t *adb, void *adbQueryResponse) { std::priority_queue < NNresult, std::vector< NNresult>, T> result; std::priority_queue< NNresult, std::vector< NNresult>, std::less<NNresult> > *point_queues = new std::priority_queue< NNresult, std::vector< NNresult>, std::less<NNresult> >[numFiles]; @@ -299,11 +298,11 @@ if(adbQueryResponse==0) { for(rit = v.rbegin(); rit < v.rend(); rit++) { r = *rit; - if(fileTable) - std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " "; + if(adb) + std::cout << audiodb_index_key(adb, r.trackID) << " "; else std::cout << r.trackID << " "; - std::cout << r.dist << std::endl; + std::cout << r.dist << std::endl; unsigned int qsize = point_queues[r.trackID].size(); // Reverse the order of the points stored in point_queues for(unsigned int k=0; k < qsize; k++){ @@ -353,8 +352,8 @@ response->result.Qpos[k] = rk.qpos; response->result.Spos[k] = rk.spos; if(qsize){ - if(fileTable) - snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE); + if(adb) + snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", audiodb_index_key(adb, r.trackID)); else snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID); point_queue.pop(); @@ -416,7 +415,7 @@ trackSequenceQueryRadReporter(unsigned int trackNN, unsigned int numFiles); ~trackSequenceQueryRadReporter(); void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist); - void report(char *fileTable, void *adbQueryResponse); + void report(adb_t *adb, void *adbQueryResponse); protected: unsigned int trackNN; unsigned int numFiles; @@ -463,7 +462,7 @@ } } -void trackSequenceQueryRadReporter::report(char *fileTable, void *adbQueryResponse) { +void trackSequenceQueryRadReporter::report(adb_t *adb, void *adbQueryResponse) { std::priority_queue < Radresult, std::vector<Radresult>, std::greater<Radresult> > result; // KLUDGE: doing this backwards in an attempt to get the same // tiebreak behaviour as before. @@ -492,8 +491,8 @@ if(adbQueryResponse==0) { for(rit = v.rbegin(); rit < v.rend(); rit++) { r = *rit; - if(fileTable) - std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " "; + if(adb) + std::cout << audiodb_index_key(adb, r.trackID) << " "; else std::cout << r.trackID << " "; std::cout << r.count << std::endl; @@ -515,8 +514,8 @@ response->result.Dist[k] = 0; response->result.Qpos[k] = 0; response->result.Spos[k] = r.count; - if(fileTable) - snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE); + if(adb) + snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", audiodb_index_key(adb, r.trackID)); else snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID); } @@ -532,7 +531,7 @@ trackSequenceQueryRadNNReporter(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles); ~trackSequenceQueryRadNNReporter(); void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist); - void report(char *fileTable, void *adbQueryResponse); + void report(adb_t *adb, void *adbQueryResponse); protected: unsigned int pointNN; unsigned int trackNN; @@ -595,7 +594,7 @@ } } -void trackSequenceQueryRadNNReporter::report(char *fileTable, void *adbQueryResponse) { +void trackSequenceQueryRadNNReporter::report(adb_t *adb, void *adbQueryResponse) { std::priority_queue < Radresult, std::vector<Radresult>, std::greater<Radresult> > result; // KLUDGE: doing this backwards in an attempt to get the same // tiebreak behaviour as before. @@ -637,7 +636,7 @@ } } // Report - rep->report(fileTable, adbQueryResponse); + rep->report(adb, adbQueryResponse); // Exit delete[] point_queues; return; @@ -651,8 +650,8 @@ if(adbQueryResponse==0) { for(rit = v.rbegin(); rit < v.rend(); rit++) { r = *rit; - if(fileTable) - std::cout << fileTable + r.trackID*O2_FILETABLE_ENTRY_SIZE << " "; + if(adb) + std::cout << audiodb_index_key(adb, r.trackID) << " "; else std::cout << r.trackID << " "; std::cout << r.count << std::endl; @@ -705,8 +704,8 @@ response->result.Qpos[k] = rk.qpos; response->result.Spos[k] = rk.spos; if(qsize){ - if(fileTable) - snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", fileTable+r.trackID*O2_FILETABLE_ENTRY_SIZE); + if(adb) + snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%s", audiodb_index_key(adb, r.trackID)); else snprintf(response->result.Rlist[k], O2_MAXFILESTR, "%d", r.trackID); point_queue.pop(); @@ -731,7 +730,7 @@ trackSequenceQueryRadNNReporterOneToOne(unsigned int pointNN, unsigned int trackNN, unsigned int numFiles); ~trackSequenceQueryRadNNReporterOneToOne(); void add_point(unsigned int trackID, unsigned int qpos, unsigned int spos, double dist); - void report(char *fileTable, void *adbQueryResponse); + void report(adb_t *adb, void *adbQueryResponse); protected: unsigned int pointNN; unsigned int trackNN; @@ -779,7 +778,7 @@ } -void trackSequenceQueryRadNNReporterOneToOne::report(char *fileTable, void *adbQueryResponse) { +void trackSequenceQueryRadNNReporterOneToOne::report(adb_t *adb, void *adbQueryResponse) { if(adbQueryResponse==0) { std::vector< NNresult >::iterator vit; NNresult rk; @@ -788,8 +787,8 @@ std::cout << rk.dist << " " << rk.qpos << " " << rk.spos << " "; - if(fileTable) - std::cout << fileTable + rk.trackID*O2_FILETABLE_ENTRY_SIZE << " "; + if(adb) + std::cout << audiodb_index_key(adb, rk.trackID) << " "; else std::cout << rk.trackID << " "; std::cout << std::endl;