DS_QueueLinkedList.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file DS_QueueLinkedList.h
  11. /// \internal
  12. /// \brief A queue implemented as a linked list.
  13. ///
  14. #ifndef __QUEUE_LINKED_LIST_H
  15. #define __QUEUE_LINKED_LIST_H
  16. #include "DS_LinkedList.h"
  17. #include "Export.h"
  18. #include "RakMemoryOverride.h"
  19. /// The namespace DataStructures was only added to avoid compiler errors for commonly named data structures
  20. /// As these data structures are stand-alone, you can use them outside of RakNet for your own projects if you wish.
  21. namespace DataStructures
  22. {
  23. /// \brief A queue implemented using a linked list. Rarely used.
  24. template <class QueueType>
  25. class RAK_DLL_EXPORT QueueLinkedList
  26. {
  27. public:
  28. QueueLinkedList();
  29. QueueLinkedList( const QueueLinkedList& original_copy );
  30. bool operator= ( const QueueLinkedList& original_copy );
  31. QueueType Pop( void );
  32. QueueType& Peek( void );
  33. QueueType& EndPeek( void );
  34. void Push( const QueueType& input );
  35. unsigned int Size( void );
  36. void Clear( void );
  37. void Compress( void );
  38. private:
  39. LinkedList<QueueType> data;
  40. };
  41. template <class QueueType>
  42. QueueLinkedList<QueueType>::QueueLinkedList()
  43. {
  44. }
  45. template <class QueueType>
  46. inline unsigned int QueueLinkedList<QueueType>::Size()
  47. {
  48. return data.Size();
  49. }
  50. template <class QueueType>
  51. inline QueueType QueueLinkedList<QueueType>::Pop( void )
  52. {
  53. data.Beginning();
  54. return ( QueueType ) data.Pop();
  55. }
  56. template <class QueueType>
  57. inline QueueType& QueueLinkedList<QueueType>::Peek( void )
  58. {
  59. data.Beginning();
  60. return ( QueueType ) data.Peek();
  61. }
  62. template <class QueueType>
  63. inline QueueType& QueueLinkedList<QueueType>::EndPeek( void )
  64. {
  65. data.End();
  66. return ( QueueType ) data.Peek();
  67. }
  68. template <class QueueType>
  69. void QueueLinkedList<QueueType>::Push( const QueueType& input )
  70. {
  71. data.End();
  72. data.Add( input );
  73. }
  74. template <class QueueType>
  75. QueueLinkedList<QueueType>::QueueLinkedList( const QueueLinkedList& original_copy )
  76. {
  77. data = original_copy.data;
  78. }
  79. template <class QueueType>
  80. bool QueueLinkedList<QueueType>::operator= ( const QueueLinkedList& original_copy )
  81. {
  82. if ( ( &original_copy ) == this )
  83. return false;
  84. data = original_copy.data;
  85. }
  86. template <class QueueType>
  87. void QueueLinkedList<QueueType>::Clear ( void )
  88. {
  89. data.Clear();
  90. }
  91. } // End namespace
  92. #endif
粤ICP备19079148号