Imported Upstream version 0.12.7
[bowtie.git] / SeqAn-1.1 / seqan / file / file_format_guess.h
1  /*==========================================================================
2                 SeqAn - The Library for Sequence Analysis
3                           http://www.seqan.de 
4  ============================================================================
5   Copyright (C) 2007
6
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.
11
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.
16
17  ============================================================================
18   $Id: file_format_guess.h,v 1.1 2008/08/25 16:20:04 langmead Exp $
19  ==========================================================================*/
20
21 #ifndef SEQAN_HEADER_FILE_GUESS_H
22 #define SEQAN_HEADER_FILE_GUESS_H
23
24 namespace SEQAN_NAMESPACE_MAIN
25 {
26
27 //////////////////////////////////////////////////////////////////////////////
28 // guessFileFormat
29 //////////////////////////////////////////////////////////////////////////////
30
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.
34 /**
35 .Function.guessFileFormat:
36 ..cat:Input/Output
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
46 ..see:Tag.File Format
47 */
48 template <typename TFile, typename TData, typename TMeta>
49 inline FileFormat<TFile, TData, TMeta, void> &
50 guessFileFormat(TFile & file,
51                                 TData & data)
52 {
53 SEQAN_CHECKPOINT
54         typename Position<TFile>::Type old_pos = _streamTellG(file);
55         typename Value<TFile>::Type c;
56
57         _streamSeekG(file, 0); /// move to beginning of file
58         c = _streamGet(file);
59                 
60         if (c=='>') 
61         {
62                 _streamSeekG(file, old_pos);
63                 return getFileFormatInstance<TFile, TData, Fasta, TMeta>();
64         }
65         
66         if (c=='L')
67         {
68                 _streamSeekG(file, old_pos);
69                 return getFileFormatInstance<TFile, TData, Genbank, TMeta>();
70         }
71
72         if (c=='I')
73         {
74                 _streamSeekG(file, old_pos);
75                 return getFileFormatInstance<TFile, TData, Embl, TMeta>();
76         }
77
78         else
79         {
80                 _streamSeekG(file, old_pos);
81                 return getFileFormatInstance<TFile, TData, Raw, TMeta>();
82         }
83 }
84
85 //////////////////////////////////////////////////////////////////////////////
86
87 /* DOCH NICHT:
88 template <typename TTarget, typename TSource>
89 inline void
90 read(TTarget & target,
91          TSource & source)
92 {
93 SEQAN_CHECKPOINT
94         read(target, source, guessFileFormat(target, source));
95 }
96 */
97
98 //////////////////////////////////////////////////////////////////////////////
99 } //namespace SEQAN_NAMESPACE_MAIN
100
101 //////////////////////////////////////////////////////////////////////////////
102
103 #endif //#ifndef SEQAN_HEADER_...