NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
deinterleaved_iterator.h
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
30 #include <nvbio/basic/types.h>
31 #include <nvbio/basic/iterator.h>
32 
33 namespace nvbio {
34 
38 template<uint32 STRIDE, uint32 WHICH, typename BaseIterator>
40 {
41  typedef typename std::iterator_traits<BaseIterator>::value_type value_type;
42  typedef typename std::iterator_traits<BaseIterator>::reference reference;
43  typedef const value_type* pointer;
45  typedef std::random_access_iterator_tag iterator_category;
46 
48 
54 
59  deinterleaved_iterator(const BaseIterator it) : m_it( it ) {}
60 
66 
71  value_type operator[] (const uint32 i) const { return m_it[ i*STRIDE + WHICH ]; }
72 
77  reference operator[] (const uint32 i) { return m_it[ i*STRIDE + WHICH ]; }
78 
83  reference operator*() const { return m_it[ WHICH ]; }
84 
90  {
91  ++m_it;
92  return *this;
93  }
94 
100  {
101  this_type r( m_it );
102  ++m_it;
103  return r;
104  }
105 
111  {
112  --m_it;
113  return *this;
114  }
115 
121  {
122  this_type r( m_it );
123  --m_it;
124  return r;
125  }
126 
132  {
133  return deinterleaved_iterator( m_it + i );
134  }
135 
141  {
142  return this_type( m_it - i );
143  }
144 
150  {
151  m_it += i;
152  return *this;
153  }
154 
160  {
161  m_it -= i;
162  return *this;
163  }
164 
170  {
171  return m_it - it.m_it;
172  }
173 
179  {
180  m_it = it.m_it;
181  return *this;
182  }
183 
184  BaseIterator m_it;
185 };
186 
187 
188 } // namespace nvbio