SearchableStack.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00025 //----------------------------------------------------------------------
00026 #ifndef ICL_CORE_SEARCHABLE_STACK_H_INCLUDED
00027 #define ICL_CORE_SEARCHABLE_STACK_H_INCLUDED
00028 
00029 #include <functional>
00030 #include <vector>
00031 
00032 #include "icl_core/BaseTypes.h"
00033 #include "icl_core/TemplateHelper.h"
00034 
00035 namespace icl_core {
00036 
00041 template <typename T, typename TCompare = std::equal_to<T>, typename TAlloc = std::allocator<T> >
00042 class SearchableStack : protected std::vector<T, TAlloc>
00043 {
00044 public:
00048   typedef typename std::vector<T>::const_iterator const_iterator;
00050   typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
00052   typedef typename std::vector<T>::size_type size_type;
00053 
00055   SearchableStack() : std::vector<T, TAlloc>(), m_comp() { }
00056 
00058   void clear() { std::vector<T, TAlloc>::clear(); }
00060   bool empty() const { return std::vector<T, TAlloc>::empty(); }
00062   size_type size() const { return std::vector<T, TAlloc>::size(); }
00063 
00065   void push(typename ConvertToRef<T>::ToConstRef t) { std::vector<T, TAlloc>::push_back(t); }
00067   void pop() { std::vector<T, TAlloc>::pop_back(); }
00069   typename ConvertToRef<T>::ToRef top() { return std::vector<T, TAlloc>::back(); }
00071   typename ConvertToRef<T>::ToConstRef top() const { return std::vector<T, TAlloc>::back(); }
00072 
00074   const_iterator begin() const { return std::vector<T, TAlloc>::begin(); }
00076   const_iterator end() const { return std::vector<T, TAlloc>::end(); }
00078   const_reverse_iterator rbegin() const { return std::vector<T, TAlloc>::rbegin(); }
00080   const_reverse_iterator rend() const { return std::vector<T, TAlloc>::rend(); }
00081 
00083   const_iterator find(typename ConvertToRef<T>::ToConstRef t) const
00084   {
00085     for (const_iterator it = begin(); it != end(); ++it)
00086     {
00087       if (m_comp(*it, t)) { return it; }
00088     }
00089     return end();
00090   }
00091 
00092   TCompare m_comp;
00093 };
00094 
00095 typedef SearchableStack<uint8_t> Unsigned8SearchableStack;
00096 typedef SearchableStack<uint16_t> Unsigned16SearchableStack;
00097 typedef SearchableStack<uint32_t> Unsigned32SearchableStack;
00098 typedef SearchableStack<uint64_t> Unsigned64SearchableStack;
00099 typedef SearchableStack<int8_t> Signed8SearchableStack;
00100 typedef SearchableStack<int16_t> Signed16SearchableStack;
00101 typedef SearchableStack<int32_t> Signed32SearchableStack;
00102 typedef SearchableStack<int64_t> Signed64SearchableStack;
00103 typedef SearchableStack<float> FloaSearchableStack;
00104 typedef SearchableStack<double> DoubleSearchableStack;
00105 
00106 }
00107 
00108 #endif


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03