1 // ==========================================================================
2 //                 SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2006-2010, Knut Reinert, FU Berlin
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 //       notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above copyright
13 //       notice, this list of conditions and the following disclaimer in the
14 //       documentation and/or other materials provided with the distribution.
15 //     * Neither the name of Knut Reinert or the FU Berlin nor the names of
16 //       its contributors may be used to endorse or promote products derived
17 //       from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 // DAMAGE.
30 //
31 // ==========================================================================
32 // Author: Manuel Holtgrewe <manuel.holtgrewe@fu-berlin.de>
33 // ==========================================================================
34 // Code for journal entries.
35 // ==========================================================================
36 
37 #ifndef SEQAN_SEQUENCE_JOURNALED_JOURNAL_ENTRY_H_
38 #define SEQAN_SEQUENCE_JOURNALED_JOURNAL_ENTRY_H_
39 
40 namespace seqan {
41 
42 // ============================================================================
43 // Enums, Classes
44 // ============================================================================
45 
46 enum SegmentSource {
47     SOURCE_NULL,
48     SOURCE_ORIGINAL,
49     SOURCE_PATCH
50 };
51 
52 
53 template <typename TPos_, typename TSize_>
54 struct JournalEntry
55 {
56     typedef TPos_ TPos;
57     typedef TSize_ TSize;
58 
59     // Flag for where the segment comes from.
60     SegmentSource segmentSource;
61     // Position in the original string or the insertion buffer,
62     // depending on segmentSource.
63     TPos physicalPosition;
64     // Position in the virtual string.
65     TPos virtualPosition;
66     // Length of the segment.
67     TSize length;
68 
JournalEntryJournalEntry69     JournalEntry()
70             : segmentSource(SOURCE_NULL),
71               physicalPosition(0),
72               virtualPosition(0),
73               length(0)
74     {
75 		SEQAN_CHECKPOINT;
76     }
77 
JournalEntryJournalEntry78     JournalEntry(SegmentSource const & _segmentSource,
79                  TPos _physicalPosition,
80                  TPos _virtualPosition,
81                  TSize _length)
82             : segmentSource(_segmentSource),
83               physicalPosition(_physicalPosition),
84               virtualPosition(_virtualPosition),
85               length(_length)
86     {
87 		SEQAN_CHECKPOINT;
88     }
89 };
90 
91 
92 template <typename TPos, typename TSize>
93 struct JournalEntryLtByVirtualPos
94 {
operatorJournalEntryLtByVirtualPos95     bool operator()(JournalEntry<TPos, TSize> const & a,
96                     JournalEntry<TPos, TSize> const & b) const
97     {
98         SEQAN_CHECKPOINT;
99         return a.virtualPosition < b.virtualPosition;
100     }
101 };
102 
103 // ============================================================================
104 // Metafunctions
105 // ============================================================================
106 
107 template <typename TPos, typename TSize>
108 struct Size<JournalEntry<TPos, TSize> >
109 {
110     typedef TSize Type;
111 };
112 
113 template <typename TPos, typename TSize>
114 struct Size<JournalEntry<TPos, TSize> const>
115         : Size<JournalEntry<TPos, TSize> > {};
116 
117 template <typename TPos, typename TSize>
118 struct Position<JournalEntry<TPos, TSize> >
119 {
120     typedef TPos Type;
121 };
122 
123 template <typename TPos, typename TSize>
124 struct Position<JournalEntry<TPos, TSize> const>
125         : Position<JournalEntry<TPos, TSize> > {};
126 
127 // ============================================================================
128 // Functions
129 // ============================================================================
130 
131 template <typename TStream, typename TPos, typename TSize>
132 TStream & operator<<(TStream & stream, JournalEntry<TPos, TSize> const & entry)
133 {
134     return stream << "{segmentSource=" << entry.segmentSource
135                   << ", virtualPosition=" << entry.virtualPosition
136                   << ", physicalPosition=" << entry.physicalPosition
137                   << ", length=" << entry.length
138                   << "}";
139 }
140 
141 }  // namespace seqan
142 
143 #endif  // SEQAN_SEQUENCE_JOURNALED_JOURNAL_ENTRY_H_
144 
145