From 93bd747242c02fbe88df530e5982fdec2dfebe9e Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Tue, 18 Dec 2007 21:00:02 +0000 Subject: [PATCH] 2007-12-18 13:08 UTC+0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/xhb/xhbcomp.prg + Added xHarbour specific methods to Type classes. --- harbour/ChangeLog | 4 + harbour/contrib/xhb/xhbcomp.prg | 185 ++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 13fe809784..49684e3256 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,10 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-12-18 13:08 UTC+0800 Pritpal Bedi (pritpal@vouchcac.com) + * contrib/xhb/xhbcomp.prg + + Added xHarbour specific methods to Type classes. + 2007-12-18 11:17 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/ChangeLog * reverted conversion to UTF8 of national characters (svn diff) diff --git a/harbour/contrib/xhb/xhbcomp.prg b/harbour/contrib/xhb/xhbcomp.prg index 4d682357f4..2ba4eee2dd 100644 --- a/harbour/contrib/xhb/xhbcomp.prg +++ b/harbour/contrib/xhb/xhbcomp.prg @@ -52,6 +52,7 @@ #include "common.ch" #include "hbclass.ch" +#include "xhb.ch" ANNOUNCE XHB_LIB @@ -73,6 +74,8 @@ CREATE CLASS Character INHERIT HBScalar FUNCTION xhb_Character OPERATOR "^" FUNCTION XHB_POW() OPERATOR "++" FUNCTION XHB_INC() OPERATOR "--" FUNCTION XHB_DEC() + + METHOD AsString INLINE HB_QSelf() ENDCLASS CREATE CLASS Numeric INHERIT HBScalar FUNCTION xhb_Numeric @@ -84,11 +87,32 @@ CREATE CLASS Numeric INHERIT HBScalar FUNCTION xhb_Numeric OPERATOR "^" FUNCTION XHB_POW() OPERATOR "++" FUNCTION XHB_INC() OPERATOR "--" FUNCTION XHB_DEC() + + METHOD AsString INLINE LTrim( Str( ( HB_QSelf() ) ) ) ENDCLASS CREATE CLASS Array INHERIT HBScalar FUNCTION xhb_Array OPERATOR "[]" FUNCTION XHB_INDEX() OPERATOR "$$" FUNCTION XHB_INCLUDE() + + MESSAGE Add METHOD Append + METHOD AddAll + METHOD Append + METHOD asString INLINE '{...}' //ValtoPrg( HB_QSelf() ) + METHOD At( n ) INLINE Self[ n ] + METHOD AtIndex( n ) INLINE Self[ n ] + METHOD AtPut( n, x ) INLINE Self[ n ] := x + METHOD Collect + METHOD Copy INLINE aCopy( Self, Array( Len( Self ) ) ) + METHOD DeleteAt + METHOD Do + METHOD IndexOf + METHOD Init( nLen ) INLINE ::Size := IIF( nLen == NIL, 0, nLen ), Self + METHOD InsertAt + METHOD Remove + METHOD Scan( bScan ) INLINE aScan( Self, bScan ) + METHOD _Size( nLen ) INLINE aSize( Self, nLen ), nLen + ENDCLASS CREATE CLASS Hash INHERIT HBScalar FUNCTION xhb_Hash @@ -96,4 +120,165 @@ CREATE CLASS Hash INHERIT HBScalar FUNCTION xhb_Hash OPERATOR "+" FUNCTION XHB_PLUS() OPERATOR "-" FUNCTION XHB_MINUS() OPERATOR "$$" FUNCTION XHB_INCLUDE() + + METHOD Add( xKey, xValue ) INLINE Self[ xKey ] := xValue, Self + METHOD AddAll( oCollection ) + METHOD AtIndex( nPos ) INLINE HGetValueAt( Self, nPos ) + METHOD AtPut( nPos, xValue ) INLINE HSetValueAt( Self, nPos, xValue ) + METHOD Append( xKey, xValue ) INLINE Self[ xKey ] := xValue, Self + METHOD AsString() INLINE '...HASH...' // ValToPrg( HB_QSelf() ) + METHOD Collect( bCollect ) + METHOD Copy() INLINE hCopy( Self, Hash() ) + METHOD DeleteAt( nPos ) INLINE hDelat( Self, nPos ) + METHOD Do( bBlock ) + METHOD IndexOf( xValue ) INLINE hScan( Self, xValue ) + METHOD Init( nLen ) INLINE ::Size := IIF( nLen == NIL, 0, nLen ), Self + METHOD Remove( xValue ) INLINE hDel( Self, xValue ) + METHOD Scan( bScan ) INLINE hScan( Self, bScan ) + METHOD _Size( nLen ) + ENDCLASS + +//----------------------------------------------------------------------------// + +METHOD AddAll( otherCollection ) CLASS Array + otherCollection:Do( {|x| ::Add(x) } ) + RETURN Self + +//----------------------------------------------------------------------------// + +METHOD Append( x ) CLASS Array + aAdd( Self, x ) + RETURN Self + +//----------------------------------------------------------------------------// + +METHOD Collect( bCollect ) CLASS Array + LOCAL xElement, aResult[0] + + FOR EACH xElement IN Self + IF Eval( bCollect, UnRef( xElement ) ) + aAdd( aResult, UnRef( xElement ) ) + END + NEXT + +RETURN aResult + +//----------------------------------------------------------------------------// + +METHOD deleteAt( nPos ) CLASS Array + + IF nPos > 0 .AND. nPos <= Len( Self ) + aDel( Self, nPos, .T. ) + ENDIF + +RETURN Self + +//----------------------------------------------------------------------------// + +METHOD Do( bEval ) CLASS Array + LOCAL xElement + + FOR EACH xElement IN Self + bEval:Eval( UnRef( xElement ), HB_EnumIndex() ) + NEXT + +RETURN Self + +//----------------------------------------------------------------------------// + +METHOD IndexOf( xValue ) CLASS Array + LOCAL xElement, cType := ValType( xValue ) + + FOR EACH xElement IN Self + IF ValType( xElement ) == cType .AND. xElement == xValue + RETURN HB_EnumIndex() + END + NEXT + +RETURN 0 + +//----------------------------------------------------------------------------// + +METHOD InsertAt( nPos, xValue ) CLASS Array + + IF nPos > Len( self ) + aSize( Self, nPos ) + Self[ nPos ] := xValue + ELSEIF nPos > 0 + aIns( Self, nPos, xValue, .T. ) + ENDIF + +RETURN Self + +//----------------------------------------------------------------------------// + +METHOD Remove( xValue ) CLASS Array + + ::DeleteAt( ::IndexOf( xValue ) ) + +RETURN Self + +//----------------------------------------------------------------------------// + +METHOD AddAll( oCollection ) CLASS HASH + + oCollection:Do( { |xKey, xValue| Self[ xKey ] := xValue } ) + +RETURN Self + +//----------------------------------------------------------------------------// + +METHOD Collect( bCollect ) CLASS HASH + LOCAL xElement, aResult[0] + + FOR EACH xElement IN Self:Values + IF Eval( bCollect, UnRef( xElement ) ) + aAdd( aResult, UnRef( xElement ) ) + END + NEXT + +RETURN aResult + +//----------------------------------------------------------------------------// + +METHOD Do( bDo ) CLASS HASH + + LOCAL xKey + + FOR EACH xKey IN Self:Keys + Eval( bDo, xKey, Self[ xKey ] ) + NEXT + +RETURN Self + +//----------------------------------------------------------------------------// + +METHOD _Size( nLen ) CLASS HASH + + LOCAL nOldLen := Len( Self ), Counter + + IF nLen == nOldLen + RETURN nLen + ELSEIF nLen > nOldLen + hAllocate( Self, nLen ) + + FOR Counter := nOldLen + 1 TO nLen + Self[ "_SIZED_" + LTrim( Str( Counter ) ) ] := NIL + NEXT + ELSE + FOR Counter := nOldLen TO nLen + 1 + hDelAt( Self, nLen + 1 ) + NEXT + ENDIF + +RETURN nLen + +//----------------------------------------------------------------------------// + +FUNCTION UnRef( xValue ) + +RETURN xValue + +//----------------------------------------------------------------------------// +