From 8cff1ae4690c8a14054075464fcf5bec9f9d8324 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 14 Jun 2009 08:38:37 +0000 Subject: [PATCH] 2009-06-14 10:37 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * include/hbextern.ch * source/vm/hashfunc.c + Added HB_HGETDEF( , [, ] ) -> This function will return when isn't found in the hash table. If isn't passed, it will return NIL. --- harbour/ChangeLog | 8 ++++++++ harbour/include/hbextern.ch | 1 + harbour/source/vm/hashfunc.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index d36a5bcbd7..5947af92ab 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,14 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-06-14 10:37 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * include/hbextern.ch + * source/vm/hashfunc.c + + Added HB_HGETDEF( , [, ] ) -> + This function will return when isn't + found in the hash table. If isn't passed, it + will return NIL. + 2009-06-14 00:02 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + harbour/contrib/hbxbp/gra.ch * harbour/contrib/hbxbp/Makefile diff --git a/harbour/include/hbextern.ch b/harbour/include/hbextern.ch index 9723ea7a77..f84162622e 100644 --- a/harbour/include/hbextern.ch +++ b/harbour/include/hbextern.ch @@ -1228,6 +1228,7 @@ EXTERNAL HB_HASH EXTERNAL HB_HHASKEY EXTERNAL HB_HPOS EXTERNAL HB_HGET +EXTERNAL HB_HGETDEF EXTERNAL HB_HSET EXTERNAL HB_HDEL EXTERNAL HB_HKEYAT diff --git a/harbour/source/vm/hashfunc.c b/harbour/source/vm/hashfunc.c index 45580819dd..4c9b1137ac 100644 --- a/harbour/source/vm/hashfunc.c +++ b/harbour/source/vm/hashfunc.c @@ -126,6 +126,27 @@ HB_FUNC( HB_HGET ) hb_errRT_BASE( EG_ARG, 1123, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } +HB_FUNC( HB_HGETDEF ) +{ + PHB_ITEM pHash = hb_param( 1, HB_IT_HASH ); + PHB_ITEM pKey = hb_param( 2, HB_IT_HASHKEY ); + + if( pHash && pKey ) + { + PHB_ITEM pDest = hb_hashGetItemPtr( pHash, pKey, HB_HASH_AUTOADD_ACCESS ); + if( pDest ) + hb_itemReturn( pDest ); + else + { + PHB_ITEM pDefault = hb_param( 3, HB_IT_ANY ); + if( pDefault ) + hb_itemReturn( pDefault ); + } + } + else + hb_errRT_BASE( EG_ARG, 1123, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + HB_FUNC( HB_HSET ) { PHB_ITEM pHash = hb_param( 1, HB_IT_HASH );