Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
vector1.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/vector1.hh
11 /// @brief vector1: std::vector with 1-based indexing
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 
14 
15 #ifndef INCLUDED_utility_vector1_HH
16 #define INCLUDED_utility_vector1_HH
17 
18 
19 // Unit headers
20 #include <utility/vector1.fwd.hh>
21 
22 // Package headers
23 #include <utility/vectorL.hh>
24 
25 #include <algorithm>
26 
27 namespace utility {
28 
29 
30 /// @brief std::vector with 1-based indexing
31 //
32 // std::vector with 1-based indexing and a few extras
33 //
34 // Can construct and assign from std::vector and swap with std::vector
35 //
36 // Can compare with std::vector: compares contents ignoring indexes
37 //
38 // Can explicitly convert to std::vector
39 //
40 // Public inheritance from concrete vectorL template is safe here
41 template< typename T, typename A >
42 class vector1 :
43  public vectorL< 1, T, A >
44 {
45 
46 private: // Types
47 
48 
50 
51 
52 public: // Types
53 
54 
55  // STL/boost style
56  typedef typename super::value_type value_type;
57  typedef typename super::reference reference;
59  typedef typename super::pointer pointer;
61  typedef typename super::iterator iterator;
65  typedef typename super::size_type size_type;
68  typedef typename super::index_type index_type;
69  typedef typename super::ssize_type ssize_type;
70 
71  // Project style
72  typedef typename super::Value Value;
73  typedef typename super::Reference Reference;
75  typedef typename super::Pointer Pointer;
77  typedef typename super::Iterator Iterator;
81  typedef typename super::Size Size;
82  typedef typename super::Difference Difference;
83  typedef typename super::Allocator Allocator;
84  typedef typename super::Index Index;
85  typedef typename super::SSize SSize;
86 
87 
88 public: // Methods: imports
89 
90 
91  using super::assign;
92  using super::at;
93  using super::back;
94  using super::begin;
95  using super::capacity;
96  using super::clear;
97  using super::empty;
98  using super::end;
99  using super::erase;
100  using super::front;
101  using super::get_allocator;
102  using super::insert;
103  using super::max_size;
104  using super::operator [];
105  using super::pop_back;
106  using super::push_back;
107  using super::rbegin;
108  using super::rend;
109  using super::reserve;
110  using super::resize;
111  using super::size;
112  using super::swap;
113 
114 
115 public: // Creation
116 
117 
118  /// @brief Default constructor
119  inline
120  explicit
121  vector1( allocator_type const & alloc = allocator_type() ) :
122  super( alloc )
123  {}
124 
125 
126  /// @brief Copy constructor
127  inline
128  vector1( vector1 const & v ) :
129  super( v )
130  {}
131 
132 
133  /// @brief Assignable copy constructor
134  template< ssize_type L_, typename T_, typename A_ >
135  inline
137  super( v.begin(), v.end() )
138  {}
139 
140 
141  /// @brief std::vector constructor
142  inline
143  explicit
144  vector1( super const & v ) :
145  super( v )
146  {}
147 
148 
149  /// @brief Assignable std::vector constructor
150  template< typename T_, typename A_ >
151  inline
152  explicit
153  vector1( std::vector< T_, A_ > const & v ) :
154  super( v.begin(), v.end() )
155  {}
156 
157 
158  /// @brief Size constructor
159  inline
160  explicit
161  vector1( size_type const num ) :
162  super( num )
163  {}
164 
165 
166  /// @brief Uniform value constructor
167  inline
169  size_type const num,
170  value_type const & value,
171  allocator_type const & alloc = allocator_type()
172  ) :
173  super( num, value, alloc )
174  {}
175 
176 
177  /// @brief Iterator range constructor
178  template< typename InputIterator >
179  inline
181  InputIterator const beg,
182  InputIterator const end,
183  allocator_type const & alloc = allocator_type()
184  ) :
185  super( beg, end, alloc )
186  {}
187 
188 
189  /// @brief Destructor
190  inline
191  virtual
193  {}
194 
195 
196 public: // Assignment
197 
198 
199  /// @brief Copy assignment
200  inline
201  vector1 &
202  operator =( vector1 const & v )
203  {
204  if ( this != &v ) {
205  super::operator =( v );
206  }
207  return *this;
208  }
209 
210 
211  /// @brief Assignable copy assignment
212  template< ssize_type L_, typename T_, typename A_ >
213  inline
214  vector1 &
216  {
217  super::assign( v.begin(), v.end() );
218  return *this;
219  }
220 
221 
222  /// @brief std::vector assignment
223  inline
224  vector1 &
225  operator =( super const & v )
226  {
227  super::operator =( v );
228  return *this;
229  }
230 
231 
232  /// @brief Assignable std::vector assignment
233  template< typename T_, typename A_ >
234  inline
235  vector1 &
236  operator =( std::vector< T_, A_ > const & v )
237  {
238  super::assign( v.begin(), v.end() );
239  return *this;
240  }
241 
242  /// @brief Find the index of an element. If not found then return 0;
243  inline
244  int
245  index( T const t ) const {
246  Size idx = 1 + std::distance( begin(), std::find(begin(), end(), t) );
247  if ( idx > size() ) return 0;
248  return idx;
249  }
250 
251  /// @brief useful function -- was commented out previously due, I think, to a conflict with has() in OptionKeys! Now renamed to has_value().
252  inline
253  bool
254  has_value( T const t ) const {
255  return ( std::find(begin(), end(), t ) != end() );
256  }
257 
258 }; // vector1
259 
260 
261 } // namespace utility
262 
263 
264 // bool specialization
265 #include <utility/vector1_bool.hh>
266 
267 
268 #endif // INCLUDED_utility_vector1_HH
super::const_iterator const_iterator
Definition: vectorL.hh:74
super::reference reference
Definition: vector1.hh:57
super::reverse_iterator reverse_iterator
Definition: vectorL.hh:75
vector1: std::vector with 1-based indexing: bool specialization
dictionary size
Definition: amino_acids.py:44
vectorL< 1, T, A > super
Definition: vector1.hh:49
vector1(InputIterator const beg, InputIterator const end, allocator_type const &alloc=allocator_type())
Iterator range constructor.
Definition: vector1.hh:180
super::ConstPointer ConstPointer
Definition: vector1.hh:76
super::index_type index_type
Definition: vector1.hh:68
super::const_reverse_iterator const_reverse_iterator
Definition: vectorL.hh:76
void swap(vectorL &v)
swap( vectorL )
Definition: vectorL.hh:614
super::Index Index
Definition: vector1.hh:84
utility::keys::lookup::end< KeyType > const end
super::pointer pointer
Definition: vector1.hh:59
super::const_reference const_reference
Definition: vectorL.hh:70
vector1 & operator=(vector1 const &v)
Copy assignment.
Definition: vector1.hh:202
super::const_reference ConstReference
Definition: vectorL.hh:86
super::allocator_type allocator_type
Definition: vectorL.hh:79
super::reverse_iterator ReverseIterator
Definition: vectorL.hh:91
virtual ~vector1()
Destructor.
Definition: vector1.hh:192
super::Pointer Pointer
Definition: vector1.hh:75
super::reverse_iterator reverse_iterator
Definition: vector1.hh:63
bool has_value(T const t) const
useful function – was commented out previously due, I think, to a conflict with has() in OptionKeys!...
Definition: vector1.hh:254
vector1(std::vector< T_, A_ > const &v)
Assignable std::vector constructor.
Definition: vector1.hh:153
super::ssize_type ssize_type
Definition: vector1.hh:69
super::Size Size
Definition: vector1.hh:81
vector1(vectorL< L_, T_, A_ > const &v)
Assignable copy constructor.
Definition: vector1.hh:136
super::difference_type difference_type
Definition: vectorL.hh:78
vector1(size_type const num, value_type const &value, allocator_type const &alloc=allocator_type())
Uniform value constructor.
Definition: vector1.hh:168
super::difference_type difference_type
Definition: vector1.hh:66
member1 value
Definition: Tag.cc:296
vector1(size_type const num)
Size constructor.
Definition: vector1.hh:161
super::Difference Difference
Definition: vector1.hh:82
vectorL: std::vector with L-based indexing
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
super::iterator iterator
Definition: vector1.hh:61
super::ConstReference ConstReference
Definition: vector1.hh:74
super::size_type size_type
Definition: vector1.hh:65
super::ReverseIterator ReverseIterator
Definition: vector1.hh:79
super::Allocator Allocator
Definition: vector1.hh:83
T distance(MathVector< T > const &VECTOR_A, MathVector< T > const &VECTOR_B)
super::const_iterator const_iterator
Definition: vector1.hh:62
super::value_type value_type
Definition: vector1.hh:56
super::const_reference const_reference
Definition: vector1.hh:58
int index(T const t) const
Find the index of an element. If not found then return 0;.
Definition: vector1.hh:245
super::Reference Reference
Definition: vector1.hh:73
vector1(allocator_type const &alloc=allocator_type())
Default constructor.
Definition: vector1.hh:121
super::ConstReverseIterator ConstReverseIterator
Definition: vector1.hh:80
super::Value Value
Definition: vector1.hh:72
vector1(super const &v)
std::vector constructor
Definition: vector1.hh:144
const_reference at(index_type const i) const
vectorL.at( i ) const
Definition: vectorL.hh:388
utility::keys::lookup::begin< KeyType > const begin
super::SSize SSize
Definition: vector1.hh:85
super::Iterator Iterator
Definition: vector1.hh:77
vector1(vector1 const &v)
Copy constructor.
Definition: vector1.hh:128
super::ConstIterator ConstIterator
Definition: vector1.hh:78
vectorL & operator=(vectorL const &v)
Copy assignment.
Definition: vectorL.hh:215
super::const_reverse_iterator ConstReverseIterator
Definition: vectorL.hh:92
utility::vector1 forward declarations
super::const_pointer const_pointer
Definition: vector1.hh:60
super::const_reverse_iterator const_reverse_iterator
Definition: vector1.hh:64
super::allocator_type allocator_type
Definition: vector1.hh:67