00001 #if !defined(__MCINTERFACE_H_)
00002 #define __MCINTERFACE_H_
00003
00004 #ident "@(#)$Id: MCInterface.h,v 1.6 2004/12/02 07:05:20 mike Exp $"
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "mcllib/MCRefCount.h"
00026 #include "mcllib/MCTypes.h"
00027 #include "mcllib/MCVariant.h"
00028
00029 namespace mcllib
00030 {
00032 typedef mcuint64 MCIID;
00033
00101 class MCInterface : public MCRefCount
00102 {
00103 public:
00105 virtual ~MCInterface();
00112 virtual bool isa(const MCIID& iid) const = 0;
00120 const MCInterface* getInterface(const MCIID& iid) const;
00128 MCInterface* getInterface(const MCIID& iid);
00129
00130
00137 static const MCIID& getInterfaceId(const MCString& name);
00144 static const MCString& getInterfaceName(const MCIID& iid);
00156 static MCInterface* getInterface(const MCIID& iid,
00157 const MCVariantType& vt);
00165 static void registerName(const MCString& name, const MCIID& iid);
00178 static void registerInterface(const MCIID& iid, const MCVariantType& vt,
00179 MCInterface* pInterface);
00180 };
00181
00188 class MCIMgrBase
00189 {
00190 protected:
00197 MCIMgrBase(MCInterface* pInterface, const MCIID& iid);
00207 MCIMgrBase(const MCIMgrBase& mgr, const MCIID& iid);
00212 MCIMgrBase(const MCIMgrBase& mgr);
00214 MCIMgrBase& operator=(const MCIMgrBase& mgr);
00216 ~MCIMgrBase();
00220 static void checkPtr(const char* msg, const void* ptr);
00221
00223 MCInterface* m_pInterface;
00224 MCIID m_iid;
00225 };
00226
00232 template<class T>
00233 class MCIMgr : public MCIMgrBase
00234 {
00235 public:
00241 MCIMgr()
00242 : MCIMgrBase(0, 0)
00243 {
00244
00245 }
00246
00252 MCIMgr(T* pT, const MCIID& iid)
00253 : MCIMgrBase(pT, iid)
00254 {
00255
00256 }
00257
00264 MCIMgr(const MCIMgrBase& imgr, const MCIID& iid)
00265 : MCIMgrBase(imgr, iid)
00266 {
00267
00268 }
00269
00271 inline const T* operator->() const
00272 {
00273 return((const T*)m_pInterface);
00274 }
00275
00277 inline T* operator->()
00278 {
00279 return((T*)m_pInterface);
00280 }
00281
00282 };
00283 };
00284
00285 #endif