00001
00002 *
00003 * Idea for the future to maybe implement:
00004 * add hooks to GeneralData, like
00005 * virtual void hookBeforeCreate(Txnid *) and
00006 * virtual void hookBeforeRemove(Txnid *).
00007 * Database::Creator would then call these hooks everytime a
00008 * create or remove is to be done.
00009 * We would now have the possibility to add substring search functionality for the
00010 * dna sequence in the DnaStrData feature.
00011 * We implement a new Class, SubStrData : public GeneralData that stores e.g. sequences
00012 * of length 12.
00013 * The DnaStrData::hookBeforeCreate(Txnid *) creates each possible 12-length-substring as records
00014 * in the SubStrData.
00015 * The SubStrData::getIndex() should return two secondary indices: one with sorting of the DnaStrData recno,
00016 * and one with sorting in lexicographical order of the 12-length-substring
00017
00018
00019 class SubStrData : public GeneralData
00020 {
00021 public:
00022 virtual TrDb::IndexMap GeneralData::getIndexMap()
00023 {
00024 TrDb::IndexMap iMap;
00025 TrDb::Index i = {
00026 &SubStrData::bt_compare_dnaStrRecNo,
00027 &SubStrData::getDnaStrRecNo,
00028 QString("dnaStrRecno"),
00029 NULL
00030 };
00031 iMap.insert( make_pair( i.name, i ) );
00032 i = {
00033 &SubStrData::bt_compare_subStr,
00034 &SubStrData::getSubStr,
00035 QString("substring"),
00036 NULL
00037 };
00038 iMap.insert( make_pair( i.name, i ) );
00039 return iMap;
00040 }
00041
00042 int getDnaStrRecNo( Db * , const Dbt * , const Dbt *pdata, Dbt *skey)
00043 {
00044 memset(skey, 0, sizeof(Dbt));
00045 StorageData * data = ( StorageData * ) pdata->get_data();
00046 skey->set_data( ( u_int8_t * ) (& (data->dnastrdataRecno)) );
00047 skey->set_size(sizeof( db_recno_t ));
00048 return(0);
00049 }
00050 struct StorageData
00051 {
00052 char[12] substring;
00053 db_recno_t dnastrdataRecno;
00054 };
00055
00056
00057 int bt_compare_dnaStrRecNo( DB * , const DBT *dbt1, const DBT *dbt2)
00058 {
00059
00060 db_recno_t * recno1 = ( db_recno_t *) dbt1->data;
00061 db_recno_t * recno2 = ( db_recno_t *) dbt2->data;
00062 if ( *recno1 > *recno2 )
00063 return 1;
00064 if ( *recno1 < *recno2 )
00065 return -1;
00066 if ( *recno1 == *recno2 )
00067 return 0;
00068
00069 return 0;
00070 }
00071
00072 db_recno_t dnastrdataRecno;
00073 protected:
00074 std::string substr;
00075 };
00076
00077
00078