aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/tier1/utlqueue.h
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /sp/src/public/tier1/utlqueue.h
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'sp/src/public/tier1/utlqueue.h')
-rw-r--r--sp/src/public/tier1/utlqueue.h114
1 files changed, 114 insertions, 0 deletions
diff --git a/sp/src/public/tier1/utlqueue.h b/sp/src/public/tier1/utlqueue.h
new file mode 100644
index 00000000..30a4fdd4
--- /dev/null
+++ b/sp/src/public/tier1/utlqueue.h
@@ -0,0 +1,114 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef UTLQUEUE_H
+#define UTLQUEUE_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "utlvector.h"
+
+// T is the type stored in the stack
+template< class T >
+class CUtlQueue
+{
+public:
+
+ // constructor: lessfunc is required, but may be set after the constructor with
+ // SetLessFunc
+ CUtlQueue( int growSize = 0, int initSize = 0 );
+ CUtlQueue( T *pMemory, int numElements );
+
+ // return the item from the front of the queue and delete it
+ T const& RemoveAtHead();
+ // return the item from the end of the queue and delete it
+ T const& RemoveAtTail();
+
+ // return item at the front of the queue
+ T const& Head();
+ // return item at the end of the queue
+ T const& Tail();
+
+ // Add a new item to the end of the queue
+ void Insert( T const &element );
+
+ // checks if an element of this value already exists on the stack, returns true if it does
+ bool Check( T const element );
+
+ // Returns the count of elements in the stack
+ int Count() const { return m_heap.Count(); }
+
+ // doesn't deallocate memory
+ void RemoveAll() { m_heap.RemoveAll(); }
+
+ // Memory deallocation
+ void Purge() { m_heap.Purge(); }
+
+protected:
+ CUtlVector<T> m_heap;
+ T m_current;
+};
+
+template< class T >
+inline CUtlQueue<T>::CUtlQueue( int growSize, int initSize ) :
+ m_heap(growSize, initSize)
+{
+}
+
+template< class T >
+inline CUtlQueue<T>::CUtlQueue( T *pMemory, int numElements ) :
+ m_heap(pMemory, numElements)
+{
+}
+
+template <class T>
+inline T const& CUtlQueue<T>::RemoveAtHead()
+{
+ m_current = m_heap[0];
+ m_heap.Remove((int)0);
+ return m_current;
+}
+
+template <class T>
+inline T const& CUtlQueue<T>::RemoveAtTail()
+{
+ m_current = m_heap[ m_heap.Count() - 1 ];
+ m_heap.Remove((int)(m_heap.Count() - 1));
+ return m_current;
+}
+
+template <class T>
+inline T const& CUtlQueue<T>::Head()
+{
+ m_current = m_heap[0];
+ return m_current;
+}
+
+template <class T>
+inline T const& CUtlQueue<T>::Tail()
+{
+ m_current = m_heap[ m_heap.Count() - 1 ];
+ return m_current;
+}
+
+template <class T>
+void CUtlQueue<T>::Insert( T const &element )
+{
+ int index = m_heap.AddToTail();
+ m_heap[index] = element;
+}
+
+template <class T>
+bool CUtlQueue<T>::Check( T const element )
+{
+ int index = m_heap.Find(element);
+ return ( index != -1 );
+}
+
+
+#endif // UTLQUEUE_H