GNU Radio 3.5.1 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 
00030 /*!
00031  * \brief template class for interleaver fifo
00032  */
00033 
00034 template<class symbol_type>
00035 class interleaver_fifo {
00036  public:
00037 
00038   interleaver_fifo (unsigned int size);
00039   ~interleaver_fifo ();
00040 
00041   //! reset interleaver (flushes contents and resets commutator)
00042   void reset ();
00043   
00044   //! stuff a symbol into the fifo and return the oldest
00045   symbol_type stuff (symbol_type input){
00046     if (m_size == 0)
00047       return input;
00048 
00049     symbol_type retval = m_fifo[m_position];
00050     m_fifo[m_position] = input;
00051     m_position++;
00052     if (m_position >= m_size)
00053       m_position = 0;
00054 
00055     return retval;
00056   }
00057 
00058 protected:
00059   unsigned int  m_size;
00060   unsigned int  m_position;
00061   symbol_type   *m_fifo;
00062 };
00063 
00064 template<class symbol_type>
00065 interleaver_fifo<symbol_type>::interleaver_fifo (unsigned int size)
00066 {
00067   m_size = size;
00068   m_position = 0;
00069   m_fifo = new symbol_type[size];
00070   memset (m_fifo, 0, m_size * sizeof (symbol_type));
00071 }
00072 
00073 template<class symbol_type>
00074 interleaver_fifo<symbol_type>::~interleaver_fifo ()
00075 {
00076   delete [] m_fifo;
00077 }
00078 
00079 template<class symbol_type> void
00080 interleaver_fifo<symbol_type>::reset ()
00081 {
00082   m_position = 0;
00083   memset (m_fifo, 0, m_size * sizeof (symbol_type));
00084 }
00085 
00086 #endif /* _INTERLEAVER_FIFO_H_ */