00001 /* 00002 * WOscLib, an object oriented OSC library. 00003 * Copyright (C) 2005 Uli Clemens Franke, Weiss Engineering LTD, Switzerland. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * For details see lgpl.txt 00020 * 00021 * Weiss Engineering LTD. 00022 * Florastrass 42 00023 * 8610 Uster 00024 * Switzerland 00025 * 00026 * uli.franke@weiss.ch 00027 */ 00028 00029 /** WOscQueueItem and WOscPriorityQueue header file. 00030 * \file 00031 * 00032 * $Author: cls-nebadje $ ( \ref _UcfWOscLib ) 00033 * $Date: 2006-05-16 21:21:41 $ 00034 * $Revision: 1.4 $ 00035 * 00036 * Copyright (c) Weiss Engineering Ltd 00037 * 00038 */ 00039 #ifndef __WOSCPRIORITYQUEUE_H__ 00040 #define __WOSCPRIORITYQUEUE_H__ 00041 00042 #include "WOscNetReturn.h" 00043 #include "WOscLib.h" 00044 #include "WOscTimeTag.h" 00045 00046 /* ----------------------------------------------------------------------- */ 00047 /* WOscQueueItem */ 00048 /* ----------------------------------------------------------------------- */ 00049 00050 /** Items which can be scheduled in a priority queue. 00051 * Priority-queue items are time-tags with a network return address. They get 00052 * queued after their time-tag values in the priority queue. 00053 * 00054 * \remarks 00055 * Any class inherited from this base class can be queued in the 00056 * priority-queue. 00057 * 00058 * \see 00059 * WOscPriorityQueue and WOscNetReturn 00060 */ 00061 class WOSC_EXPORT WOscQueueItem : public WOscTimeTag 00062 { 00063 public: 00064 WOscQueueItem(const WOscTimeTag& timeTag, WOscNetReturn* ra) : 00065 WOscTimeTag(timeTag) 00066 { 00067 /* copy reference */ 00068 m_ra = ra; 00069 /* register myself, since i'm using it */ 00070 m_ra->AddParent(); 00071 } 00072 virtual ~WOscQueueItem() 00073 { 00074 /* if it's a received packet, it should have a 00075 * return address. unregister it before death 00076 * of this object. 00077 */ 00078 if ( m_ra ) 00079 m_ra->RemoveParent(); 00080 } 00081 /** When removing the network return address from the queue item, the 00082 * caller must decrement the reference counter himself. 00083 */ 00084 WOscNetReturn* RemoveNetworkReturnAddress() 00085 { 00086 WOscNetReturn* tmp = m_ra; 00087 m_ra = NULL; 00088 return tmp; 00089 } 00090 00091 private: 00092 WOscQueueItem(); 00093 WOscQueueItem(const WOscQueueItem&); 00094 /** As long we own the reference counted object we have to decrement 00095 * the usage counter. 00096 */ 00097 WOscNetReturn* m_ra; 00098 }; 00099 00100 /* ----------------------------------------------------------------------- */ 00101 /* WOscPriorityQueue */ 00102 /* ----------------------------------------------------------------------- */ 00103 #if WOSC_USE_PRIORITY_QUEUE == 1 00104 /** Sorts queue-items by their time tag when inserted. 00105 * The earliest items can be queried and/or removed. 00106 * 00107 * \remarks 00108 * The queue items are stored internally only by reference, 00109 * the user must control the life (allocation and deletion) 00110 * of the queue items. 00111 * 00112 * \see 00113 * WOscQueueItem 00114 */ 00115 class WOSC_EXPORT WOscPriorityQueue 00116 { 00117 public: 00118 WOscPriorityQueue(int initialCapacity); 00119 virtual ~WOscPriorityQueue(); 00120 00121 void InsertItem(WOscQueueItem *item); 00122 WOscQueueItem* RemoveEarliestItem(); 00123 WOscTimeTag GetEarliestTimeTag(); 00124 int GetNumItems(); 00125 00126 private: 00127 void DoubleCapacity(); 00128 void RemoveItem(int idx); 00129 00130 /** Pointer to the priority queue. */ 00131 WOscQueueItem** m_list; 00132 /** Number of item is the queue. */ 00133 int m_itemsInList; 00134 /** Current list capacity. Can be doubled by calling doubleCapacity(). */ 00135 int m_listCapacity; 00136 }; 00137 00138 #endif // #if WOSC_USE_PRIORITY_QUEUE == 1 00139 00140 #endif // #ifndef __WOSCPRIORITYQUEUE_H__