NptQueue.h

00001 /*****************************************************************
00002 |
00003 |   Neptune - Queue
00004 |
00005 |   (c) 2001-2006 Gilles Boccon-Gibod
00006 |   Author: Gilles Boccon-Gibod (bok@bok.net)
00007 |
00008  ****************************************************************/
00009 
00010 #ifndef _NPT_QUEUE_H_
00011 #define _NPT_QUEUE_H_
00012 
00013 /*----------------------------------------------------------------------
00014 |   includes
00015 +---------------------------------------------------------------------*/
00016 #include "NptTypes.h"
00017 #include "NptConstants.h"
00018 
00019 /*----------------------------------------------------------------------
00020 |   NPT_QueueItem
00021 +---------------------------------------------------------------------*/
00022 class NPT_QueueItem;
00023 
00024 /*----------------------------------------------------------------------
00025 |   NPT_GenericQueue
00026 +---------------------------------------------------------------------*/
00027 class NPT_GenericQueue
00028 {
00029  public:
00030     // class methods
00031     static NPT_GenericQueue* CreateInstance(NPT_Cardinal max_items = 0);
00032 
00033     // methods
00034     virtual           ~NPT_GenericQueue() {}
00035     virtual NPT_Result Push(NPT_QueueItem* item) = 0; 
00036     virtual NPT_Result Pop(NPT_QueueItem*& item, 
00037                            bool            blocking = true) = 0;
00038 
00039  protected:
00040     // methods
00041     NPT_GenericQueue() {}
00042 };
00043 
00044 /*----------------------------------------------------------------------
00045 |   NPT_Queue
00046 +---------------------------------------------------------------------*/
00047 template <class T>
00048 class NPT_Queue
00049 {
00050  public:
00051     // methods
00052     NPT_Queue(NPT_Cardinal max_items = 0) :
00053         m_Delegate(NPT_GenericQueue::CreateInstance(max_items)) {}
00054     virtual ~NPT_Queue<T>() { delete m_Delegate; }
00055     virtual NPT_Result Push(T* item) {
00056         return m_Delegate->Push(reinterpret_cast<NPT_QueueItem*>(item));
00057     }
00058     virtual NPT_Result Pop(T*& item, bool blocking = true) {
00059         return m_Delegate->Pop(reinterpret_cast<NPT_QueueItem*&>(item), 
00060                                blocking);
00061     }
00062 
00063  protected:
00064     // members
00065     NPT_GenericQueue* m_Delegate;
00066 };
00067 
00068 #endif // _NPT_QUEUE_H_