00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef UTIL_OBJCREATOR_H_DEFINED
00036 #define UTIL_OBJCREATOR_H_DEFINED
00037
00038 #ifdef INVT_USE_CPPOX//we need c++ 0X features for this to work
00039
00040 #include "GenericUtils/ParamList.H"
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 template <class T, class ConvertType = T>
00057 class ObjCreator
00058 {
00059 public:
00060 template <typename... Params>
00061 static T* create(const ParamList<Params...>& paramlist)
00062 {
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 T* t = creator<ParamList<Params...>::length, T>::create(paramlist);
00077 ConvertType* ct = dynamic_cast<ConvertType*>(t);
00078 return (ct == NULL) ? NULL : ct;
00079 };
00080
00081 private:
00082
00083
00084
00085
00086 template <uint num, class U> struct creator;
00087
00088 template <class U> struct creator<0, U> {
00089 template<typename... Params>
00090 static U* create(const ParamList<Params...>& pl)
00091 { return new U(); }; };
00092
00093 template <class U> struct creator<1, U> {
00094 template<typename... Params>
00095 static U* create(const ParamList<Params...>& pl)
00096 {return new U(ParamListHelper::at<0>(pl)); }; };
00097
00098 template <class U> struct creator<2, U> {
00099 template<typename... Params>
00100 static U* create(const ParamList<Params...>& pl)
00101 { using namespace ParamListHelper;
00102 return new U(at<0>(pl),at<1>(pl)); }; };
00103
00104 template <class U> struct creator<3, U> {
00105 template<typename... Params>
00106 static U* create(const ParamList<Params...>& pl)
00107 { using namespace ParamListHelper;
00108 return new U(at<0>(pl),at<1>(pl),at<2>(pl)); }; };
00109
00110 template <class U> struct creator<4, U> {
00111 template<typename... Params>
00112 static U* create(const ParamList<Params...>& pl)
00113 { using namespace ParamListHelper;
00114 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl)); }; };
00115
00116 template <class U> struct creator<5, U> {
00117 template<typename... Params>
00118 static U* create(const ParamList<Params...>& pl)
00119 { using namespace ParamListHelper;
00120 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl)); }; };
00121
00122 template <class U> struct creator<6, U> {
00123 template<typename... Params>
00124 static U* create(const ParamList<Params...>& pl)
00125 { using namespace ParamListHelper;
00126 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00127 at<5>(pl)); }; };
00128
00129 template <class U> struct creator<7, U> {
00130 template<typename... Params>
00131 static U* create(const ParamList<Params...>& pl)
00132 { using namespace ParamListHelper;
00133 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00134 at<5>(pl), at<6>(pl)); }; };
00135
00136 template <class U> struct creator<8, U> {
00137 template<typename... Params>
00138 static U* create(const ParamList<Params...>& pl)
00139 { using namespace ParamListHelper;
00140 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00141 at<5>(pl),at<6>(pl),at<7>(pl)); }; };
00142
00143 template <class U> struct creator<9, U> {
00144 template<typename... Params>
00145 static U* create(const ParamList<Params...>& pl)
00146 { using namespace ParamListHelper;
00147 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00148 at<5>(pl),at<6>(pl),at<7>(pl),at<8>(pl)); }; };
00149
00150 template <class U> struct creator<10, U> {
00151 template<typename... Params>
00152 static U* create(const ParamList<Params...>& pl)
00153 { using namespace ParamListHelper;
00154 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00155 at<5>(pl),at<6>(pl),at<7>(pl),at<8>(pl),at<9>(pl)); }; };
00156
00157 template <class U> struct creator<11, U> {
00158 template<typename... Params>
00159 static U* create(const ParamList<Params...>& pl)
00160 { using namespace ParamListHelper;
00161 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00162 at<5>(pl),at<6>(pl),at<7>(pl),at<8>(pl),at<9>(pl),
00163 at<10>(pl)); }; };
00164
00165 template <class U> struct creator<12, U> {
00166 template<typename... Params>
00167 static U* create(const ParamList<Params...>& pl)
00168 { using namespace ParamListHelper;
00169 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00170 at<5>(pl),at<6>(pl),at<7>(pl),at<8>(pl),at<9>(pl),
00171 at<10>(pl),at<11>(pl)); }; };
00172
00173 template <class U> struct creator<13, U> {
00174 template<typename... Params>
00175 static U* create(const ParamList<Params...>& pl)
00176 { using namespace ParamListHelper;
00177 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00178 at<5>(pl),at<6>(pl),at<7>(pl),at<8>(pl),at<9>(pl),
00179 at<10>(pl),at<11>(pl),at<12>(pl)); }; };
00180
00181 template <class U> struct creator<14, U> {
00182 template<typename... Params>
00183 static U* create(const ParamList<Params...>& pl)
00184 { using namespace ParamListHelper;
00185 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00186 at<5>(pl),at<6>(pl),at<7>(pl),at<8>(pl),at<9>(pl),
00187 at<10>(pl),at<11>(pl),at<12>(pl),at<13>(pl)); }; };
00188
00189
00190 template <class U> struct creator<15, U> {
00191 template<typename... Params>
00192 static U* create(const ParamList<Params...>& pl)
00193 { using namespace ParamListHelper;
00194 return new U(at<0>(pl),at<1>(pl),at<2>(pl),at<3>(pl),at<4>(pl),
00195 at<5>(pl),at<6>(pl),at<7>(pl),at<8>(pl),at<9>(pl),
00196 at<10>(pl),at<11>(pl),at<12>(pl),at<13>(pl), at<15>(pl)); }; };
00197 };
00198
00199 #endif //INVT_USE_CPPOX
00200 #endif//UTIL_OBJCREATOR_H_DEFINED