TPIE

2362a60
internal_stack_vector_base.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_STACK_VECTOR_BASE_H__
20 #define __TPIE_INTERNAL_STACK_VECTOR_BASE_H__
21 
26 #include <tpie/array.h>
27 #include <tpie/util.h>
28 
29 namespace tpie {
30 
37 template <typename T, typename child_t>
39 protected:
42 
44  size_t m_size;
45 public:
46  typedef T value_type;
47 
52 
56  static double memory_overhead() {
57  return array<T>::memory_overhead() - sizeof(array<T>) + sizeof(child_t);
58  }
59 
70  m_elements(size, b), m_size(0) {}
71 
77  void resize(size_t size=0) {m_elements.resize(size); m_size=0;}
78 
82  inline bool empty() const {return m_size==0;}
83 
87  inline size_t size() const {return m_size;}
88 
92  inline void clear(){m_size=0;}
93 };
94 
95 }
96 #endif //__TPIE_INTERNAL_STACK_VECTOR_BASE_H__
Base class of data structures with linear memory usage.
Definition: util.h:73
size_t m_size
Number of elements pushed to the structure.
void resize(size_t size=0)
Change the capacity of the structure and clear all elements.
size_t size() const
Return the number of elements in the data structure.
A base class for a generic internal fixed size stack and vector.
void clear()
Clear the data structure of all elements.
Generic internal array with known memory requirements.
static double memory_overhead()
Return the memory overhead of the structure.
Class storring a reference to a memory bucket.
Definition: memory.h:366
Miscellaneous utility functions.
static double memory_coefficient()
Return the memory coefficient of the structure.
static double memory_coefficient()
Return the memory coefficient of the structure.
Definition: array.h:393
void resize(size_t size, const T &elm)
Change the size of the array.
Definition: array.h:485
static double memory_overhead()
Return the memory overhead of the structure.
Definition: array.h:400
array< T > m_elements
Element storage.
bool empty() const
Check if no elements are currently pushed to the structure.
internal_stack_vector_base(size_t size=0, tpie::memory_bucket_ref b=memory_bucket_ref())
Construct structure with given capacity.