git.h

Go to the documentation of this file.
00001 00004 /* 00005 * Copyright © 2000, 2001 Sofus Mortensen 00006 * 00007 * This material is provided "as is", with absolutely no warranty 00008 * expressed or implied. Any use is at your own risk. Permission to 00009 * use or copy this software for any purpose is hereby granted without 00010 * fee, provided the above notices are retained on all copies. 00011 * Permission to modify the code and to distribute modified code is 00012 * granted, provided the above notices are retained, and a notice that 00013 * the code was modified is included with the above copyright notice. 00014 * 00015 * This header is part of comet. 00016 * http://www.lambdasoft.dk/comet 00017 */ 00018 00019 #ifndef COMET_GIT_H 00020 #define COMET_GIT_H 00021 00022 #include <comet/config.h> 00023 00024 #include <comet/ptr.h> 00025 00026 namespace comet { 00030 00031 class GIT; 00032 00034 template<typename Itf> class GIT_cookie 00035 { 00036 friend class GIT; 00037 public: 00038 GIT_cookie(const GIT_cookie& c) : cookie_(c.cookie_) {} 00039 explicit GIT_cookie(DWORD c) : cookie_(c) {} 00040 00041 DWORD get_cookie() { return cookie_; } 00042 private: 00043 DWORD cookie_; 00044 }; 00045 00047 class GIT { 00048 public: 00049 GIT() : git_(CLSID_StdGlobalInterfaceTable) 00050 {} 00051 00056 template<typename Itf> 00057 GIT_cookie<Itf> register_interface(com_ptr<Itf>& ptr) 00058 { 00059 DWORD cookie; 00060 git_->RegisterInterfaceInGlobal(ptr.get(), uuidof<Itf>(), &cookie) | raise_exception; 00061 return GIT_cookie<Itf>(cookie); 00062 } 00063 00068 template<typename Itf> 00069 com_ptr<Itf> get_interface(GIT_cookie<Itf>& c) 00070 { 00071 Itf* itf; 00072 git_->GetInterfaceFromGlobal(c.get_cookie(), uuidof<Itf>(), reinterpret_cast<void**>(&itf)) | raise_exception; 00073 return auto_attach(itf); 00074 } 00075 00079 template<typename Itf> 00080 void revoke_interface(GIT_cookie<Itf>& c) 00081 { 00082 git_->RevokeInterfaceFromGlobal(c.get_cookie()) | raise_exception; 00083 } 00084 00085 private: 00086 com_ptr<::IGlobalInterfaceTable> git_; 00087 }; 00089 00090 } // namespace comet 00091 00092 #endif