Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCInterface Class Reference

Base class for all virtual interfaces allocated using new. More...

#include <mcllib/MCInterface.h>

Inheritance diagram for MCInterface:

MCRefCount List of all members.

Public Member Functions

MCInterfacegetInterface (const MCIID &iid)
 Obtain an interface pointer for an interface identifier.
const MCInterfacegetInterface (const MCIID &iid) const
 Obtain a const interface pointer for an interface identifier.
virtual bool isa (const MCIID &iid) const =0
 Check what interface is implemented.
virtual ~MCInterface ()
 Allows virtual deletes.

Static Public Member Functions

MCInterfacegetInterface (const MCIID &iid, const MCVariantType &vt)
 Find a specific implementation of an interface.
const MCIIDgetInterfaceId (const MCString &name)
 Get the interface identifier for a named interface.
const MCStringgetInterfaceName (const MCIID &iid)
 Get an interface name for an interface identifier.
void registerInterface (const MCIID &iid, const MCVariantType &vt, MCInterface *pInterface)
 Register an interface implementation to an implementation key.
void registerName (const MCString &name, const MCIID &iid)
 Register a name for an interface identifier.

Detailed Description

Base class for all virtual interfaces allocated using new.

Each interface is bound to an interface identifier MCIID. Registering implementations of an interface is a two stage process Firstly, the interface must be registered with its interface identifier. Secondly, one or more impelentations must be registered against the interface identifier with keys which are unique to the interface. Different interfaces (with different interface identifiers) may register the same name for one of their implementations.

Example interface definition class

 -- MyIf.h --
 class MyIf : public mcllib::MCInterface
 {
 public:
       // An interface identifier defined elsewhere
       static const mcllib::MCIID IID;
       // contract defined by MCInterface
     virtual ~MyIf();
     virtual bool isa(const mcllib::MCIID& iid) const;
       // the methods defined by this MyIf
     virtual void doMyThing() = 0;
 };

 -- MyIf.cpp --
 const mcllib::MCIID MyIf::ID = some_iid;
 bool MyIf::isa(const mcllib::MCIID& iid) const
 {
     return(iid == IID);
 }
 

Once an interface definition class has been created, one or more implementation classes can be written which derive from it and implement its pure virtual methods.

Example implementation class

 -- MyImpl.h --
 class MyImpl : public MyIf
 {
 public:
     MyImpl();
     virtual ~MyImpl();
     virtual bool isa(const mcllib::MCIID& iid) const;
       // contract defined by MyIf
     virtual void doMyThing();
 };

 -- MyImpl.cpp --
 void MyImpl::doMyThing() const
 {
     ...
 }
 

After interface definition and implementation classes have been written, the interface and its implementation(s) can be registered. This is an optional process, since there may only be one implementation of an interface.

Example registration

 // Register a name for the interface. Ties together name and identifier
 mcllib::MCInterface::registerName("myif.mydomain.com", MyIf::IID);
 // Construct an implementation object
 MyImpl* pImpl = new MyImpl;
 // Get a name for this particular implementation
 mcllib::MCVTString implKey("myimpl1");
 mcllib::MCInterface::registerInterface(MyIf::IID, implKey, pImpl);
 


Member Function Documentation

MCInterface* getInterface const MCIID iid,
const MCVariantType vt
[static]
 

Find a specific implementation of an interface.

The implementation must have been previously registered with registerName().

Parameters:
iid the interface identifier to find an implementation for. An exception is thrown if the interface identifier is unknown.
vt a key associated with the implementation An exception is thrown if an implementation has not been registered against this implementation key.
Returns:
the registered interface.

MCInterface* getInterface const MCIID iid  ) 
 

Obtain an interface pointer for an interface identifier.

Throws an exception if the interface identifier specifies an interface which is not implemented.

Parameters:
iid the interface identifier to get an interface for
Returns:
a pointer to this if isa(iid) would return true.

const MCInterface* getInterface const MCIID iid  )  const
 

Obtain a const interface pointer for an interface identifier.

Throws an exception if the interface identifier specifies an interface which is not implemented.

Parameters:
iid the interface identifier to get an interface for
Returns:
a pointer to this if isa(iid) would return true.

const MCIID& getInterfaceId const MCString name  )  [static]
 

Get the interface identifier for a named interface.

Parameters:
name the interface name to obtain an interface identifier for. An exception is thrown if the name is unknown.
Returns:
the interface identifier corresponding to name

const MCString& getInterfaceName const MCIID iid  )  [static]
 

Get an interface name for an interface identifier.

Parameters:
iid the interface identifier to obtain a name for An exception is thrown if the name is unknown.
Returns:
the name corresponding to the interface identifier

virtual bool isa const MCIID iid  )  const [pure virtual]
 

Check what interface is implemented.

Parameters:
iid the interface identifier to check for.
Returns:
true if the interface identifier is implemented, false if not.

void registerInterface const MCIID iid,
const MCVariantType vt,
MCInterface pInterface
[static]
 

Register an interface implementation to an implementation key.

Subsequent calls to getInterface() which specify the iid and vt will return pInterface.

Parameters:
iid the interface id to register the implementation against. If iid has not been registered with registerName() an exception is thrown.
vt the implementation key to register the implementation against
pInterface the implementation to register against the interface id and implementation key.

void registerName const MCString name,
const MCIID iid
[static]
 

Register a name for an interface identifier.

Subsequent calls to getInterfaceId() or getInterfaceName() that specifiy the appropriate parameters will succeed.

Parameters:
name name of the interface
iid interface identifier of the interface


Generated on Wed Jan 12 19:05:49 2005 for MCLLIB by  doxygen 1.3.9.1