Mercurial > hg > audiodb
diff audioDB.cpp @ 146:c9c508be69b3 powertable
Define a power command-line option; use it to turn on the DB flag.
Also enforce strict ordering: only accept power files if the DB has the
flag set; error if they're provided and the DB doesn't have the flag.
author | mas01cr |
---|---|
date | Wed, 31 Oct 2007 10:20:09 +0000 |
parents | 7162a8e9ab12 |
children | a564e6d7a30c |
line wrap: on
line diff
--- a/audioDB.cpp Tue Oct 30 15:28:48 2007 +0000 +++ b/audioDB.cpp Wed Oct 31 10:20:09 2007 +0000 @@ -72,6 +72,9 @@ else if(O2_ACTION(COM_L2NORM)) l2norm(dbName); + else if(O2_ACTION(COM_POWER)) + power_flag(dbName); + else if(O2_ACTION(COM_DUMP)) dump(dbName); @@ -220,6 +223,12 @@ return 0; } + if(args_info.POWER_given){ + command=COM_POWER; + dbName=args_info.database_arg; + return 0; + } + if(args_info.INSERT_given){ command=COM_INSERT; dbName=args_info.database_arg; @@ -529,6 +538,9 @@ if(!usingTimes && (dbH->flags & O2_FLAG_TIMES)) error("Must use timestamps with timestamped database","use --times"); + if(!usingPower && (dbH->flags & O2_FLAG_POWER)) + error("Must use power with power-enabled database", dbName); + // Check that there is room for at least 1 more file if((char*)timesTable<((char*)dataBuf+dbH->length+statbuf.st_size-sizeof(int))) error("No more room in database","insert failed: reason database is full."); @@ -663,6 +675,10 @@ void audioDB::insertPowerData(unsigned numVectors, int powerfd, double *powerdata) { if (usingPower) { + if (!(dbH->flags & O2_FLAG_POWER)) { + error("Cannot insert power data on non-power DB", dbName); + } + int one; unsigned int count; @@ -703,6 +719,9 @@ if(!usingTimes && (dbH->flags & O2_FLAG_TIMES)) error("Must use timestamps with timestamped database","use --times"); + if(!usingPower && (dbH->flags & O2_FLAG_POWER)) + error("Must use power with power-enabled database", dbName); + unsigned totalVectors=0; char *thisKey = new char[MAXSTR]; char *thisFile = new char[MAXSTR]; @@ -1060,7 +1079,15 @@ dbH->flags = dbH->flags|O2_FLAG_L2NORM; memcpy (db, dbH, O2_HEADERSIZE); } - + +void audioDB::power_flag(const char *dbName) { + initTables(dbName, true, 0); + if (dbH->length > 0) { + error("cannot turn on power storage for non-empty database", dbName); + } + dbH->flags |= O2_FLAG_POWER; + memcpy(db, dbH, O2_HEADERSIZE); +} void audioDB::query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){