GNU Radio 3.4.2 C++ API
interleaver_fifo.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef _INTERLEAVER_FIFO_H_
00024 #define _INTERLEAVER_FIFO_H_
00025 
00026 
00027 #include <interleaver_fifo.h>
00028 #include <string.h>
00029 #include <strings.h>
00030 
00031 /*!
00032  * \brief template class for interleaver fifo
00033  */
00034 
00035 template<class symbol_type>
00036 class interleaver_fifo {
00037  public:
00038 
00039   interleaver_fifo (unsigned int size);
00040   ~interleaver_fifo ();
00041 
00042   //! reset interleaver (flushes contents and resets commutator)
00043   void reset ();
00044   
00045   //! stuff a symbol into the fifo and return the oldest
00046   symbol_type stuff (symbol_type input){
00047     if (m_size == 0)
00048       return input;
00049 
00050     symbol_type retval = m_fifo[m_position];
00051     m_fifo[m_position] = input;
00052     m_position++;
00053     if (m_position >= m_size)
00054       m_position = 0;
00055 
00056     return retval;
00057   }
00058 
00059 protected:
00060   unsigned int  m_size;
00061   unsigned int  m_position;
00062   symbol_type   *m_fifo;
00063 };
00064 
00065 template<class symbol_type>
00066 interleaver_fifo<symbol_type>::interleaver_fifo (unsigned int size)
00067 {
00068   m_size = size;
00069   m_position = 0;
00070   m_fifo = new symbol_type[size];
00071   memset (m_fifo, 0, m_size * sizeof (symbol_type));
00072 }
00073 
00074 template<class symbol_type>
00075 interleaver_fifo<symbol_type>::~interleaver_fifo ()
00076 {
00077   delete [] m_fifo;
00078 }
00079 
00080 template<class symbol_type> void
00081 interleaver_fifo<symbol_type>::reset ()
00082 {
00083   m_position = 0;
00084   memset (m_fifo, 0, m_size * sizeof (symbol_type));
00085 }
00086 
00087 #endif /* _INTERLEAVER_FIFO_H_ */