2007-12-18 13:08 UTC+0800 Pritpal Bedi (pritpal@vouchcac.com)

* contrib/xhb/xhbcomp.prg
    + Added xHarbour specific methods to Type classes.
This commit is contained in:
Pritpal Bedi
2007-12-18 21:00:02 +00:00
parent 3a934f0ae8
commit 93bd747242
2 changed files with 189 additions and 0 deletions

View File

@@ -8,6 +8,10 @@
2002-12-01 13:30 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
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)

View File

@@ -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
//----------------------------------------------------------------------------//