Imported Upstream version 0.12.7
[bowtie.git] / SeqAn-1.1 / seqan / find / find_multi.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: find_multi.h,v 1.1 2008/08/25 16:20:06 langmead Exp $
19  ==========================================================================*/
20
21 #ifndef SEQAN_HEADER_FIND_MULTI_H
22 #define SEQAN_HEADER_FIND_MULTI_H
23
24 namespace SEQAN_NAMESPACE_MAIN
25 {
26
27 //////////////////////////////////////////////////////////////////////////////
28
29 struct _MultipatternFinder;
30 typedef Tag<_MultipatternFinder> MultipatternFinder;
31         
32 //____________________________________________________________________________
33
34 template <typename THaystack>
35 class Finder<THaystack, MultipatternFinder>
36 {
37 //____________________________________________________________________________
38 private:
39         unsigned int data_pattern;
40
41 public:
42         Finder():
43                 data_pattern(0)
44         {
45 SEQAN_CHECKPOINT
46         }
47
48         Finder(Finder const & other_):
49                 data_pattern(other_.data_pattern)
50         {
51 SEQAN_CHECKPOINT
52         }
53
54         ~Finder()
55         {
56 SEQAN_CHECKPOINT
57         }
58 //____________________________________________________________________________
59
60         Finder & 
61         operator = (Finder const & other_)
62         {
63 SEQAN_CHECKPOINT
64                 data_pattern = other_.data_pattern;
65                 return *this;
66         }
67 //____________________________________________________________________________
68
69         friend inline unsigned int &
70         needle(Finder & me)
71         {
72 SEQAN_CHECKPOINT
73                 return me.data_pattern;
74         }
75         friend inline unsigned int const &
76         needle(Finder const & me)
77         {
78 SEQAN_CHECKPOINT
79                 return me.data_pattern;
80         }
81 //____________________________________________________________________________
82
83         friend inline void
84         setNeedle(Finder & me, unsigned int const needleIndex_)
85         {
86 SEQAN_CHECKPOINT
87                 me.data_pattern = needleIndex_;
88         }
89
90 //____________________________________________________________________________
91
92         friend inline void
93         init(Finder & me)
94         {
95 SEQAN_CHECKPOINT
96                 me.data_pattern = 0;
97         }
98 //____________________________________________________________________________
99
100
101 //////////////////////////////////////////////////////////////////////////////
102
103 template <typename THaystack, typename TNeedle>
104 friend inline bool
105 find(Finder & me,
106          THaystack & hstk,
107          TNeedle const & ndl)
108 {
109 SEQAN_CHECKPOINT
110         while ( needle(me) < length(ndl) )
111         {
112                 Finder<THaystack, Horspool> horspool(ndl[needle(me)]);
113                 bool found = find(horspool, hstk, ndl[needle(me)]);
114                 if (found)
115                 {
116                         return true;
117                 }
118                 setPosition(hstk, 0);
119                 ++needle(me);
120         }
121         return false;
122 }
123
124 //////////////////////////////////////////////////////////////////////////////
125 /*
126 template <typename THaystack, typename TNeedle>
127 bool
128 findNext(Finder & me,
129                  THaystack & hstk,
130                  TNeedle const & ndl)
131 {
132 SEQAN_CHECKPOINT
133         ++hstk;
134         return find(me, hstk, ndl);
135 }*/
136
137 //////////////////////////////////////////////////////////////////////////////
138
139 };
140
141 }// namespace SEQAN_NAMESPACE_MAIN
142
143 #endif //#ifndef SEQAN_HEADER_...