ProteoWizard
CharIndexedVector.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6//
7// Copyright 2008 Spielberg Family Center for Applied Proteomics
8// Cedars Sinai Medical Center, Los Angeles, California 90048
9// Copyright 2008 Vanderbilt University - Nashville, TN 37232
10//
11// Licensed under the Apache License, Version 2.0 (the "License");
12// you may not use this file except in compliance with the License.
13// You may obtain a copy of the License at
14//
15// http://www.apache.org/licenses/LICENSE-2.0
16//
17// Unless required by applicable law or agreed to in writing, software
18// distributed under the License is distributed on an "AS IS" BASIS,
19// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20// See the License for the specific language governing permissions and
21// limitations under the License.
22//
23
24
25#ifndef _CHARINDEXEDVECTOR_HPP_
26#define _CHARINDEXEDVECTOR_HPP_
27
28#include "boost/array.hpp"
29
30namespace pwiz {
31namespace util {
32
33/// an iterator for CharIndexedVector
34template<class T>
36{
37 typedef boost::array<T, 129> type;
38 typename type::iterator m_itr;
39
40public:
41 typedef typename type::value_type value_type;
42 typedef typename type::iterator iterator;
43 typedef typename type::iterator pointer;
44 typedef typename type::const_iterator const_iterator;
45 typedef typename type::difference_type difference_type;
46 typedef typename type::reference reference;
47 typedef typename type::const_reference const_reference;
48 typedef typename type::size_type size_type;
49 typedef std::random_access_iterator_tag iterator_category;
50
52
54 {
55 return *m_itr;
56 }
57
59 {
60 return m_itr != *(iterator*)&rhs;
61 }
62
64 {
65 return m_itr - rhs.m_itr;
66 }
67
69 { // preincrement
70 ++m_itr;
71 return (*this);
72 }
73
75 { // postincrement
76 CharIndexedVectorIterator _Tmp = *this;
77 ++m_itr;
78 return (_Tmp);
79 }
80
82 { // predecrement
83 ++m_itr;
84 return (*this);
85 }
86
88 { // postdecrement
89 CharIndexedVectorIterator _Tmp = *this;
90 ++m_itr;
91 return (_Tmp);
92 }
93
95 { // increment by integer
96 m_itr += _Off;
97 return (*this);
98 }
99
101 { // decrement by integer
102 return (*this += -_Off);
103 }
104
106 {
107 return m_itr < rhs.m_itr;
108 }
109};
110
111/// a const_iterator for CharIndexedVector
112template<class T>
114{
115 typedef boost::array<T, 129> type;
116 typename type::const_iterator m_itr;
117
118public:
119 typedef typename type::value_type value_type;
120 typedef typename type::iterator iterator;
121 typedef typename type::iterator pointer;
122 typedef typename type::const_iterator const_iterator;
123 typedef typename type::difference_type difference_type;
124 typedef typename type::reference reference;
125 typedef typename type::const_reference const_reference;
126 typedef typename type::size_type size_type;
127 typedef std::random_access_iterator_tag iterator_category;
128
130
132 {
133 return *m_itr;
134 }
135
137 {
138 return m_itr != *(const_iterator*)&rhs;
139 }
140
142 {
143 return m_itr - rhs.m_itr;
144 }
145
147 { // preincrement
148 ++m_itr;
149 return (*this);
150 }
151
153 { // postincrement
155 ++m_itr;
156 return (_Tmp);
157 }
158
160 { // predecrement
161 ++m_itr;
162 return (*this);
163 }
164
166 { // postdecrement
168 ++m_itr;
169 return (_Tmp);
170 }
171
173 { // increment by integer
174 m_itr += _Off;
175 return (*this);
176 }
177
179 { // decrement by integer
180 return (*this += -_Off);
181 }
182
184 {
185 return m_itr < rhs.m_itr;
186 }
187};
188
189/// a wrapper for boost::array that is indexable by character; supports indexes 0-127
190template<class T>
191struct CharIndexedVector : public boost::array<T, 129>
192{
193 typedef boost::array<T, 129> type;
196 typedef std::reverse_iterator<iterator> reverse_iterator;
197 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
198
200 {
201 clear();
202 }
203
204 size_t size() const
205 {
206 return 128;
207 }
208
209 void erase(const char c)
210 {
211 this->operator[](c) = T();
212 }
213
214 void clear()
215 {
216 std::fill(type::begin(), type::end(), T());
217 }
218
219 char getIndexAsChar(iterator itr) const
220 {
221 return 'A' + (itr - type::begin());
222 }
223
224 char getIndexAsChar(size_t i) const
225 {
226 return 'A' + (&this->operator[](i) - type::begin());
227 }
228
229 const T& operator[](const char c) const
230 {
231 return type::operator[]((size_t) c);
232 }
233
234 T& operator[](const char c)
235 {
236 return type::operator[]((size_t) c);
237 }
238
239 const_iterator begin() const {return type::begin();}
240 const_iterator end() const {return type::end();}
241 iterator begin() {return type::begin();}
242 iterator end() {return type::end();}
243};
244
245} // namespace util
246} // namespace pwiz
247
248#endif // _CHARINDEXEDVECTOR_HPP_
a const_iterator for CharIndexedVector
CharIndexedVectorConstIterator & operator--()
CharIndexedVectorConstIterator(const const_iterator &itr)
CharIndexedVectorConstIterator operator++(int)
bool operator!=(const CharIndexedVectorConstIterator &rhs) const
CharIndexedVectorConstIterator & operator++()
CharIndexedVectorConstIterator operator--(int)
std::random_access_iterator_tag iterator_category
bool operator<(const CharIndexedVectorConstIterator &rhs)
difference_type operator-(const CharIndexedVectorConstIterator &rhs) const
CharIndexedVectorConstIterator & operator-=(difference_type _Off)
CharIndexedVectorConstIterator & operator+=(difference_type _Off)
an iterator for CharIndexedVector
CharIndexedVectorIterator & operator--()
std::random_access_iterator_tag iterator_category
CharIndexedVectorIterator & operator+=(difference_type _Off)
CharIndexedVectorIterator operator++(int)
bool operator!=(const CharIndexedVectorIterator &rhs) const
difference_type operator-(const CharIndexedVectorIterator &rhs) const
CharIndexedVectorIterator & operator++()
CharIndexedVectorIterator & operator-=(difference_type _Off)
bool operator<(const CharIndexedVectorIterator &rhs)
CharIndexedVectorIterator operator--(int)
a wrapper for boost::array that is indexable by character; supports indexes 0-127
std::reverse_iterator< const_iterator > const_reverse_iterator
CharIndexedVectorIterator< T > iterator
std::reverse_iterator< iterator > reverse_iterator
CharIndexedVectorConstIterator< T > const_iterator
char getIndexAsChar(iterator itr) const
const T & operator[](const char c) const