From a5c242f2b28acc812a4ecd1a9a9ad9949e435c25 Mon Sep 17 00:00:00 2001 From: Eddie Runia Date: Mon, 10 May 1999 10:28:27 +0000 Subject: [PATCH] Functions isData(), isMethod() and isMessage() added --- harbour/ChangeLog | 6 ++++ harbour/source/rtl/classes.c | 13 +++++++++ harbour/tests/working/debugtst.prg | 45 +++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8922878eb1..a70c03de1d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,9 @@ +19990510-11:30 Eddie Runia + * source/rtl/classes.c + Function IsMessage() added + * tests/working/debugtst.prg + Function IsData() / IsMethod() added. Also contains tests for Is*() + 19990510-10:05 Eddie Runia * source/vm/hvm.c Function PCount() added /* QUESTION: Should it be there ? */ diff --git a/harbour/source/rtl/classes.c b/harbour/source/rtl/classes.c index 476f1ad784..438cf80f7d 100644 --- a/harbour/source/rtl/classes.c +++ b/harbour/source/rtl/classes.c @@ -447,6 +447,19 @@ HARBOURFUNC GetMethod( PITEM pObject, PSYMBOL pMessage ) return 0; } +HARBOUR ISMESSAGE() /* Is the message valid for the class */ + /* := IsMessage( , ) */ +{ + PITEM pObject = _param( 1, IT_OBJECT ); + PITEM pString = _param( 2, IT_STRING ); + PSYMBOL pMessage = GetDynSym( pString->value.szText )->pSymbol; + /* QUESTION: Warning when using HARBOURFUNC ? */ + ULONG pFunc = (ULONG) GetMethod( pObject, pMessage ); + /* Get function pointer of */ + /* message */ + _retl( pFunc != 0 ); +} + void ReleaseClass( PCLASS pClass ) { _xfree( pClass->szName ); diff --git a/harbour/tests/working/debugtst.prg b/harbour/tests/working/debugtst.prg index 5f82b6beca..c38d701556 100644 --- a/harbour/tests/working/debugtst.prg +++ b/harbour/tests/working/debugtst.prg @@ -23,11 +23,28 @@ function Main() oForm:Show() QOut() - QOut( "-DEBUG Functions-") + QOut( "-OBJECT additions-" ) + QOut( "What is in oForm ? " ) Debug( oForm:Transfer() ) - oForm:Transfer( {"nLeft", 50}, {"nRight", 100} ) + QOut( "Does transfer exists ? ", IsMessage( oForm, "Transfer" ) ) + QOut( "Is transfer DATA ? ", IsData ( oForm, "Transfer" ) ) + QOut( "Is transfer METHOD ? ", IsMethod ( oForm, "Transfer" ) ) + QOut( "Does nLeft exists ? ", IsMessage( oForm, "nLeft" ) ) + QOut( "Is nLeft DATA ? ", IsData ( oForm, "nLeft" ) ) + QOut( "Is nLeft METHOD ? ", IsMethod ( oForm, "nLeft" ) ) + QOut( "Does unknown exists ? ", IsMessage( oForm, "Unknown" ) ) + QOut( "Is unknown DATA ? ", IsData ( oForm, "Unknown" ) ) + QOut( "Is unknown METHOD ? ", IsMethod ( oForm, "Unknown" ) ) + QOut( "Set nLeft to 50 and nRight to 100" ) + oForm:Transfer( {"nLeft", 50}, {"nRight", 100} ) + Debug( oForm:Transfer() ) + + Pause() + + + QOut( "-DEBUG Functions-") QOut( "-Statics-" ) Debug( __aStatic() ) @@ -222,8 +239,7 @@ function TForm() oClass:AddData( "nBottom" ) oClass:AddData( "nRight" ) - oClass:AddVirtual( "aExcept" ) - // Export exceptions + oClass:AddVirtual( "aExcept" ) // Export exceptions oClass:AddMethod( "New", @New() ) // define this class objects methods oClass:AddMethod( "Show", @Show() ) @@ -516,4 +532,25 @@ function QuickSort( aSort, nLeft, nRight, bOrder ) return nil +// +// := IsData( , ) +// +// Is the symbol present in the object as DATA ? +// +function IsData( oObject, cSymbol ) + +return IsMessage( oObject, cSymbol ) .and. IsMessage( oObject, "_" + cSymbol ) + + +// +// := IsMethod( , ) +// +// Is the symbol present in the object as METHOD ? +// +function IsMethod( oObject, cSymbol ) + +return IsMessage( oObject, cSymbol ) .and. !IsMessage( oObject, "_" + cSymbol ) + + +