Cairo__CObject.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 13 Feb 2016 17:10:25 +0000
changeset 36 9b680e54aa94
parent 30 c8fe298c8cc7
child 40 28dfc583beb5
permissions -rw-r--r--
Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context ...into two separate classes for cleaner responsibilities. Also, API of Smalltalk/X graphics contexts does not play well with Cairo's save/restore semantics.

"{ Package: 'stx:goodies/libcairo' }"

"{ NameSpace: Cairo }"

ExternalAddress subclass:#CObject
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Cairo-Objects'
!


!CObject class methodsFor:'instance creation'!

fromExternalAddress: anExternalAddress
    ^ self new fromExternalAddress: anExternalAddress

    "Created: / 24-12-2014 / 22:18:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-12-2014 / 10:33:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CObject methodsFor:'accessing'!

referenceCount
    "Return value or reference counter"

    ^ self subclassResponsibility

    "Created: / 09-09-2008 / 20:33:48 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 28-12-2014 / 22:09:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CObject methodsFor:'finalization'!

executor

    ^self class basicNew
        setAddress: self address;
        yourself

    "Created: / 10-09-2008 / 18:57:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 25-12-2014 / 10:36:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

finalize
    self infoPrintCR:'Instance destroyed'.
    self destroy

    "Created: / 09-09-2008 / 20:30:22 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 10-09-2008 / 18:45:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 28-12-2014 / 21:39:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CObject methodsFor:'initialization & release'!

release
    self unregisterForFinalization.
    ^self destroy

    "Created: / 25-12-2014 / 10:34:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-02-2016 / 16:10:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CObject methodsFor:'private'!

destroy
    "Tell Cairo library to destroy the corresponding C object.
     Remember that object is physically destroyed only if internal
     refcounter goes to zero. However, after calling destroy, 
     this instance should be treated as invalid."

    ^ self subclassResponsibility

    "Created: / 28-12-2014 / 21:41:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

fromExternalAddress:anExternalAddress 
    self setAddress: anExternalAddress address.  
    self registerForFinalization.
    self infoPrintCR:'Instance created'.

    "Created: / 09-09-2008 / 20:35:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 10-09-2008 / 18:45:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 25-12-2014 / 10:36:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

infoPrintCR:aString 
    Stdout
        nextPutAll:'Cairo [info] (';
        nextPutAll:self class nameWithoutPrefix;
        nextPutAll:' @ 0x';
        nextPutAll:(self address printStringRadix:16);
        nextPutAll:' @ ';
        nextPutAll:(self referenceCount printString);
        nextPutAll:': ';
        nextPutAll:aString;
        cr

    "Created: / 10-09-2008 / 18:45:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!CObject class methodsFor:'documentation'!

version
    ^'$Id$'
!

version_HG
    ^ '$Changeset: <not expanded> $'
! !