On 28/07/11 12:26, Weese, David wrote:
OK, so if I've understood correctly I think the following should work. I'm trying to set up a ESA that uses a SAValue of type unsigned. I get a load of compile errors about No match for ‘getValueI2(unsigned int)’. Can you let me know what I'm doing wrong or if this is not possible.I tend to look in the reference section of the documentation so I was here:http://www.seqan.de/dddoc/html_devel/SPEC_Index_Esa.html I could see the definition Index<TText, IndexEsa<> >but from this page I had no idea I could overload the SAValue, or indeed if I could whether it would be an argument to the IndexEsa template or to the Index template. Are you saying I need to specialise the metafunction SAValue to overload it for my index? Presumably this must be done in the seqan namespace? Is the SAValue for the index not a template argument to Index?Metafunctions shall not only be used by a user to determine a type of a function or data structure. They are as well defining the types of data structures, i.e. if you change the return type of a metafunction you can change the behaviour and the types of data structures in the library. This is a bit different to the STL, where types are defined in a trait structure - an additional template argument.Changing the return type of a metafunction is only possible for a type which is more special than the default type (it was already specialized for). Of course there is a SAValue specialization done for all Index classes of the form Index<TText, TSpec> which returns the SAValue<TText>::Type. To be more special you can either specialize for TText or TSpec. The example in my last mail did the latter. You will find the list of metafunctions specialized for a certain type under "Metafunction" on its documentation page.Yes, the specialization needs to be done in the seqan namespace. SAValue is not an argument of the Index as there are many more metafunctions (see Fibre, DefaultIndexCreator, ...) would blow the interface. We intentionally left a single extra argument (TSpec) open for enhancements. If you want to create a specialized index you can define your own struct (MyIndex in the example) and give it as TSpec. You can then change the behaviour of your index by specializing only the types/tags you want to change like SAValue, Fibre, ... Just like you would do it for functions in OOP.
#include <seqan/index.h> #include <seqan/sequence.h> using namespace seqan; struct global {}; // specialise for our index namespace seqan { template< typename TText > struct SAValue< Index< TText, IndexEsa< global > > > { typedef unsigned Type; }; } // namespace seqan typedef String< Dna5 > string_t; ///< A string of Dna5. typedef StringSet< string_t > string_set_t; ///< StringSet type. typedef Index< string_set_t, IndexEsa< global > > index_t; int main( int argc, char * argv[] ) { string_set_t sequences; index_t index( sequences ); Iterator< index_t, TopDown<> >::Type it( index ); return 0; }