Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
scf_impl.h
00001 /* 00002 Crystal Space Shared Class Facility (SCF) 00003 Copyright (C) 2005 by Marten Svanfeldt and Michael D. Adams 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #ifndef SCF_IN_IMPLEMENTATION_H 00028 #error Do not include this file directly. Included from scf_implementation.h 00029 #endif 00030 00031 #ifndef SCF_IMPL_EXT 00032 # define SCF_IMPL_NAME SCF_IMPL_CAT(scfImplementation,SCF_IMPL_N) 00033 # define SCF_IMPL_SUPER scfImplementation<Class> 00034 # define SCF_IMPL_PRE_TYPES 00035 # define SCF_IMPL_PRE_ARGS 00036 #else /* SCF_IMPL_EXT */ 00037 # define SCF_IMPL_NAME SCF_IMPL_CAT(scfImplementationExt,SCF_IMPL_N) 00038 # define SCF_IMPL_SUPER Super 00039 # define SCF_IMPL_PRE_TYPES class Super, 00040 # define SCF_IMPL_PRE_ARGS Super, 00041 #endif 00042 00043 #if SCF_IMPL_N == 1 00044 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES class I1 00045 # define SCF_IMPL_INTERFACES public I1 00046 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1 00047 #elif SCF_IMPL_N == 2 00048 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES class I1, class I2 00049 # define SCF_IMPL_INTERFACES public I1, public I2 00050 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1, I2 00051 #elif SCF_IMPL_N == 3 00052 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES class I1, class I2, class I3 00053 # define SCF_IMPL_INTERFACES public I1, public I2, public I3 00054 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1, I2, I3 00055 #elif SCF_IMPL_N == 4 00056 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES \ 00057 class I1, class I2, class I3, class I4 00058 # define SCF_IMPL_INTERFACES \ 00059 public I1, public I2, public I3, public I4 00060 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1, I2, I3, I4 00061 #elif SCF_IMPL_N == 5 00062 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES \ 00063 class I1, class I2, class I3, class I4, class I5 00064 # define SCF_IMPL_INTERFACES \ 00065 public I1, public I2, public I3, public I4, public I5 00066 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1, I2, I3, I4, I5 00067 #elif SCF_IMPL_N == 6 00068 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES \ 00069 class I1, class I2, class I3, class I4, class I5, \ 00070 class I6 00071 # define SCF_IMPL_INTERFACES \ 00072 public I1, public I2, public I3, public I4, public I5, \ 00073 public I6 00074 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1, I2, I3, I4, I5, I6 00075 #elif SCF_IMPL_N == 7 00076 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES \ 00077 class I1, class I2, class I3, class I4, class I5, \ 00078 class I6, class I7 00079 # define SCF_IMPL_INTERFACES \ 00080 public I1, public I2, public I3, public I4, public I5, \ 00081 public I6, public I7 00082 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1, I2, I3, I4, I5, I6, I7 00083 #elif SCF_IMPL_N == 8 00084 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES \ 00085 class I1, class I2, class I3, class I4, class I5, \ 00086 class I6, class I7, class I8 00087 # define SCF_IMPL_INTERFACES \ 00088 public I1, public I2, public I3, public I4, public I5, \ 00089 public I6, public I7, public I8 00090 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1, I2, I3, I4, I5, I6, I7, I8 00091 #elif SCF_IMPL_N == 9 00092 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES \ 00093 class I1, class I2, class I3, class I4, class I5, \ 00094 class I6, class I7, class I8, class I9 00095 # define SCF_IMPL_INTERFACES \ 00096 public I1, public I2, public I3, public I4, public I5, \ 00097 public I6, public I7, public I8, public I9 00098 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS I1, I2, I3, I4, I5, I6, I7, I8, I9 00099 #elif SCF_IMPL_N == 10 00100 # define SCF_IMPL_TYPES SCF_IMPL_PRE_TYPES \ 00101 class I1, class I2, class I3, class I4, class I5, \ 00102 class I6, class I7, class I8, class I9, class I10 00103 # define SCF_IMPL_INTERFACES \ 00104 public I1, public I2, public I3, public I4, public I5, \ 00105 public I6, public I7, public I8, public I9, public I10 00106 # define SCF_IMPL_ARGS SCF_IMPL_PRE_ARGS \ 00107 I1, I2, I3, I4, I5, I6, I7, I8, I9, I10 00108 #else 00109 # error Unsuported value of SCF_IMPL_N 00110 #endif 00111 00112 // Taken from http://www.boost.org/boost/preprocessor/cat.hpp 00113 #define SCF_IMPL_CAT(a, b) SCF_IMPL_CAT_I(a, b) 00114 #define SCF_IMPL_CAT_I(a, b) SCF_IMPL_CAT_II(a ## b) 00115 #define SCF_IMPL_CAT_II(res) res 00116 00117 template<class Class, SCF_IMPL_TYPES> 00118 class SCF_IMPL_NAME : 00119 public SCF_IMPL_SUPER, 00120 SCF_IMPL_INTERFACES 00121 { 00122 public: 00123 inline void *QueryInterface(scfInterfaceID id, scfInterfaceVersion version) 00124 { 00125 void *x; 00126 #if SCF_IMPL_N >= 1 00127 if((x = VC6Workaround<I1>::GetInterface(this->scfObject, id, version)) != 0) return x; 00128 #endif 00129 #if SCF_IMPL_N >= 2 00130 if((x = VC6Workaround<I2>::GetInterface(this->scfObject, id, version)) != 0) return x; 00131 #endif 00132 #if SCF_IMPL_N >= 3 00133 if((x = VC6Workaround<I3>::GetInterface(this->scfObject, id, version)) != 0) return x; 00134 #endif 00135 #if SCF_IMPL_N >= 4 00136 if((x = VC6Workaround<I4>::GetInterface(this->scfObject, id, version)) != 0) return x; 00137 #endif 00138 #if SCF_IMPL_N >= 5 00139 if((x = VC6Workaround<I5>::GetInterface(this->scfObject, id, version)) != 0) return x; 00140 #endif 00141 #if SCF_IMPL_N >= 6 00142 if((x = VC6Workaround<I6>::GetInterface(this->scfObject, id, version)) != 0) return x; 00143 #endif 00144 #if SCF_IMPL_N >= 7 00145 if((x = VC6Workaround<I7>::GetInterface(this->scfObject, id, version)) != 0) return x; 00146 #endif 00147 #if SCF_IMPL_N >= 8 00148 if((x = VC6Workaround<I8>::GetInterface(this->scfObject, id, version)) != 0) return x; 00149 #endif 00150 #if SCF_IMPL_N >= 9 00151 if((x = VC6Workaround<I9>::GetInterface(this->scfObject, id, version)) != 0) return x; 00152 #endif 00153 #if SCF_IMPL_N >= 10 00154 if((x = VC6Workaround<I10>::GetInterface(this->scfObject, id, version)) != 0) return x; 00155 #endif 00156 00157 return SCF_IMPL_SUPER::QueryInterface(id, version); 00158 } 00159 00160 protected: 00161 #ifndef SCF_IMPL_EXT 00162 SCF_IMPL_NAME(Class *object, iBase *parent=0) 00163 : SCF_IMPL_SUPER(object, parent) 00164 {} 00165 #else /* SCF_IMPL_EXT */ 00166 SCF_IMPL_NAME(Class *object) 00167 : SCF_IMPL_SUPER(), scfObject(object) {} 00168 00169 template<class T1> 00170 SCF_IMPL_NAME(Class *object, T1 t1) 00171 : SCF_IMPL_SUPER(t1), scfObject(object) {} 00172 00173 template<class T1, class T2> 00174 SCF_IMPL_NAME(Class *object, T1 t1, T2 t2) 00175 : SCF_IMPL_SUPER(t1, t2), scfObject(object) {} 00176 00177 template<class T1, class T2, class T3> 00178 SCF_IMPL_NAME(Class *object, T1 t1, T2 t2, T3 t3) 00179 : SCF_IMPL_SUPER(t1, t2, t3), scfObject(object) {} 00180 00181 template<class T1, class T2, class T3, class T4> 00182 SCF_IMPL_NAME(Class *object, T1 t1, T2 t2, T3 t3, T4 t4) 00183 : SCF_IMPL_SUPER(t1, t2, t3, t4), scfObject(object) {} 00184 00185 template<class T1, class T2, class T3, class T4, class T5> 00186 SCF_IMPL_NAME(Class *object, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) 00187 : SCF_IMPL_SUPER(t1, t2, t3, t4, t5), scfObject(object) {} 00188 00189 Class *scfObject; 00190 #endif 00191 00192 virtual ~SCF_IMPL_NAME() {} 00193 00194 typedef SCF_IMPL_NAME<Class, SCF_IMPL_ARGS> scfImplementationType; 00195 00196 private: 00197 template<class I> 00198 struct VC6Workaround 00199 { 00200 static CS_FORCEINLINE void* GetInterface(Class* scfObject, scfInterfaceID id, 00201 scfInterfaceVersion version) 00202 { 00203 if (id == scfInterfaceTraits<I>::GetID() && 00204 scfCompatibleVersion(version, scfInterfaceTraits<I>::GetVersion())) 00205 { 00206 scfObject->IncRef(); 00207 return CS_STATIC_CAST(I*, scfObject); 00208 } 00209 else 00210 { 00211 return 0; 00212 } 00213 } 00214 }; 00215 }; 00216 00217 #undef SCF_IMPL_NAME 00218 #undef SCF_IMPL_SUPER 00219 #undef SCF_IMPL_PRE_TYPES 00220 #undef SCF_IMPL_PRE_ARGS 00221 00222 #undef SCF_IMPL_TYPES 00223 #undef SCF_IMPL_ARGS 00224 #undef SCF_IMPL_INTERFACES 00225
Generated for Crystal Space by doxygen 1.4.4