Mercurial > hg > audiodb
comparison audioDB.cpp @ 409:99e6cbad7f76 api-inversion
The lesser of two evils, part 2.
Implement paths through audiodb_insert_datum_internal() for databases
with O2_FLAG_LARGE_ADB, including in some of the helper functions. Most
of the nasty stuff is concentrated in writing out the paths in what is
now step 6, and everything else looks much as before, apart from a
renumbering of the steps taken.
Now we can implement audiodb_insert() for O2_FLAG_LARGE_ADB databases;
we need to construct an adb_datum_internal_t from our adb_insert_t, but
that's straightforward -- even just about straightforward enough to do
it inline.
Then audioDB::batchinsert() can be rewritten completely in terms of API
functions, and doesn't need any kind of special treatment for the large
case. Hooray. The real point of that is of course that we can now
delete wodges of dead code, and move out audioDB::insert and
audioDB::batchinsert into audioDB.cpp, because all they're doing now is
dealing with command-line logic.
This point marks the limit of what can be achieved in terms of "API
inversion" at this time; the only remaining function,
audiodb_query() / audioDB::query cannot be inverted because its
API implementation is incomplete.
Future plans, in some order:
- merge this branch to trunk (check with current API/ABI clients);
- complete audiodb_query() implementation;
- invert audioDB::query / audiodb_query();
- MORE TESTS;
- remove audioDB.cpp from list of files compiled into the library;
- implement missing API functions (index, liszt, sample) directly;
- source code rearrangement into library and command-line directories;
- include bindings to library for some plausible candidate environments
(Perl, Python, Lisp, Pd, Max/MSP) as examples;
- API documentation.
author | mas01cr |
---|---|
date | Tue, 09 Dec 2008 22:48:30 +0000 |
parents | ef4792df8f93 |
children | a7d61291fbda |
comparison
equal
deleted
inserted
replaced
408:f0a69693eaef | 409:99e6cbad7f76 |
---|---|
731 error("Failed to dump database to ", output); | 731 error("Failed to dump database to ", output); |
732 } | 732 } |
733 status(dbName); | 733 status(dbName); |
734 } | 734 } |
735 | 735 |
736 void audioDB::insert(const char* dbName, const char* inFile) { | |
737 if(!adb) { | |
738 if(!(adb = audiodb_open(dbName, O_RDWR))) { | |
739 error("failed to open database", dbName); | |
740 } | |
741 } | |
742 | |
743 /* at this point, we have powerfd (an fd), timesFile (a | |
744 * std::ifstream *) and inFile (a char *). Wacky, huh? Ignore | |
745 * the wackiness and just use the names. */ | |
746 adb_insert_t insert; | |
747 insert.features = inFile; | |
748 insert.times = timesFileName; | |
749 insert.power = powerFileName; | |
750 insert.key = key; | |
751 | |
752 if(audiodb_insert(adb, &insert)) { | |
753 error("insertion failure", inFile); | |
754 } | |
755 status(dbName); | |
756 } | |
757 | |
758 void audioDB::batchinsert(const char* dbName, const char* inFile) { | |
759 if(!adb) { | |
760 if(!(adb = audiodb_open(dbName, O_RDWR))) { | |
761 error("failed to open database", dbName); | |
762 } | |
763 } | |
764 | |
765 if(!key) | |
766 key=inFile; | |
767 std::ifstream *filesIn = 0; | |
768 std::ifstream *keysIn = 0; | |
769 | |
770 if(!(filesIn = new std::ifstream(inFile))) | |
771 error("Could not open batch in file", inFile); | |
772 if(key && key!=inFile) | |
773 if(!(keysIn = new std::ifstream(key))) | |
774 error("Could not open batch key file",key); | |
775 | |
776 unsigned totalVectors=0; | |
777 char *thisFile = new char[MAXSTR]; | |
778 char *thisKey = 0; | |
779 if (key && (key != inFile)) { | |
780 thisKey = new char[MAXSTR]; | |
781 } | |
782 char *thisTimesFileName = new char[MAXSTR]; | |
783 char *thisPowerFileName = new char[MAXSTR]; | |
784 | |
785 do { | |
786 filesIn->getline(thisFile,MAXSTR); | |
787 if(key && key!=inFile) { | |
788 keysIn->getline(thisKey,MAXSTR); | |
789 } else { | |
790 thisKey = thisFile; | |
791 } | |
792 if(usingTimes) { | |
793 timesFile->getline(thisTimesFileName,MAXSTR); | |
794 } | |
795 if(usingPower) { | |
796 powerFile->getline(thisPowerFileName, MAXSTR); | |
797 } | |
798 | |
799 if(filesIn->eof()) { | |
800 break; | |
801 } | |
802 if(usingTimes){ | |
803 if(timesFile->eof()) { | |
804 error("not enough timestamp files in timesList", timesFileName); | |
805 } | |
806 } | |
807 if (usingPower) { | |
808 if(powerFile->eof()) { | |
809 error("not enough power files in powerList", powerFileName); | |
810 } | |
811 } | |
812 adb_insert_t insert; | |
813 insert.features = thisFile; | |
814 insert.times = usingTimes ? thisTimesFileName : NULL; | |
815 insert.power = usingPower ? thisPowerFileName : NULL; | |
816 insert.key = thisKey; | |
817 if(audiodb_insert(adb, &insert)) { | |
818 error("insertion failure", thisFile); | |
819 } | |
820 } while(!filesIn->eof()); | |
821 | |
822 VERB_LOG(0, "%s %s %u vectors %ju bytes.\n", COM_BATCHINSERT, dbName, totalVectors, (intmax_t) (totalVectors * dbH->dim * sizeof(double))); | |
823 | |
824 delete [] thisPowerFileName; | |
825 if(key && (key != inFile)) { | |
826 delete [] thisKey; | |
827 } | |
828 delete [] thisFile; | |
829 delete [] thisTimesFileName; | |
830 | |
831 delete filesIn; | |
832 delete keysIn; | |
833 | |
834 // Report status | |
835 status(dbName); | |
836 } | |
837 | |
736 // This entry point is visited once per instance | 838 // This entry point is visited once per instance |
737 // so it is a good place to set any global state variables | 839 // so it is a good place to set any global state variables |
738 int main(const int argc, const char* argv[]){ | 840 int main(const int argc, const char* argv[]){ |
739 SERVER_LSH_INDEX_SINGLETON = 0; // Initialize global variables | 841 SERVER_LSH_INDEX_SINGLETON = 0; // Initialize global variables |
740 SERVER_ADB_ROOT = 0; // Server-side database root prefix | 842 SERVER_ADB_ROOT = 0; // Server-side database root prefix |