Library of Assembled Shared Sources
object_factory.h
Go to the documentation of this file.
1/*
2 * *** ATTENTION! DO NOT MODIFY THIS FILE DIRECTLY! ***
3 *
4 * It has automatically been generated from object_factory.tmpl.h
5 * by param_expander.py on Mon Oct 6 22:51:38 2025.
6 */
7
8/** @file
9 * @author Bram de Greve (bram@cocamware.com)
10 * @author Tom De Muer (tom@cocamware.com)
11 *
12 * *** BEGIN LICENSE INFORMATION ***
13 *
14 * The contents of this file are subject to the Common Public Attribution License
15 * Version 1.0 (the "License"); you may not use this file except in compliance with
16 * the License. You may obtain a copy of the License at
17 * http://lass.sourceforge.net/cpal-license. The License is based on the
18 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
19 * use of software over a computer network and provide for limited attribution for
20 * the Original Developer. In addition, Exhibit A has been modified to be consistent
21 * with Exhibit B.
22 *
23 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
24 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
25 * language governing rights and limitations under the License.
26 *
27 * The Original Code is LASS - Library of Assembled Shared Sources.
28 *
29 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
30 * The Original Developer is the Initial Developer.
31 *
32 * All portions of the code written by the Initial Developer are:
33 * Copyright (C) 2004-2011 the Initial Developer.
34 * All Rights Reserved.
35 *
36 * Contributor(s):
37 *
38 * Alternatively, the contents of this file may be used under the terms of the
39 * GNU General Public License Version 2 or later (the GPL), in which case the
40 * provisions of GPL are applicable instead of those above. If you wish to allow use
41 * of your version of this file only under the terms of the GPL and not to allow
42 * others to use your version of this file under the CPAL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and other
44 * provisions required by the GPL License. If you do not delete the provisions above,
45 * a recipient may use your version of this file under either the CPAL or the GPL.
46 *
47 * *** END LICENSE INFORMATION ***
48 */
49
50#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_OBJECT_FACTORY_H
51#define LASS_GUARDIAN_OF_INCLUSION_UTIL_OBJECT_FACTORY_H
52
53#include "util_common.h"
54
55namespace lass
56{
57namespace util
58{
59
60template
61<
62 typename ObjectType,
63 typename KeyType,
64 typename PointerType = ObjectType*,
65 typename MakerType = PointerType(*)()
66>
67class ObjectFactory
68{
69public:
70
71 typedef ObjectType TObject;
72 typedef KeyType TKey;
73 typedef PointerType TPointer;
74 typedef MakerType TMaker;
75
76 void subscribe(typename CallTraits<TKey>::TParam key, typename CallTraits<TMaker>::TParam maker)
77 {
78 makers_[key] = maker;
79 }
80
81 TPointer make(typename CallTraits<TKey>::TParam key) const
82 {
83 const typename TMakers::const_iterator i = makers_.find(key);
84 if (i == makers_.end())
85 {
86 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
87 }
88 return (i->second)();
89 }
90
91 template <typename P1>
92 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1) const
93 {
94 const typename TMakers::const_iterator i = makers_.find(key);
95 if (i == makers_.end())
96 {
97 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
98 }
99 return (i->second)(p1);
100 }
101
102 template <typename P1, typename P2>
103 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2) const
104 {
105 const typename TMakers::const_iterator i = makers_.find(key);
106 if (i == makers_.end())
107 {
108 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
109 }
110 return (i->second)(p1, p2);
111 }
112
113 template <typename P1, typename P2, typename P3>
114 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3) const
115 {
116 const typename TMakers::const_iterator i = makers_.find(key);
117 if (i == makers_.end())
118 {
119 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
120 }
121 return (i->second)(p1, p2, p3);
122 }
123
124 template <typename P1, typename P2, typename P3, typename P4>
125 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4) const
126 {
127 const typename TMakers::const_iterator i = makers_.find(key);
128 if (i == makers_.end())
129 {
130 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
131 }
132 return (i->second)(p1, p2, p3, p4);
133 }
134
135 template <typename P1, typename P2, typename P3, typename P4, typename P5>
136 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5) const
137 {
138 const typename TMakers::const_iterator i = makers_.find(key);
139 if (i == makers_.end())
140 {
141 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
142 }
143 return (i->second)(p1, p2, p3, p4, p5);
144 }
145
146 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
147 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6) const
148 {
149 const typename TMakers::const_iterator i = makers_.find(key);
150 if (i == makers_.end())
151 {
152 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
153 }
154 return (i->second)(p1, p2, p3, p4, p5, p6);
155 }
156
157 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
158 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7) const
159 {
160 const typename TMakers::const_iterator i = makers_.find(key);
161 if (i == makers_.end())
162 {
163 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
164 }
165 return (i->second)(p1, p2, p3, p4, p5, p6, p7);
166 }
167
168 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
169 TPointer make(typename CallTraits<TKey>::TParam key, P1& p1, P2& p2, P3& p3, P4& p4, P5& p5, P6& p6, P7& p7, P8& p8) const
170 {
171 const typename TMakers::const_iterator i = makers_.find(key);
172 if (i == makers_.end())
173 {
174 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
175 }
176 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8);
177 }
178
179 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
180 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
181 {
182 const typename TMakers::const_iterator i = makers_.find(key);
183 if (i == makers_.end())
184 {
185 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
186 }
187 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9);
188 }
189
190 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10>
191 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
192 {
193 const typename TMakers::const_iterator i = makers_.find(key);
194 if (i == makers_.end())
195 {
196 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
197 }
198 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
199 }
200
201 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>
202 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
203 {
204 const typename TMakers::const_iterator i = makers_.find(key);
205 if (i == makers_.end())
206 {
207 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
208 }
209 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
210 }
211
212 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>
213 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
214 {
215 const typename TMakers::const_iterator i = makers_.find(key);
216 if (i == makers_.end())
217 {
218 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
219 }
220 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12);
221 }
222
223 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>
224 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
225 {
226 const typename TMakers::const_iterator i = makers_.find(key);
227 if (i == makers_.end())
228 {
229 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
230 }
231 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13);
232 }
233
234 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>
235 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
236 {
237 const typename TMakers::const_iterator i = makers_.find(key);
238 if (i == makers_.end())
239 {
240 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
241 }
242 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14);
243 }
244
245 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>
246 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
247 {
248 const typename TMakers::const_iterator i = makers_.find(key);
249 if (i == makers_.end())
250 {
251 LASS_THROW_EX(KeyError, "no product maker registered by key '" << key << "'");
252 }
253 return (i->second)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15);
254 }
255
256
257private:
258
259 typedef std::map<TKey, TMaker> TMakers;
260
261 TMakers makers_;
262};
263
264}
265}
266
267#endif
268
269// EOF
270
general utility, debug facilities, ...
Library for Assembled Shared Sources.
Definition config.h:53