fifo.h

Go to the documentation of this file.
00001 //    sampalib.org ESL library and tools
00002 //    Copyright (C) 2007  Thierry Grellier
00003 //
00004 //    This program is free software; you can redistribute it and/or modify
00005 //    it under the terms of the GNU General Public License version 2 as
00006 //    published by the Free Software Foundation.
00007 //
00008 //    This program is distributed in the hope that it will be useful,
00009 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //    GNU General Public License for more details.
00012 //
00013 //    You should have received a copy of the GNU General Public License along
00014 //    with this program; if not, write to the Free Software Foundation, Inc.,
00015 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016 //
00017 //    contact: www.sampalib.org
00018 
00019 #ifndef SAMPA_FIFO_H
00020 #define SAMPA_FIFO_H
00021 
00022 #include "sampa/core/object.h"
00023 
00024 namespace Sampa {
00025  
00035   class Fifo : public Object {
00036   public:
00037     Fifo(const Name& name);
00038     bool  is_empty() const     { return m_size == 0; } 
00039     bool  is_full() const      { return m_size == get_capacity(); } 
00040     short peek() const         { return m_rd_ptr & m_depth_mask; } 
00041     short pop()                { short rd = m_rd_ptr; m_rd_ptr = (m_rd_ptr+1) & m_depth_mask; m_size--; return rd; } 
00042     short push()               { short wr = m_wr_ptr; m_wr_ptr = (m_wr_ptr+1) & m_depth_mask; m_size++; return wr; } 
00043     short pushable() const     { return m_size < get_capacity(); } 
00044     short get_capacity() const { return m_depth_mask + 1; } 
00045     short get_size() const     { return m_size; } 
00046     //@cond
00047   private:
00048     short m_size;
00049     short m_rd_ptr;
00050     short m_wr_ptr;
00051     short m_depth_mask;
00052     SAMPA_PERSISTENT(Fifo);
00053     //@endcond
00054   };
00055 
00064   class TraceFifo : public Object {
00065   public:
00066     TraceFifo(const Name& name);
00067     bool  is_empty() const     { return m_size == 0; } 
00068     bool  is_full() const      { return m_size == get_capacity(); } 
00069     short peek() const         { return m_rd_ptr & m_depth_mask; } 
00070     short pop();  
00071     short push(); 
00072     short pushable() const     { return m_size < get_capacity(); } 
00073     short get_capacity() const { return m_depth_mask + 1; } 
00074     short get_size() const     { return m_size; } 
00075     //@cond
00076   private:
00077     short m_size;
00078     short m_rd_ptr;
00079     short m_wr_ptr;
00080     short m_depth_mask;
00081     SAMPA_PERSISTENT(TraceFifo);
00082     //@endcond
00083   };
00084 
00085 }
00086 
00087 #endif

Generated on Sat Feb 16 16:23:15 2008 for Sampa by  doxygen 1.5.3