[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Now let's explain how to use all this mess from client side. First, we should
be able to create objects that implements the interfaces we want. For this,
you should use the SCF_CREATE_INSTANCE()
macro. It receives two arguments:
the name of external class, and the name of the interface it implements. So,
if we know class `MyGraphics3D' implements the `iGraphics3D'
interface, you should write:
iGraphics3D* G3D = SCF_CREATE_INSTANCE("MyGraphics3D", iGraphics3D); if (!G3D) { fprintf(stderr, "Failed to create an instance of MyGraphics3D!\n"); abort(); } |
Now you can use the object any way you like, just like standard C++:
G3D->BeginDraw(); G3D->DrawLine(...); G3D->DrawPolygon(...); G3D->EndDraw(); |
When you are done using the `G3D' pointer (say, when program exits), you
should free that object by calling G3D->DecRef()
. After this you can
not use `G3D' anymore; you should create another instance of
`iGraphics3D' for this.
To query an embedded interface, you will want to use the
SCF_QUERY_INTERFACE()
macro. It also receives two arguments, first being
the object you are querying for the embedded interface and second being the
name of the interface you want. Example:
iHalo* halo = SCF_QUERY_INTERFACE(G3D, iHalo); if (!halo) { fprintf(stderr, "3D graphic driver doesn't support halos!\n"); return; } |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |