begin process at 2012 02 17 05:43:02
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > GESTION DE PILE FIFO DANS UNE CLASSE (SANS RECORDSET)

GESTION DE PILE FIFO DANS UNE CLASSE (SANS RECORDSET)


 Information sur la source

Note :
Aucune note
Catégorie :Divers Niveau :Débutant Date de création :17/09/2003 Date de mise à jour :17/09/2003 11:59:09 Vu / téléchargé :3 324 / 234

Auteur : facdaar

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Pour utiliser la classe, créer un objet :
dim objFIFO as cFifoStack

puis l'initialiser :
Set objFIFO = new cFifoStack

Pour empiler des données :
If objFIFO.StackIn(MaDonnéeAEmpiler) then
     'c'est stocké
else
     ' la pile est pleine, peut-etre reporter ce stockage. (pile mal dimensionnée)
endif

Pour dépiler :
If objFIFO.DataInStack then
    ' il y a qqch dans la pile
    if objFIFO.StackOut(LaDonnéeDépilée) then
        ' faire qqch avec 'LaDonnéeDépilée)
    else
        ' ne devrait pas arriver !
    endif
endif

ET ENFIN, qd on ne s'en sert plus:
Set objFIFO=Nothing

Source

  • ''
  • ' cFifoStack <BR>
  • ' Class to create a FIFO stack with the option to precise the length of the stack.
  • '
  • ' @remarks
  • ' This program is free software; you can redistribute it and/or modify
  • ' it under the terms of the GNU General Public License as published by
  • ' the Free Software Foundation; either version 2 of the License, or
  • ' (at your option) any later version.
  • '
  • ' This program is distributed in the hope that it will be useful,
  • ' but WITHOUT ANY WARRANTY; without even the implied warranty of
  • ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • ' GNU General Public License for more details.
  • '
  • ' You should have received a copy of the GNU General Public License
  • ' along with this program; if not, write to the Free Software
  • ' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  • '
  • ' @require
  • ' <UL TYPE=SQUARE>
  • ' <LI> OLE Automation - stdole2.tlb </LI>
  • ' </UL>
  • ' @author David ARNOLD
  • ' @version 1.0
  • ' @date 17-Sep-03
  • Option Explicit
  • '' Default stack size
  • Private Const iDEF_STACK_LENGTH As Integer = 1000
  • ''
  • ' Stack type. Contains the datas and indexes to hold the stack.
  • '
  • ' @param iStackIn_Index Index to input datas
  • ' @param iStackOut_Index Index to output datas
  • ' @param StackDatas Datas
  • Private Type Stack
  • iStackIn_Index As Integer
  • iStackOut_Index As Integer
  • StackDatas As Collection
  • End Type
  • '' Local stack
  • Private mStack As Stack
  • '' Stack length
  • Private mStackLength As Integer
  • '----------------------------------------------------------------------------------------------------------------------------------------------------
  • ' Public METHODS
  • '----------------------------------------------------------------------------------------------------------------------------------------------------
  • ''
  • ' Put a data in the stack.
  • '
  • '@param vData <B>IN PARAMETER</B>. Data to stack in.
  • '
  • '@return True if stack in has been done (false if not, when the stack is full, data in stack > stack length)
  • '@remarks
  • '@see
  • '@todo
  • '@bug
  • '@history
  • Public Function StackIn(ByVal vData As Variant) As Boolean
  • Attribute StackIn.VB_Description = "Put a data in the stack."
  • Dim tmpIndex As Integer
  • On Error GoTo StackIn_Error
  • tmpIndex = (mStack.iStackIn_Index + 1) Mod mStackLength
  • mStack.StackDatas.Add vData, "k" + CStr(tmpIndex)
  • mStack.iStackIn_Index = tmpIndex
  • StackIn = True
  • On Error GoTo 0
  • Exit Function
  • StackIn_Error:
  • StackIn = False
  • End Function
  • ''
  • ' Get a data from the stack.
  • '
  • '@param vData <B>OUT PARAMETER</B>. Data to stack out.
  • '
  • '@return True if stack out has been done (false if not, when the stack is empty, use property DataInStack).
  • '@remarks
  • '@see
  • '@todo
  • '@bug
  • '@history
  • Public Function StackOut(ByRef vData As Variant) As Boolean
  • Attribute StackOut.VB_Description = "Get a data from the stack."
  • Dim tmpIndex As Integer
  • On Error GoTo StackOut_Error
  • tmpIndex = (mStack.iStackOut_Index + 1) Mod mStackLength
  • vData = mStack.StackDatas.Item("k" + CStr(tmpIndex))
  • mStack.StackDatas.Remove "k" + CStr(tmpIndex)
  • mStack.iStackOut_Index = tmpIndex
  • StackOut = True
  • On Error GoTo 0
  • Exit Function
  • StackOut_Error:
  • StackOut = False
  • End Function
  • '----------------------------------------------------------------------------------------------------------------------------------------------------
  • ' Public PROPERTIES
  • '----------------------------------------------------------------------------------------------------------------------------------------------------
  • ''
  • ' Check if datas available in the stack.
  • '
  • '@return True if datas available in the stack.
  • '@remarks
  • '@see
  • '@todo
  • '@bug
  • '@history
  • Public Property Get DataInStack() As Boolean
  • Attribute DataInStack.VB_Description = "Check if datas available in the stack."
  • Attribute DataInStack.VB_ProcData.VB_Invoke_Property = ";Data"
  • DataInStack = (mStack.StackDatas.Count > 0)
  • End Property
  • ''
  • ' Let the length of the stack.
  • '
  • '@param iStackLength Length of the stack.
  • '@remarks
  • ' The stack has to be empty to change the length
  • '@see
  • '@todo
  • '@bug
  • '@history
  • Public Property Let StackLength(ByVal iStackLength As Integer)
  • Attribute StackLength.VB_Description = "Let the length of the stack."
  • Attribute StackLength.VB_ProcData.VB_Invoke_PropertyPut = ";Data"
  • If mStack.StackDatas.Count = 0 Then
  • mStackLength = iStackLength
  • mStack.iStackIn_Index = 0
  • mStack.iStackOut_Index = 0
  • End If
  • End Property
  • '----------------------------------------------------------------------------------------------------------------------------------------------------
  • ' Private METHODS
  • '----------------------------------------------------------------------------------------------------------------------------------------------------
  • ''
  • ' Standard Initialize class method
  • '@remarks Set the stack length to the default value.
  • '@see iDEF_STACK_LENGTH
  • '@todo
  • '@bug
  • '@history
  • Private Sub Class_Initialize()
  • mStackLength = iDEF_STACK_LENGTH
  • mStack.iStackIn_Index = 0
  • mStack.iStackOut_Index = 0
  • Set mStack.StackDatas = New Collection
  • End Sub
  • ''
  • ' Standard Terminate class method
  • '@remarks
  • '@see
  • '@todo
  • '@bug
  • '@history
  • Private Sub Class_Terminate()
  • mStackLength = 0
  • mStack.iStackIn_Index = 0
  • mStack.iStackOut_Index = 0
  • Set mStack.StackDatas = Nothing
  • End Sub
''
' cFifoStack <BR>
'      Class to create a FIFO stack with the option to precise the length of the stack.
'
' @remarks
'      This program is free software; you can redistribute it and/or modify
'      it under the terms of the GNU General Public License as published by
'      the Free Software Foundation; either version 2 of the License, or
'      (at your option) any later version.
'
'      This program is distributed in the hope that it will be useful,
'      but WITHOUT ANY WARRANTY; without even the implied warranty of
'      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'      GNU General Public License for more details.
'
'      You should have received a copy of the GNU General Public License
'      along with this program; if not, write to the Free Software
'      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'
' @require
' <UL TYPE=SQUARE>
' <LI>     OLE Automation - stdole2.tlb </LI>
' </UL>
' @author David ARNOLD
' @version 1.0
' @date 17-Sep-03

Option Explicit

'' Default stack size
Private Const iDEF_STACK_LENGTH As Integer = 1000

''
' Stack type. Contains the datas and indexes to hold the stack.
'
' @param    iStackIn_Index      Index to input datas
' @param    iStackOut_Index     Index to output datas
' @param    StackDatas          Datas
Private Type Stack
    iStackIn_Index As Integer
    iStackOut_Index As Integer
    StackDatas As Collection
End Type

'' Local stack
Private mStack As Stack
'' Stack length
Private mStackLength As Integer


'----------------------------------------------------------------------------------------------------------------------------------------------------
'                                   Public METHODS
'----------------------------------------------------------------------------------------------------------------------------------------------------


''
' Put a data in the stack.
'
'@param     vData   <B>IN PARAMETER</B>. Data to stack in.
'
'@return    True if stack in has been done (false if not, when the stack is full, data in stack > stack length)
'@remarks
'@see
'@todo
'@bug
'@history
Public Function StackIn(ByVal vData As Variant) As Boolean
Attribute StackIn.VB_Description = "Put a data in the stack."
    Dim tmpIndex As Integer
    
   On Error GoTo StackIn_Error

    tmpIndex = (mStack.iStackIn_Index + 1) Mod mStackLength
    mStack.StackDatas.Add vData, "k" + CStr(tmpIndex)
    mStack.iStackIn_Index = tmpIndex
    StackIn = True
   
   On Error GoTo 0
   Exit Function
StackIn_Error:
    StackIn = False
End Function

''
' Get a data from the stack.
'
'@param     vData   <B>OUT PARAMETER</B>. Data to stack out.
'
'@return    True if stack out has been done (false if not, when the stack is empty, use property DataInStack).
'@remarks
'@see
'@todo
'@bug
'@history
Public Function StackOut(ByRef vData As Variant) As Boolean
Attribute StackOut.VB_Description = "Get a data from the stack."
    Dim tmpIndex As Integer
    
   On Error GoTo StackOut_Error

    tmpIndex = (mStack.iStackOut_Index + 1) Mod mStackLength
    vData = mStack.StackDatas.Item("k" + CStr(tmpIndex))
    mStack.StackDatas.Remove "k" + CStr(tmpIndex)
    mStack.iStackOut_Index = tmpIndex
    StackOut = True

   On Error GoTo 0
   Exit Function
StackOut_Error:
    StackOut = False
End Function


'----------------------------------------------------------------------------------------------------------------------------------------------------
'                                   Public PROPERTIES
'----------------------------------------------------------------------------------------------------------------------------------------------------


''
' Check if datas available in the stack.
'
'@return    True if datas available in the stack.
'@remarks
'@see
'@todo
'@bug
'@history
Public Property Get DataInStack() As Boolean
Attribute DataInStack.VB_Description = "Check if datas available in the stack."
Attribute DataInStack.VB_ProcData.VB_Invoke_Property = ";Data"
    DataInStack = (mStack.StackDatas.Count > 0)
End Property

''
' Let the length of the stack.
'
'@param    iStackLength     Length of the stack.
'@remarks
'   The stack has to be empty to change the length
'@see
'@todo
'@bug
'@history
Public Property Let StackLength(ByVal iStackLength As Integer)
Attribute StackLength.VB_Description = "Let the length of the stack."
Attribute StackLength.VB_ProcData.VB_Invoke_PropertyPut = ";Data"
    If mStack.StackDatas.Count = 0 Then
        mStackLength = iStackLength
        mStack.iStackIn_Index = 0
        mStack.iStackOut_Index = 0
    End If
End Property


'----------------------------------------------------------------------------------------------------------------------------------------------------
'                                   Private METHODS
'----------------------------------------------------------------------------------------------------------------------------------------------------


''
' Standard Initialize class method
'@remarks Set the stack length to the default value.
'@see   iDEF_STACK_LENGTH
'@todo
'@bug
'@history
Private Sub Class_Initialize()
    mStackLength = iDEF_STACK_LENGTH
    mStack.iStackIn_Index = 0
    mStack.iStackOut_Index = 0
    Set mStack.StackDatas = New Collection
End Sub


''
' Standard Terminate class method
'@remarks
'@see
'@todo
'@bug
'@history
Private Sub Class_Terminate()
    mStackLength = 0
    mStack.iStackIn_Index = 0
    mStack.iStackOut_Index = 0
    Set mStack.StackDatas = Nothing
End Sub

 Conclusion

Je sais, ça existe déjà, mais voici ma version !

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   cFifoStack

Télécharger le zip


 Sources du même auteur

Source avec Zip SERVEUR TELNET (MULTI-CLIENTS)
Source avec Zip RÉCUPÉRATION DES ARGUMENTS D'UN ÉXÉCUTABLE LANCÉ EN LIGNE DE...
LIRE ET ÉCRIRE DANS LA BASE DE REGISTRE FACILEMENT QUELQUESO...
Source avec Zip CRÉER ET LIRE UN FICHIER ZIP DANS VB

 Sources de la même categorie

Source avec Zip TEXTBOX EN NUMÉRIQUE par 320C
Source avec Zip DÉCIMAL TO HEXDECIMAL par loulou27200
SOUS-TITRES : INCRÉMENTATION DE TOUTES LES CHAÎNES DE CARACT... par ALMIRA
Source avec Zip Source avec une capture EVALUER UN NOMBRE D'OBJETS AVEC UNE BALANCE ET DEUX ÉCHANTIL... par lexsty
Source avec Zip Source avec une capture PETIT LOGICIEL DE DEVIS SANS BD par lololilizozo

Commentaires et avis

Commentaire de cqui789 le 13/02/2005 16:31:02

tres interessant, je venait de me faire une gestion de pile dans un module classique mais je vais adapter ta classe, d'autant plus que je decouvre les classes donc interret double.

L'auteur indique, c'est toi ou tu nous fait profiter de tes outils (ce qui reste tres utile a des gents comme moi)

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 2,090 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales