Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
interface.h
Go to the documentation of this file.00001 00006 /* 00007 * Copyright © 2000, 2001 Sofus Mortensen 00008 * 00009 * This material is provided "as is", with absolutely no warranty 00010 * expressed or implied. Any use is at your own risk. Permission to 00011 * use or copy this software for any purpose is hereby granted without 00012 * fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is 00014 * granted, provided the above notices are retained, and a notice that 00015 * the code was modified is included with the above copyright notice. 00016 * 00017 * This header is part of comet. 00018 * http://www.lambdasoft.dk/comet 00019 */ 00020 00021 #ifndef COMET_INTERFACE_H 00022 #define COMET_INTERFACE_H 00023 00024 #include <comet/config.h> 00025 00026 #include <ocidl.h> 00027 #include <string> 00028 #include <stdexcept> 00029 00030 #include <comet/typelist.h> 00031 #include <comet/static_assert.h> 00032 #include <comet/uuid_fwd.h> 00033 00034 #pragma warning(push, 4) 00035 // NB: coclass_implementation _must_ have no data members. 00036 // The comet framework uses the test 00037 // sizeof coclass_implementation<T> == sizeof coclass_implementation<nil> 00038 // in order to determine whether the user has specialized based on T or not. 00039 // The logic here is that any real implementation will have a size that is at least 00040 // sizeof IUnknown, because any real coclass_implementation must at least derive 00041 // off IUnknown and have a "vtable" pointer. 00048 template<typename T> class coclass_implementation {}; 00049 00050 #pragma warning(pop) 00051 00052 namespace comet { 00053 00056 template<typename ITF, UUID *ItfID, typename BASE = ::IUnknown> struct uuid_comtype 00057 { 00058 static const uuid_t& uuid() { return uuid_t::create_const_reference(*ItfID); } 00059 typedef BASE base; 00060 }; 00061 00062 00067 template<typename T> struct comtype { 00068 static const IID& uuid() throw() { return comtype<COMET_STRICT_TYPENAME T::interface_is>::uuid(); } 00069 typedef typename comtype<COMET_STRICT_TYPENAME T::interface_is>::base base; 00070 }; 00071 00072 template<> struct comtype<nil> { 00073 // static const IID& uuid() throw() { throw std::logic_error("interface.h:35"); return IID_NULL; } 00074 typedef nil base; 00075 }; 00076 00077 template<> struct comtype< ::IUnknown > 00078 { 00079 static const IID& uuid() { return IID_IUnknown; } 00080 typedef nil base; 00081 }; 00082 00083 template<> struct comtype<IConnectionPoint> 00084 { 00085 static const IID& uuid() { return IID_IConnectionPoint; } 00086 typedef ::IUnknown base; 00087 }; 00088 00089 template<> struct comtype<IConnectionPointContainer> 00090 { 00091 static const IID& uuid() { return IID_IConnectionPointContainer; } 00092 typedef ::IUnknown base; 00093 }; 00094 00095 template<> struct comtype<IEnumConnections> 00096 { 00097 static const IID& uuid() { return IID_IEnumConnections; } 00098 typedef ::IUnknown base; 00099 }; 00100 00101 template<> struct comtype<IDispatch> 00102 { 00103 static const IID& uuid() { return IID_IDispatch; } 00104 typedef ::IUnknown base; 00105 }; 00106 00107 template<> struct comtype<IEnumVARIANT> 00108 { 00109 static const IID& uuid() { return IID_IEnumVARIANT; } 00110 typedef ::IUnknown base; 00111 }; 00112 00113 template<> struct comtype<ISupportErrorInfo> 00114 { 00115 static const IID& uuid() { return IID_ISupportErrorInfo; } 00116 typedef ::IUnknown base; 00117 }; 00118 00119 template<> struct comtype<IErrorInfo> 00120 { 00121 static const IID& uuid() { return IID_IErrorInfo; } 00122 typedef ::IUnknown base; 00123 }; 00124 00125 template<> struct comtype<IProvideClassInfo> 00126 { 00127 static const IID& uuid() throw() { return IID_IProvideClassInfo; } 00128 typedef ::IUnknown base; 00129 }; 00130 00131 template<> struct comtype<IPersist> 00132 { 00133 static const IID& uuid() throw() { return IID_IPersist; } 00134 typedef ::IUnknown base; 00135 }; 00136 00137 template<> struct comtype<IPersistFile> 00138 { 00139 static const IID& uuid() throw() { return IID_IPersistFile; } 00140 typedef ::IPersist base; 00141 }; 00142 00143 template<> struct comtype<IPersistStream> 00144 { 00145 static const IID& uuid() throw() { return IID_IPersistStream; } 00146 typedef ::IPersist base; 00147 }; 00148 00149 template<> struct comtype<IPersistStreamInit> 00150 { 00151 static const IID& uuid() throw() { return IID_IPersistStreamInit; } 00152 typedef ::IPersist base; 00153 }; 00154 00155 template<> struct comtype<IMessageFilter> 00156 { 00157 static const IID& uuid() throw() { return IID_IMessageFilter; } 00158 typedef ::IUnknown base; 00159 }; 00160 00161 template<> struct comtype<IProvideClassInfo2> 00162 { 00163 static const IID& uuid() throw() { return IID_IProvideClassInfo2; } 00164 typedef ::IUnknown base; 00165 }; 00166 00167 template<> struct comtype<IMarshal> 00168 { 00169 static const IID& uuid() throw() { return IID_IMarshal; } 00170 typedef ::IUnknown base; 00171 }; 00172 00173 template<> struct comtype<IFontDisp> 00174 { 00175 static const IID& uuid() throw() { return IID_IFontDisp; } 00176 typedef ::IDispatch base; 00177 }; 00178 00179 template<> struct comtype<IPictureDisp> 00180 { 00181 static const IID& uuid() throw() { return IID_IPictureDisp; } 00182 typedef ::IDispatch base; 00183 }; 00184 template<> struct comtype<IGlobalInterfaceTable> 00185 { 00186 static const IID& uuid() throw() { return IID_IGlobalInterfaceTable; } 00187 typedef ::IUnknown base; 00188 }; 00189 00190 template<> struct comtype<IClassFactory> 00191 { 00192 static const IID& uuid() throw() { return IID_IClassFactory; } 00193 typedef ::IUnknown base; 00194 }; 00195 00196 00197 00199 00202 template<typename Itf> inline const uuid_t& uuidof(Itf * = 0) throw() 00203 { return uuid_t::create_const_reference(comtype<Itf>::uuid()); } 00204 00205 namespace impl { 00206 00207 template<typename Itf> struct interface_lookup 00208 { 00209 static bool supports(const uuid_t& iid) 00210 { 00211 if (iid == uuidof<Itf>()) 00212 return true; 00213 else 00214 return interface_lookup< typename comtype<Itf>::base >::supports(); 00215 } 00216 00217 template<typename T> static Itf* cast(T* t) 00218 { 00219 return static_cast<Itf*>(t); 00220 } 00221 }; 00222 00223 template<> struct interface_lookup<nil> 00224 { 00225 static bool supports(const uuid_t&) 00226 { 00227 return false; 00228 } 00229 00230 }; 00231 00232 /* template<> struct interface_lookup<make_list<> > 00233 { 00234 static bool supports(const uuid_t&) 00235 { 00236 return false; 00237 } 00238 00239 };*/ 00240 } 00241 00242 } // namespace 00243 00244 #endif