changeset 452:25ee0b77f8ca api-inversion

No more audioDB::error in audioDB::query_loop Change it to return an int, and return non-zero for an error instead. This is very coarse-grained, yes, but necessary.
author mas01cr
date Wed, 24 Dec 2008 10:57:09 +0000
parents ef9ef130e27b
children 16a903968d18
files audioDB.h query.cpp
diffstat 2 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/audioDB.h	Wed Dec 24 10:57:05 2008 +0000
+++ b/audioDB.h	Wed Dec 24 10:57:09 2008 +0000
@@ -325,7 +325,7 @@
   void error(const char* a, const char* b = "", const char *sysFunc = 0);
 
   void insertTimeStamps(unsigned n, std::ifstream* timesFile, double* timesdata);
-  void query_loop(adb_t *adb, adb_query_spec_t *spec, Uns32T queryIndex);
+  int query_loop(adb_t *adb, adb_query_spec_t *spec, Uns32T queryIndex);
   void query_loop_points(adb_query_spec_t *spec, double* query, adb_qpointers_internal_t *qpointers);
   void initRNG();
   void initDBHeader(const char *dbName);
--- a/query.cpp	Wed Dec 24 10:57:05 2008 +0000
+++ b/query.cpp	Wed Dec 24 10:57:09 2008 +0000
@@ -205,7 +205,9 @@
   }
   else{
     VERB_LOG(1, "Calling brute-force query on database %s\n", dbName);
-    query_loop(adb, &qspec, query_from_key_index);
+    if(query_loop(adb, &qspec, query_from_key_index)) {
+      error("query_loop failed");
+    }
   }
 
   adb_query_results_t *rs = accumulator->get_points();
@@ -690,22 +692,25 @@
   SAFE_DELETE_ARRAY(dbpointers.mean_duration);
 }
 
-void audioDB::query_loop(adb_t *adb, adb_query_spec_t *spec, Uns32T queryIndex) {
+int audioDB::query_loop(adb_t *adb, adb_query_spec_t *spec, Uns32T queryIndex) {
   
   double *query, *query_data;
   adb_qpointers_internal_t qpointers = {0}, dbpointers = {0};
 
   bool power_refine = spec->refine.flags & (ADB_REFINE_ABSOLUTE_THRESHOLD|ADB_REFINE_RELATIVE_THRESHOLD);
 
-  if( adb->header->flags & O2_FLAG_LARGE_ADB )
-    error("error: LARGE_ADB requires indexed query");
+  if(adb->header->flags & O2_FLAG_LARGE_ADB) {
+    /* FIXME: actually it would be nice to support this mode of
+     * operation, but for now... */
+    return 1;
+  }
 
   if(audiodb_query_spec_qpointers(adb, spec, &query_data, &query, &qpointers)) {
-    error("failed to set up qpointers");
+    return 1;
   }
 
   if(audiodb_set_up_dbpointers(adb, spec, &dbpointers)) {
-    error("failed to set up db");
+    return 1;
   }
 
   unsigned j,k,track,trackOffset=0, HOP_SIZE = spec->refine.hopsize;
@@ -735,7 +740,7 @@
       if(!trackFile->eof()) {
 	track = audiodb_key_index(adb, nextKey);
         if(track == (uint32_t) -1) {
-          error("key not found", nextKey);
+          return 1;
         }
         trackOffset = (*adb->track_offsets)[track];
         lseek(adb->fd, adb->header->dataOffset + trackOffset, SEEK_SET);
@@ -758,8 +763,9 @@
 
     trackIndexOffset = trackOffset / (adb->header->dim * sizeof(double)); // dbpointers.nvectors offset
 
-    if(audiodb_read_data(adb, adb->fd, track, &data_buffer, &data_buffer_size))
-      error("failed to read data");
+    if(audiodb_read_data(adb, adb->fd, track, &data_buffer, &data_buffer_size)) {
+      return 1;
+    }
     if(wL <= (*adb->track_lengths)[track]) {  // test for short sequences
       
       audiodb_initialize_arrays(adb, spec, track, qpointers.nvectors, query, data_buffer, D, DD);
@@ -829,4 +835,6 @@
     delete[] DD;
   if(dbpointers.mean_duration)
     delete[] dbpointers.mean_duration;
+
+  return 0;
 }