TPIE

11a2c2d
internal_vector.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2010, 2012, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 #ifndef __TPIE_INTERNAL_VECTOR_H__
20 #define __TPIE_INTERNAL_VECTOR_H__
21 
26 #include <tpie/array.h>
27 #include <tpie/util.h>
29 namespace tpie {
30 
36 template <typename T>
37 class internal_vector: public internal_stack_vector_base<T,internal_vector<T> > {
38 public:
40  typedef typename array<T>::iterator iterator;
41  typedef typename array<T>::const_iterator const_iterator;
43  using parent_t::m_size;
44 
50  : parent_t(size, bucket){}
51 
52 
53  internal_vector(tpie::memory_bucket_ref bucket): parent_t(0, bucket){}
54 
58  inline T & operator[](size_t s){return m_elements[s];}
59 
63  inline const T & operator[](size_t s)const {return m_elements[s];}
64 
68  inline T & front(){return m_elements[0];}
69 
73  inline const T & front()const {return m_elements[0];}
74 
78  inline T & back(){return m_elements[m_size-1];}
79 
83  inline const T & back()const {return m_elements[m_size-1];}
84 
94  inline T & push_back(const T & val){m_elements[m_size++] = val; return back();}
95 
103  inline T & push_back(){++m_size; return back();}
104 
110  inline void pop_back(){--m_size;}
111 
115  inline iterator begin(){ return m_elements.begin();}
116 
120  inline const_iterator begin()const {return m_elements.begin();}
121 
125  inline iterator end(){return m_elements.find(m_size);}
126 
130  inline const_iterator end()const {return m_elements.find(m_size);}
131 };
132 
133 }
134 #endif //__TPIE_INTERNAL_VECTOR_H__
tpie::internal_vector::operator[]
const T & operator[](size_t s) const
Element access. No range checking is done.
Definition: internal_vector.h:63
tpie::internal_vector::front
const T & front() const
Get the first item pushed. Requires !empty().
Definition: internal_vector.h:73
tpie::internal_vector::end
const_iterator end() const
Get an iterator to the end of the structure.
Definition: internal_vector.h:130
tpie::internal_stack_vector_base< T, internal_vector< T > >::m_size
size_t m_size
Number of elements pushed to the structure.
Definition: internal_stack_vector_base.h:44
tpie::internal_vector::push_back
T & push_back(const T &val)
Add an element to the end of the vector.
Definition: internal_vector.h:94
internal_stack_vector_base.h
tpie::internal_vector::internal_vector
internal_vector(size_t size=0, tpie::memory_bucket_ref bucket=memory_bucket_ref())
Construct structure with given capacity.
Definition: internal_vector.h:49
tpie::array
A generic array with a fixed size.
Definition: array.h:149
tpie::array::begin
iterator begin()
Return an iterator to the beginning of the array.
Definition: array.h:312
tpie::internal_vector::begin
iterator begin()
Get an iterator to the beginning of the structure.
Definition: internal_vector.h:115
array.h
tpie::internal_vector::back
T & back()
Get the last item pushed. Requires !empty().
Definition: internal_vector.h:78
tpie::array::find
iterator find(size_t idx)
Return an iterator to the i'th element of the array.
Definition: array.h:172
tpie::internal_vector
A generic internal vector.
Definition: internal_vector.h:37
tpie::memory_bucket_ref
Class storring a reference to a memory bucket.
Definition: memory.h:334
tpie::internal_vector::begin
const_iterator begin() const
Get an iterator to the beginning of the structure.
Definition: internal_vector.h:120
tpie::internal_vector::front
T & front()
Get the first item pushed. Requires !empty().
Definition: internal_vector.h:68
tpie::internal_vector::push_back
T & push_back()
If an item was previously popped from this point in the structure, push it to the structure again; ot...
Definition: internal_vector.h:103
tpie::internal_stack_vector_base< T, internal_vector< T > >::m_elements
array< T > m_elements
Element storage.
Definition: internal_stack_vector_base.h:41
tpie::internal_vector::operator[]
T & operator[](size_t s)
Element access. No range checking is done.
Definition: internal_vector.h:58
tpie::internal_vector::back
const T & back() const
Get the last item pushed. Requires !empty().
Definition: internal_vector.h:83
tpie::internal_stack_vector_base
A base class for a generic internal fixed size stack and vector.
Definition: internal_stack_vector_base.h:38
tpie::internal_vector::pop_back
void pop_back()
Remove the last element from the vector.
Definition: internal_vector.h:110
tpie::internal_stack_vector_base< T, internal_vector< T > >::size
size_t size() const
Return the number of elements in the data structure.
Definition: internal_stack_vector_base.h:87
util.h
tpie
Definition: access_type.h:26
tpie::internal_vector::end
iterator end()
Get an iterator to the end of the structure.
Definition: internal_vector.h:125