tSearchableStack.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_T_SEARCHABLE_STACK_H_INCLUDED
27 #define ICL_CORE_T_SEARCHABLE_STACK_H_INCLUDED
28 
29 #include <functional>
30 #include <vector>
31 
32 #include "icl_core/BaseTypes.h"
33 #include "icl_core/Deprecate.h"
35 
36 namespace icl_core {
37 
42 template <typename T, typename Compare = std::equal_to<T>, typename Alloc = std::allocator<T> >
43 class ICL_CORE_VC_DEPRECATE tSearchableStack : protected std::vector<T, Alloc>
44 {
45 public:
49  typedef typename std::vector<T>::const_iterator const_iterator;
51  typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
53  typedef typename std::vector<T>::size_type size_type;
54 
56  tSearchableStack() : std::vector<T, Alloc>(), m_comp() { }
57 
59  void clear() { std::vector<T, Alloc>::clear(); }
61  bool empty() const { return std::vector<T, Alloc>::empty(); }
63  size_type size() const { return std::vector<T, Alloc>::size(); }
64 
66  void push(typename ConvertToRef<T>::ToConstRef t) { std::vector<T, Alloc>::push_back(t); }
68  void pop() { std::vector<T, Alloc>::pop_back(); }
70  typename ConvertToRef<T>::ToRef top() { return std::vector<T, Alloc>::back(); }
72  typename ConvertToRef<T>::ToConstRef top() const { return std::vector<T, Alloc>::back(); }
73 
75  const_iterator begin() const { return std::vector<T, Alloc>::begin(); }
77  const_iterator end() const { return std::vector<T, Alloc>::end(); }
79  const_reverse_iterator rbegin() const { return std::vector<T, Alloc>::rbegin(); }
81  const_reverse_iterator rend() const { return std::vector<T, Alloc>::rend(); }
82 
84  const_iterator find(typename ConvertToRef<T>::ToConstRef t) const
85  {
86  for (const_iterator it = begin(); it != end(); ++it)
87  {
88  if (m_comp(*it, t)) { return it; }
89  }
90  return end();
91  }
92 
93  Compare m_comp;
95 
106 
107 }
108 
109 #endif
Helper definitions for template programming.
void pop()
Pops an element off the stack.
void push(typename ConvertToRef< T >::ToConstRef t)
Pushes an element onto the stack.
size_type size() const
Returns the number of elements on the stack.
std::vector< T >::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
tSearchableStack< tSigned8 > tSigned8SearchableStack
#define ICL_CORE_VC_DEPRECATE
Definition: Deprecate.h:35
std::vector< T >::const_iterator const_iterator
tSearchableStack< tSigned32 > tSigned32SearchableStack
Contains macros to deprecate classes, types, functions and variables.
tSearchableStack< tUnsigned64 > tUnsigned64SearchableStack
tSearchableStack< tUnsigned32 > tUnsigned32SearchableStack
tSearchableStack< tSigned16 > tSigned16SearchableStack
const_iterator begin() const
Returns an iterator to the bottom element of the stack.
tSearchableStack< tUnsigned8 > tUnsigned8SearchableStack
std::vector< T >::size_type size_type
Size type.
const_iterator find(typename ConvertToRef< T >::ToConstRef t) const
Finds a specific element on the stack by linear search.
void clear()
Clears the stack.
tSearchableStack< tSigned64 > tSigned64SearchableStack
tSearchableStack< tUnsigned16 > tUnsigned16SearchableStack
tSearchableStack()
Constructs an empty stack.
const_reverse_iterator rend() const
Returns a reverse iterator to the bottom end of the stack.
const_reverse_iterator rbegin() const
Returns a reverse iterator to the top element of the stack.
tSearchableStack< tFloat > tFloatSearchableStack
tSearchableStack< tDouble > tDoubleSearchableStack
Contains Interface base classes and base types.
ICL_CORE_VC_DEPRECATE SetRelation tSetRelation ICL_CORE_GCC_DEPRECATE
Definition: SetHelper.h:42
ConvertToRef< T >::ToRef top()
Returns a reference to the top stack element.
bool empty() const
Returns true if the stack is empty.
ConvertToRef< T >::ToConstRef top() const
Returns a const reference to the top stack element.
const_iterator end() const
Returns an iterator to the top end of the stack.


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