TPIE

2362a60
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 
105  inline T & push_back(){++m_size; return back();}
106 
112  inline void pop_back(){--m_size;}
113 
117  inline iterator begin(){ return m_elements.begin();}
118 
122  inline const_iterator begin()const {return m_elements.begin();}
123 
127  inline iterator end(){return m_elements.find(m_size);}
128 
132  inline const_iterator end()const {return m_elements.find(m_size);}
133 };
134 
135 }
136 #endif //__TPIE_INTERNAL_VECTOR_H__
const_iterator begin() const
Get an iterator to the beginning of the structure.
iterator find(size_t idx)
Return an iterator to the i'th element of the array.
Definition: array.h:167
const T & back() const
Get the last item pushed. Requires !empty().
size_t m_size
Number of elements pushed to the structure.
A generic array with a fixed size.
Definition: array.h:144
Generic base for internal stack and vector with known memory requirements.
size_t size() const
Return the number of elements in the data structure.
T & push_back(const T &val)
Add an element to the end of the vector.
A base class for a generic internal fixed size stack and vector.
T & front()
Get the first item pushed. Requires !empty().
void pop_back()
Remove the last element from the vector.
const T & front() const
Get the first item pushed. Requires !empty().
Generic internal array with known memory requirements.
const_iterator end() const
Get an iterator to the end of the structure.
Class storring a reference to a memory bucket.
Definition: memory.h:366
A generic internal vector.
Miscellaneous utility functions.
const T & operator[](size_t s) const
Element access. No range checking is done.
iterator begin()
Get an iterator to the beginning of the structure.
T & back()
Get the last item pushed. Requires !empty().
internal_vector(size_t size=0, tpie::memory_bucket_ref bucket=memory_bucket_ref())
Construct structure with given capacity.
T & push_back()
If an item was previously popped from this point in the structure, push it to the structure again; ot...
iterator begin()
Return an iterator to the beginning of the array.
Definition: array.h:307
iterator end()
Get an iterator to the end of the structure.
T & operator[](size_t s)
Element access. No range checking is done.