HDO. Source of the class that manages the RDL ...

HDO. Source of the class that manages the RDL ...

Postby xmanuel » Thu Dec 01, 2016 7:40 pm

Some of you have asked me to study some source of HDO.
I leave you the complete code of the class THDORDL that is in charge of the management of the RDL is with the RDDRegister of the RDD.
Like all HDO class is made in C completely.

Code: Select all  Expand view

/***
 * Proyecto: Harbour Data Objects (HDO)
 * Fichero: hdoRDL.c
 * Descripcion: Gestion de de RDLs
 * Autor: Manu Exposito 2015-16
 * Fecha: 10/01/2016
 */


/*
 * Notas:
 * Solo tiene una DATA de solo lectura con una tabla Hash
 * { NOMBRE_RDL => PUNTERO_FUNCION_METODOS }
 */


#include "hdoRDL.h"

/***
 * Definicion de la clase con atributos y metodos
 */


CREATE_CLASS( "THDORDL", THDORDL, THDORDL_IVARCOUNT )
{
    /* Metodos */
    METHOD( "NEW",              THDORDL_NEW )
    METHOD( "REGISTER",         THDORDL_REGISTER )
    METHOD( "LIST",             THDORDL_LIST )
    METHOD( "ISREGISTERED",     THDORDL_ISREGISTERED )
    METHOD( "GETPOS",           THDORDL_GETPOS )
    METHOD( "GETNAME",          THDORDL_GETNAME )
    METHOD( "GETPFUNCBYNAME",   THDORDL_GETPFUNCBYNAME )
}
END_CLASS

/***
 * Metodo: NEW
 * Uso: Constructor de la clase
 * Parametros: Ninguno
 * Devuelve: Self, un objeto inicializado
 */


HB_METHOD( THDORDL_NEW )
{
    PHB_ITEM pSelf = hb_pSelf();

    PHB_ITEM pd = hb_hashNew( NULL );
    PHB_ITEM pKey = hb_itemNew( NULL );
    PHB_ITEM pValue = hb_itemNew( NULL );

    hb_hashClearFlags( pd, HB_HASH_BINARY );
    hb_hashSetFlags( pd, HB_HASH_IGNORECASE | HB_HASH_RESORT );

    hdo_listRDL( pd, pKey, pValue );

    hb_itemRelease( pKey );
    hb_itemRelease( pValue );

    hb_arraySetForward( pSelf, IVAR_HASHRDL, pd );

    hb_itemRelease( pd );

    /* Devuelve SELF */
    hb_itemReturnRelease( pSelf );
}

/***
 * Metodo: LIST
 * Uso: Consulta de RDL registrados
 * Parametros: Ninguno
 * Devuelve: Array con los RDLs registrados
 */


HB_METHOD( THDORDL_LIST )
{
    PHB_ITEM pd = hb_getHRDL();

    if( pd )
    {
        hb_itemReturnRelease( hb_hashGetKeys( pd ) );
    }
    else
    {
        hb_ret();
    }
}

/***
 * Metodo: REGISTER
 * Uso: Registra un RDL si no existe
 * Parametros: El nombre del RDL y un puntero a la funcion del RDL
 * Devuelve: Nada
 */


HB_METHOD( THDORDL_REGISTER )
{
    PHB_ITEM pd = hb_getHRDL();

    if( pd )
    {
        PHB_ITEM pKey = hb_param( 1, HB_IT_STRING );
        PHB_ITEM pValue = hb_param( 2, HB_IT_POINTER );

        if( pKey )
        {
            hb_hashAdd( pd, pKey, pValue );
        }
    }
}

/***
 * Metodo: ISREGISTERED
 * Uso: Comprueba si un RDL esta registrado
 * Parametros: Nombre del RDL
 * Devuelve: Valor logico indicando si existe o no
 */


HB_METHOD( THDORDL_ISREGISTERED )
{
    PHB_ITEM pd = hb_getHRDL();
    HB_BOOL bRet = HB_FALSE;

    if( pd )
    {
        PHB_ITEM pKey = hb_param( 1, HB_IT_STRING );

        if( pKey )
        {
            bRet = ( hb_hashGetCItemPos( pd, pKey ) != 0 );
        }
    }

    hb_retl( bRet );
}

/***
 * Metodo: GETPOS
 * Uso: Comprueba la posicion que ocupa un RDL
 * Parametros: Nombre del RDL
 * Devuelve: La posicion o 0 encaso de no estar registrado
 */


HB_METHOD( THDORDL_GETPOS )
{
    PHB_ITEM pd = hb_getHRDL();
    HB_SIZE nRet = 0;

    if( pd )
    {
        PHB_ITEM pKey = hb_param( 1, HB_IT_STRING );

        if( pKey )
        {
            nRet = hb_hashGetCItemPos( pd, pKey );

        }
    }

    hb_retni( nRet );
}

/***
 * Metodo: GETNAME
 * Uso: Consultar el nombre de un RDL por la posicion que ocupa
 * Parametros: Entero positivo
 * Devuelve: El nombre del RDL si esta registrado o NULL si no lo esta
 */


HB_METHOD( THDORDL_GETNAME )
{
    PHB_ITEM pd = hb_getHRDL();
    PHB_ITEM pRet = NULL;

    if( pd )
    {
        HB_USHORT nPos = hb_parni( 1 );

        if( nPos >= 1 )          /* Controlar el LEN del array */
        {
            pRet = hb_hashGetKeyAt( pd, nPos );
        }
    }

    hb_itemReturnRelease( pRet );
}

/***
 * Metodo: GETPFUNCBYNAME
 * Uso: Comprueba la posicion que ocupa un RDL
 * Parametros: Nombre del RDL
 * Devuelve: La posicion o 0 encaso de no estar registrado
 */


HB_METHOD( THDORDL_GETPFUNCBYNAME )
{
    PHB_ITEM pd = hb_getHRDL();
    PHB_ITEM pValue = NULL;

    if( pd )
    {
        PHB_ITEM pKey = hb_param( 1, HB_IT_STRING );

        if( pKey )
        {
            pValue = hb_hashGetItemPtr( pd, pKey, HB_HASH_AUTOADD_ACCESS );
        }
    }

    hb_itemReturn( pValue );
}

 


:roll:
______________________________________________________________________________
Sevilla - Andalucía
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 5 guests