RingBuffer.hpp
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 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #ifndef ICL_CORE_RING_BUFFER_HPP_INCLUDED
00024 #define ICL_CORE_RING_BUFFER_HPP_INCLUDED
00025 
00026 namespace icl_core {
00027 
00028 template <typename T>
00029 typename RingBuffer<T>::array_range RingBuffer<T>::arrayOne()
00030 {
00031   if (m_write >= m_read)
00032   {
00033     return array_range(&m_buffer[m_read], m_write-m_read);
00034   }
00035   else
00036   {
00037     return array_range(&m_buffer[m_read], m_buffer.size()-m_read);
00038   }
00039 }
00040 
00041 template <typename T>
00042 typename RingBuffer<T>::const_array_range RingBuffer<T>::arrayOne() const
00043 {
00044   if (m_write >= m_read)
00045   {
00046     return const_array_range(&m_buffer[m_read], m_write-m_read);
00047   }
00048   else
00049   {
00050     return const_array_range(&m_buffer[m_read], m_buffer.size()-m_read);
00051   }
00052 }
00053 
00054 template <typename T>
00055 typename RingBuffer<T>::array_range RingBuffer<T>::arrayTwo()
00056 {
00057   if (m_write >= m_read)
00058   {
00059     return array_range(&m_buffer[m_write], 0);
00060   }
00061   else
00062   {
00063     return array_range(&m_buffer[0], m_write);
00064   }
00065 }
00066 
00067 template <typename T>
00068 typename RingBuffer<T>::const_array_range RingBuffer<T>::arrayTwo() const
00069 {
00070   if (m_write >= m_read)
00071   {
00072     return const_array_range(&m_buffer[m_write], 0);
00073   }
00074   else
00075   {
00076     return const_array_range(&m_buffer[0], m_write);
00077   }
00078 }
00079 
00080 template <typename T>
00081 typename RingBuffer<T>::array_range RingBuffer<T>::emptyArrayOne()
00082 {
00083   if (m_write >= m_read)
00084   {
00085     if (m_read == 0)
00086     {
00087       return array_range(&m_buffer[m_write], m_buffer.size()-m_write-1);
00088     }
00089     else
00090     {
00091       return array_range(&m_buffer[m_write], m_buffer.size()-m_write);
00092     }
00093   }
00094   else
00095   {
00096     return array_range(&m_buffer[m_write], m_read-m_write-1);
00097   }
00098 }
00099 
00100 template <typename T>
00101 typename RingBuffer<T>::const_array_range RingBuffer<T>::emptyArrayOne() const
00102 {
00103   if (m_write >= m_read)
00104   {
00105     if (m_read == 0)
00106     {
00107       return const_array_range(&m_buffer[m_write], m_buffer.size()-m_write-1);
00108     }
00109     else
00110     {
00111       return const_array_range(&m_buffer[m_write], m_buffer.size()-m_write);
00112     }
00113   }
00114   else
00115   {
00116     return const_array_range(&m_buffer[m_write], m_read-m_write-1);
00117   }
00118 }
00119 
00120 template <typename T>
00121 typename RingBuffer<T>::array_range RingBuffer<T>::emptyArrayTwo()
00122 {
00123   if (m_write >= m_read)
00124   {
00125     return array_range(&m_buffer[0], (m_read>0?m_read:1) - 1);
00126   }
00127   else
00128   {
00129     return array_range(&m_buffer[m_read], 0);
00130   }
00131 }
00132 
00133 template <typename T>
00134 typename RingBuffer<T>::const_array_range RingBuffer<T>::emptyArrayTwo() const
00135 {
00136   if (m_write >= m_read)
00137   {
00138     return const_array_range(&m_buffer[0], (m_read>0?m_read:1) - 1);
00139   }
00140   else
00141   {
00142     return const_array_range(&m_buffer[m_read], 0);
00143   }
00144 }
00145 
00146 template <typename T>
00147 void RingBuffer<T>::skip(size_type count)
00148 {
00149   if (count >= size())
00150   {
00151     clear();
00152   }
00153   else
00154   {
00155     m_read = (m_read+count) % m_buffer.size();
00156   }
00157 }
00158 
00159 template <typename T>
00160 void RingBuffer<T>::fakeWrite(size_t count)
00161 {
00162   if (count > reserve())
00163   {
00164     count = reserve();
00165   }
00166   m_write = (m_write + count) % m_buffer.size();
00167 }
00168 
00170 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00171 
00175 template <typename T>
00176 void RingBuffer<T>::Clear()
00177 {
00178   clear();
00179 }
00180 
00182 
00187 template <typename T>
00188 void RingBuffer<T>::Write(const T& val, bool overwrite)
00189 {
00190   write(val, overwrite);
00191 }
00192 
00194 
00199 template <typename T>
00200 const T& RingBuffer<T>::At(size_type pos) const
00201 {
00202   return at(pos);
00203 }
00204 
00206 
00211 template <typename T>
00212 T& RingBuffer<T>::At(size_type pos)
00213 {
00214   return at(pos);
00215 }
00216 
00220 template <typename T>
00221 void RingBuffer<T>::Skip()
00222 {
00223   skip();
00224 }
00225 
00227 
00230 template <typename T>
00231 T RingBuffer<T>::Read()
00232 {
00233   return read();
00234 }
00235 
00239 template <typename T>
00240 typename RingBuffer<T>::size_type RingBuffer<T>::Size() const
00241 {
00242   return size();
00243 }
00244 
00248 template <typename T>
00249 typename RingBuffer<T>::size_type RingBuffer<T>::Capacity() const
00250 {
00251   return capacity();
00252 }
00253 
00255 
00260 template <typename T>
00261 void RingBuffer<T>::SetCapacity(size_type capacity)
00262 {
00263   setCapacity(capacity);
00264 }
00265 
00266 #endif
00267 
00268 
00269 }
00270 
00271 #endif


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19