TPIE

v1.1rc1-6-g0c97303
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 
54  inline T & operator[](size_t s){return m_elements[s];}
55 
59  inline const T & operator[](size_t s)const {return m_elements[s];}
60 
64  inline T & front(){return m_elements[0];}
65 
69  inline const T & front()const {return m_elements[0];}
70 
74  inline T & back(){return m_elements[m_size-1];}
75 
79  inline const T & back()const {return m_elements[m_size-1];}
80 
90  inline T & push_back(const T & val){m_elements[m_size++] = val; return back();}
91 
101  inline T & push_back(){++m_size; return back();}
102 
108  inline void pop_back(){--m_size;}
109 
113  inline iterator begin(){ return m_elements.begin();}
114 
118  inline const_iterator begin()const {return m_elements.begin();}
119 
123  inline iterator end(){return m_elements.find(m_size);}
124 
128  inline const_iterator end()const {return m_elements.find(m_size);}
129 };
130 
131 }
132 #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:166
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:143
Generic base for internal stack and vector with known memory requirements.
internal_vector(size_t size=0)
Construct structure with given capacity.
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.
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().
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:274
iterator end()
Get an iterator to the end of the structure.
T & operator[](size_t s)
Element access. No range checking is done.