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
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_OBJECT_FACTORY_H
00051 #define LASS_GUARDIAN_OF_INCLUSION_UTIL_OBJECT_FACTORY_H
00052
00053 #include "util_common.h"
00054
00055 namespace lass
00056 {
00057 namespace util
00058 {
00059
00060 template
00061 <
00062 typename ObjectType,
00063 typename KeyType,
00064 typename PointerType = ObjectType*,
00065 typename MakerType = PointerType(*)()
00066 >
00067 class ObjectFactory
00068 {
00069 public:
00070
00071 typedef ObjectType TObject;
00072 typedef KeyType TKey;
00073 typedef PointerType TPointer;
00074 typedef MakerType TMaker;
00075
00076 void subscribe(typename CallTraits<TKey>::TParam key, typename CallTraits<TMaker>::TParam maker)
00077 {
00078 makers_[key] = maker;
00079 }
00080
00081 TPointer make(typename CallTraits<TKey>::TParam key) const
00082 {
00083 const typename TMakers::const_iterator i = makers_.find(key);
00084 if (i == makers_.end())
00085 {
00086 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00087 }
00088 return (i->second)();
00089 }
00090
00091 template <typename P1>
00092 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1) const
00093 {
00094 const typename TMakers::const_iterator i = makers_.find(key);
00095 if (i == makers_.end())
00096 {
00097 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00098 }
00099 return (i->second)(p1);
00100 }
00101
00102 template <typename P1, typename P2>
00103 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2) const
00104 {
00105 const typename TMakers::const_iterator i = makers_.find(key);
00106 if (i == makers_.end())
00107 {
00108 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00109 }
00110 return (i->second)(p1, p2);
00111 }
00112
00113 template <typename P1, typename P2, typename P3>
00114 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3) const
00115 {
00116 const typename TMakers::const_iterator i = makers_.find(key);
00117 if (i == makers_.end())
00118 {
00119 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00120 }
00121 return (i->second)(p1, p2, p3);
00122 }
00123
00124 template <typename P1, typename P2, typename P3, typename P4>
00125 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4) const
00126 {
00127 const typename TMakers::const_iterator i = makers_.find(key);
00128 if (i == makers_.end())
00129 {
00130 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00131 }
00132 return (i->second)(p1, p2, p3, p4);
00133 }
00134
00135 template <typename P1, typename P2, typename P3, typename P4, typename P5>
00136 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5) const
00137 {
00138 const typename TMakers::const_iterator i = makers_.find(key);
00139 if (i == makers_.end())
00140 {
00141 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00142 }
00143 return (i->second)(p1, p2, p3, p4, p5);
00144 }
00145
00146 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00147 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6) const
00148 {
00149 const typename TMakers::const_iterator i = makers_.find(key);
00150 if (i == makers_.end())
00151 {
00152 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00153 }
00154 return (i->second)(p1, p2, p3, p4, p5, p6);
00155 }
00156
00157 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
00158 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7) const
00159 {
00160 const typename TMakers::const_iterator i = makers_.find(key);
00161 if (i == makers_.end())
00162 {
00163 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00164 }
00165 return (i->second)(p1, p2, p3, p4, p5, p6, p7);
00166 }
00167
00168 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
00169 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8) const
00170 {
00171 const typename TMakers::const_iterator i = makers_.find(key);
00172 if (i == makers_.end())
00173 {
00174 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00175 }
00176 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8);
00177 }
00178
00179 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
00180 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8, P9& p9) const
00181 {
00182 const typename TMakers::const_iterator i = makers_.find(key);
00183 if (i == makers_.end())
00184 {
00185 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00186 }
00187 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9);
00188 }
00189
00190 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
00191 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8, P9& p9, P10& p10) const
00192 {
00193 const typename TMakers::const_iterator i = makers_.find(key);
00194 if (i == makers_.end())
00195 {
00196 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00197 }
00198 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
00199 }
00200
00201 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
00202 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8, P9& p9, P10& p10, P11& p11) const
00203 {
00204 const typename TMakers::const_iterator i = makers_.find(key);
00205 if (i == makers_.end())
00206 {
00207 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00208 }
00209 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
00210 }
00211
00212 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>
00213 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8, P9& p9, P10& p10, P11& p11, P12& p12) const
00214 {
00215 const typename TMakers::const_iterator i = makers_.find(key);
00216 if (i == makers_.end())
00217 {
00218 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00219 }
00220 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12);
00221 }
00222
00223 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13>
00224 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8, P9& p9, P10& p10, P11& p11, P12& p12, P13& p13) const
00225 {
00226 const typename TMakers::const_iterator i = makers_.find(key);
00227 if (i == makers_.end())
00228 {
00229 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00230 }
00231 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13);
00232 }
00233
00234 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14>
00235 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8, P9& p9, P10& p10, P11& p11, P12& p12, P13& p13, P14& p14) const
00236 {
00237 const typename TMakers::const_iterator i = makers_.find(key);
00238 if (i == makers_.end())
00239 {
00240 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00241 }
00242 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14);
00243 }
00244
00245 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15>
00246 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8, P9& p9, P10& p10, P11& p11, P12& p12, P13& p13, P14& p14, P15& p15) const
00247 {
00248 const typename TMakers::const_iterator i = makers_.find(key);
00249 if (i == makers_.end())
00250 {
00251 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
00252 }
00253 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15);
00254 }
00255
00256
00257 private:
00258
00259 typedef std::map<TKey, TMaker> TMakers;
00260
00261 TMakers makers_;
00262 };
00263
00264 }
00265 }
00266
00267 #endif
00268
00269
00270