Commit 08df07f4 authored by Mikaël Salson's avatar Mikaël Salson

kmerstorefactory.hpp: Can create index depending on type.

This has been moved in another file for better code separation.
parent 3152a7d5
......@@ -588,35 +588,4 @@ T& ArrayKmerStore<T>::operator[](int word){
return store[word];
}
/**
* KmerStoreFactory is a factory that allows to create an index that best fits
* your needs!
*/
class KmerStoreFactory {
public:
template<class T>
static IKmerStore<T> *createIndex(string seed, bool revcomp=false);
template<class T>
static IKmerStore<T> *createIndex(int k, bool revcomp=false);
};
template<class T>
IKmerStore<T> *KmerStoreFactory::createIndex(string seed, bool revcomp) {
IKmerStore<T> *index;
try{
index = new ArrayKmerStore<T>(seed, revcomp);
}catch(exception e){
cout << " (using a MapKmer to fit into memory)" << endl;
index = new MapKmerStore<T>(seed, revcomp);
}
return index;
}
template<class T>
IKmerStore<T> *KmerStoreFactory::createIndex(int k, bool revcomp) {
return createIndex<T>(seed_contiguous(k), revcomp);
}
#endif
#ifndef KMERSTOREFACTORY_HPP
#define KMERSTOREFACTORY_HPP
#include "kmerstore.h"
#include "automaton.h"
/**
* KmerStoreFactory is a factory that allows to create an index that best fits
* your needs!
*/
template<class T=KmerAffect>
class KmerStoreFactory {
public:
static IKmerStore<T> *createIndex(IndexTypes indexType, string seed, bool revcomp=false);
static IKmerStore<T> *createIndex(IndexTypes indexType, int k, bool revcomp=false);
};
template<class T=KmerAffect, IndexTypes type=KMER_INDEX>
class _KmerStoreFactory {
public:
static IKmerStore<T> *createIndex(string seed, bool revcomp=false);
static IKmerStore<T> *createIndex(int k, bool revcomp=false) {
return createIndex(seed_contiguous(k), revcomp);
}
};
template<class T>
class _KmerStoreFactory<T, KMER_INDEX> {
public:
static IKmerStore<T> *createIndex(string seed, bool revcomp) {
IKmerStore<T> *index;
try{
index = new ArrayKmerStore<T>(seed, revcomp);
}catch(exception e){
cout << " (using a MapKmer to fit into memory)" << endl;
index = new MapKmerStore<T>(seed, revcomp);
}
return index;
}
};
template<class T>
class _KmerStoreFactory<T, AC_AUTOMATON> {
public:
static IKmerStore<T> *createIndex(string seed, bool revcomp) {
return new PointerACAutomaton<T>(seed, revcomp);
}
};
template<class T>
IKmerStore<T> *KmerStoreFactory<T>::createIndex(IndexTypes indexType, string seed,
bool revcomp) {
if (indexType == KMER_INDEX) {
return _KmerStoreFactory<T, KMER_INDEX>::createIndex(seed, revcomp);
} else if (indexType == AC_AUTOMATON) {
return _KmerStoreFactory<T, AC_AUTOMATON>::createIndex(seed, revcomp);
} else {
throw std::domain_error("No such index type");
}
}
template<class T>
IKmerStore<T> *KmerStoreFactory<T>::createIndex(IndexTypes indexType, int k,
bool revcomp) {
return createIndex(indexType, seed_contiguous(k), revcomp);
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment