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

MCInterface.h

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  * Copyright Miba Consulting Ltd. (c) 2000-2003
00008  * 
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  * 
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * Lesser General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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         // Registration (static) methods
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             // Do not attempt to use one unless you have assigned to it
00245         }
00246 
00252         MCIMgr(T* pT, const MCIID& iid)
00253             : MCIMgrBase(pT, iid)
00254         {
00255             // Construction checks that pT->isa(iid)
00256         }
00257 
00264         MCIMgr(const MCIMgrBase& imgr, const MCIID& iid)
00265             : MCIMgrBase(imgr, iid)
00266         {
00267             // Construction checks that pT->isa(iid)
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

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