''' -----------------------------------------------------------------------------
''' Project	 : Scandir
''' Class	 : ClsAnneau
''' 
''' -----------------------------------------------------------------------------
''' <summary>
''' Classe permettant de faire un tampon sous forme d'anneau
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	[nicolas]	22/10/2005	Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class ClsAnneau
    Private mAnneau As Queue
    Private mMaxCount As Integer = 0
    Private Sub New()
        'e
    End Sub
    Private Sub New(ByRef Obj As ClsAnneau)
        'e
    End Sub
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Constructeur de la classe
    ''' </summary>
    ''' <param name="NbItem">Nombre d'élément dans l'anneau</param>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[nicolas]	22/10/2005	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Sub New(ByVal NbItem As Integer)
        Dim i As Integer
        If NbItem <= 0 Then NbItem = 10
        mMaxCount = NbItem
        mAnneau = New Queue
    End Sub
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Ajoute un nouvel élément, retourne false si echec (anneau plein)
    ''' </summary>
    ''' <param name="pObj">Objet à ajouter</param>
    ''' <returns></returns>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[nicolas]	22/10/2005	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Function AddItem(ByRef pObj As Object) As Boolean
        If mAnneau.Count < mMaxCount Then
            SyncLock mAnneau
                If mAnneau.Count < mMaxCount Then
                    mAnneau.Enqueue(pObj)
                    Return True
                Else
                    Return False
                End If
            End SyncLock
        Else
            Return False
        End If
    End Function
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Retourne un Item de l'anneau
    ''' </summary>
    ''' <param name="ReleaseObject">true pour "effacer" la cellule</param>
    ''' <returns></returns>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[nicolas]	22/10/2005	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Function GetItem(Optional ByVal ReleaseObject As Boolean = True) As Object
        Dim mObj As Object
        If mAnneau.Count <= 0 Then
            Return Nothing
        Else
            SyncLock mAnneau
                If mAnneau.Count <= 0 Then
                    Return Nothing
                Else
                    If ReleaseObject Then
                        mObj = mAnneau.Dequeue()
                    Else
                        mObj = mAnneau.Peek()
                    End If
                    Return mObj
                End If
            End SyncLock
        End If
    End Function
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Retourne le nombre de case replie dans l'anneau
    ''' </summary>
    ''' <value></value>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[nicolas]	28/10/2005	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public ReadOnly Property Count() As Integer
        Get
            Return mAnneau.Count
        End Get
    End Property
    Protected Overrides Sub Finalize()
        mAnneau = Nothing
        MyBase.Finalize()
    End Sub
End Class
