SearchableStack.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 #ifndef ICL_CORE_SEARCHABLE_STACK_H_INCLUDED
27 #define ICL_CORE_SEARCHABLE_STACK_H_INCLUDED
28 
29 #include <functional>
30 #include <vector>
31 
32 #include "icl_core/BaseTypes.h"
34 
35 namespace icl_core {
36 
41 template <typename T, typename TCompare = std::equal_to<T>, typename TAlloc = std::allocator<T> >
42 class SearchableStack : protected std::vector<T, TAlloc>
43 {
44 public:
48  typedef typename std::vector<T>::const_iterator const_iterator;
50  typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
52  typedef typename std::vector<T>::size_type size_type;
53 
55  SearchableStack() : std::vector<T, TAlloc>(), m_comp() { }
56 
58  void clear() { std::vector<T, TAlloc>::clear(); }
60  bool empty() const { return std::vector<T, TAlloc>::empty(); }
62  size_type size() const { return std::vector<T, TAlloc>::size(); }
63 
65  void push(typename ConvertToRef<T>::ToConstRef t) { std::vector<T, TAlloc>::push_back(t); }
67  void pop() { std::vector<T, TAlloc>::pop_back(); }
69  typename ConvertToRef<T>::ToRef top() { return std::vector<T, TAlloc>::back(); }
71  typename ConvertToRef<T>::ToConstRef top() const { return std::vector<T, TAlloc>::back(); }
72 
74  const_iterator begin() const { return std::vector<T, TAlloc>::begin(); }
76  const_iterator end() const { return std::vector<T, TAlloc>::end(); }
78  const_reverse_iterator rbegin() const { return std::vector<T, TAlloc>::rbegin(); }
80  const_reverse_iterator rend() const { return std::vector<T, TAlloc>::rend(); }
81 
83  const_iterator find(typename ConvertToRef<T>::ToConstRef t) const
84  {
85  for (const_iterator it = begin(); it != end(); ++it)
86  {
87  if (m_comp(*it, t)) { return it; }
88  }
89  return end();
90  }
91 
92  TCompare m_comp;
93 };
94 
105 
106 }
107 
108 #endif
bool empty() const
Returns true if the stack is empty.
Helper definitions for template programming.
const_iterator find(typename ConvertToRef< T >::ToConstRef t) const
Finds a specific element on the stack by linear search.
ConvertToRef< T >::ToConstRef top() const
Returns a const reference to the top stack element.
SearchableStack< int16_t > Signed16SearchableStack
void pop()
Pops an element off the stack.
SearchableStack< int8_t > Signed8SearchableStack
const_iterator begin() const
Returns an iterator to the bottom element of the stack.
ConvertToRef< T >::ToRef top()
Returns a reference to the top stack element.
const_iterator end() const
Returns an iterator to the top end of the stack.
SearchableStack< uint16_t > Unsigned16SearchableStack
const_reverse_iterator rend() const
Returns a reverse iterator to the bottom end of the stack.
SearchableStack< double > DoubleSearchableStack
SearchableStack< uint8_t > Unsigned8SearchableStack
const_reverse_iterator rbegin() const
Returns a reverse iterator to the top element of the stack.
SearchableStack< uint64_t > Unsigned64SearchableStack
SearchableStack()
Constructs an empty stack.
SearchableStack< float > FloaSearchableStack
SearchableStack< uint32_t > Unsigned32SearchableStack
std::vector< T >::const_iterator const_iterator
size_type size() const
Returns the number of elements on the stack.
void clear()
Clears the stack.
std::vector< T >::size_type size_type
Size type.
Contains Interface base classes and base types.
SearchableStack< int64_t > Signed64SearchableStack
void push(typename ConvertToRef< T >::ToConstRef t)
Pushes an element onto the stack.
std::vector< T >::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
SearchableStack< int32_t > Signed32SearchableStack


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58