1 /*==========================================================================
2 SeqAn - The Library for Sequence Analysis
4 ============================================================================
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 ============================================================================
18 $Id: file_format_guess.h,v 1.1 2008/08/25 16:20:04 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_FILE_GUESS_H
22 #define SEQAN_HEADER_FILE_GUESS_H
24 namespace SEQAN_NAMESPACE_MAIN
27 //////////////////////////////////////////////////////////////////////////////
29 //////////////////////////////////////////////////////////////////////////////
31 //guessFileFormat braucht auch data, weil die FileFormat-Klasse von TData
32 //abhaengig, und das ist so, weil sonst die Kombination von Templates mit
33 //virtuellen Funktionen nicht funktionieren wuerde.
35 .Function.guessFileFormat:
37 ..summary:Tries to determine the format of a file.
38 ..signature:guessFileFormat(file, data)
39 ..param.file: An input file.
40 ..param.data: The target container.
41 ...remarks:This container is not modified by this function.
42 ..returns:A file format object instance that represents the determined file format.
43 ...type:Class.FileFormat
44 ..remarks:The $data$-argument is used here as a tag to determine the type of the target.
45 ..see:Function.Fileformat#read
48 template <typename TFile, typename TData, typename TMeta>
49 inline FileFormat<TFile, TData, TMeta, void> &
50 guessFileFormat(TFile & file,
54 typename Position<TFile>::Type old_pos = _streamTellG(file);
55 typename Value<TFile>::Type c;
57 _streamSeekG(file, 0); /// move to beginning of file
62 _streamSeekG(file, old_pos);
63 return getFileFormatInstance<TFile, TData, Fasta, TMeta>();
68 _streamSeekG(file, old_pos);
69 return getFileFormatInstance<TFile, TData, Genbank, TMeta>();
74 _streamSeekG(file, old_pos);
75 return getFileFormatInstance<TFile, TData, Embl, TMeta>();
80 _streamSeekG(file, old_pos);
81 return getFileFormatInstance<TFile, TData, Raw, TMeta>();
85 //////////////////////////////////////////////////////////////////////////////
88 template <typename TTarget, typename TSource>
90 read(TTarget & target,
94 read(target, source, guessFileFormat(target, source));
98 //////////////////////////////////////////////////////////////////////////////
99 } //namespace SEQAN_NAMESPACE_MAIN
101 //////////////////////////////////////////////////////////////////////////////
103 #endif //#ifndef SEQAN_HEADER_...