library of assembled shared sources

http://lass.cocamware.com

object_factory.h

Go to the documentation of this file.
00001 /*
00002  * *** ATTENTION!  DO NOT MODIFY THIS FILE DIRECTLY! ***
00003  * 
00004  * It has automatically been generated from object_factory.tmpl.h
00005  * by param_expander.py on Sun Nov 09 16:55:52 2008.
00006  */
00007 
00008 /** @file
00009  *  @author Bram de Greve (bramz@users.sourceforge.net)
00010  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00011  *
00012  *  *** BEGIN LICENSE INFORMATION ***
00013  *  
00014  *  The contents of this file are subject to the Common Public Attribution License 
00015  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00016  *  the License. You may obtain a copy of the License at 
00017  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00018  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00019  *  use of software over a computer network and provide for limited attribution for 
00020  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00021  *  with Exhibit B.
00022  *  
00023  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00024  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00025  *  language governing rights and limitations under the License.
00026  *  
00027  *  The Original Code is LASS - Library of Assembled Shared Sources.
00028  *  
00029  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00030  *  The Original Developer is the Initial Developer.
00031  *  
00032  *  All portions of the code written by the Initial Developer are:
00033  *  Copyright (C) 2004-2007 the Initial Developer.
00034  *  All Rights Reserved.
00035  *  
00036  *  Contributor(s):
00037  *
00038  *  Alternatively, the contents of this file may be used under the terms of the 
00039  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00040  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00041  *  of your version of this file only under the terms of the GPL and not to allow 
00042  *  others to use your version of this file under the CPAL, indicate your decision by 
00043  *  deleting the provisions above and replace them with the notice and other 
00044  *  provisions required by the GPL License. If you do not delete the provisions above,
00045  *  a recipient may use your version of this file under either the CPAL or the GPL.
00046  *  
00047  *  *** END LICENSE INFORMATION ***
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 // EOF
00270 

Generated on Mon Nov 10 14:20:31 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo