Snippets

SeanB Push Pop Argument Stack for dataflex

Created by SeanB
Function StrToSize Global String sSize Returns Integer  
    Integer iMultiply 
    Integer iSize 
    
    Move (Uppercase(sSize)) to sSize
    If (Pos("M",sSize)) Move (1024) to iMultiply
    If (Pos("K",sSize)) Move (1) to iMultiply
    If (Pos("G",sSize)) Move (1024*1024) to iMultiply
    
    Move (Replaces("K",sSize,"")) to sSize
    Move (Replaces("M",sSize,"")) to sSize
    Move (Replaces("G",sSize,"")) to sSize
    
    If (iMultiply>0) Begin 
        Move ((Number(sSize))*iMultiply) to iSize
        Move (iSize*1024) to iSize
    End
    Else Move sSize to iSize
    
    Function_Return iSize 
End_Function

Object oArgumentStack is a cObject 
    Property Integer[] paItems 
    
    //todo:better way of doing this (StrToSize)
    Procedure Push Global String sSize 
        Integer[] aItems 
        Integer iArgSize
        
        Get paItems to aItems 
        Get_Argument_Size to iArgSize
        Move iArgSize to aItems[sizeOfArray(aItems)]
        Set paItems to aItems
        
        Set_Argument_Size (StrToSize(sSize))
    End_Procedure
    
    Procedure Pop Global 
        Integer[] aItems 
        Integer iPos 
        
        Get paItems to aItems 
        Move ((SizeOfArray(aItems))-1) to iPos
        If (iPos<0) Procedure_Return  
        Set_Argument_Size aItems[iPos]
        Set paItems to (ResizeArray(aItems,iPos))
    End_Procedure
End_Object

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.