Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/circBuffer.h

Go to the documentation of this file.
00001 // Filename: circBuffer.h
00002 // Created by:  drose (08Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef CIRCBUFFER_H
00020 #define CIRCBUFFER_H
00021 
00022 #include <pandabase.h>
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : CircBuffer
00026 // Description : This class implements a queue of some type via a
00027 //               circular buffer.  The circular buffer has the
00028 //               advantage that no synchronization is required when
00029 //               one process adds to the queue while another process
00030 //               extracts.  It works for any kind of Thing that has a
00031 //               valid assignment operator and copy constructor
00032 //               defined.
00033 ////////////////////////////////////////////////////////////////////
00034 template<class Thing, int max_size>
00035 class CircBuffer {
00036 public:
00037   INLINE CircBuffer();
00038   INLINE ~CircBuffer();
00039 
00040   // Methods that are safe to call without synchronization primitives
00041   // from either thread.
00042   INLINE int size() const;
00043 
00044   // Methods that are safe to call without synchronization primitives
00045   // only from the reader thread.
00046   INLINE bool empty() const;
00047 
00048   INLINE const Thing &front() const;
00049   INLINE Thing &front();
00050   INLINE void pop_front();
00051 
00052   INLINE const Thing &operator[] (int n) const;
00053   INLINE Thing &operator[] (int n);
00054 
00055   // Methods that are safe to call without synchronization primitives
00056   // only from the writer thread.
00057   INLINE bool full() const;
00058 
00059   INLINE const Thing &back() const;
00060   INLINE Thing &back();
00061   INLINE void push_back(const Thing &t);
00062 
00063 private:
00064   Thing _array[max_size+1];
00065   int _in, _out;
00066 };
00067 
00068 #include "circBuffer.I"
00069 
00070 #endif

Generated on Fri May 2 00:38:18 2003 for Panda by doxygen1.3