2002-08-11 05:49:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The Loki Library
|
|
|
|
// Copyright (c) 2001 by Andrei Alexandrescu
|
2005-07-28 14:03:30 +00:00
|
|
|
// Copyright (c) 2005 by Peter Kuemmel
|
|
|
|
// This code DOES NOT accompany the book:
|
2006-10-27 18:05:03 +00:00
|
|
|
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
|
2002-08-11 05:49:45 +00:00
|
|
|
// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
|
2005-07-28 14:03:30 +00:00
|
|
|
//
|
|
|
|
// Code covered by the MIT License
|
2011-09-23 00:46:21 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
2002-08-11 05:49:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2005-09-26 07:33:05 +00:00
|
|
|
#ifndef LOKI_FACTORYPARM_INC_
|
|
|
|
#define LOKI_FACTORYPARM_INC_
|
2002-08-11 05:49:45 +00:00
|
|
|
|
2006-10-17 19:50:02 +00:00
|
|
|
// $Id$
|
|
|
|
|
2006-01-16 19:05:09 +00:00
|
|
|
|
2010-04-19 03:09:59 +00:00
|
|
|
#include <loki/LokiTypeInfo.h>
|
|
|
|
#include <loki/Functor.h>
|
|
|
|
#include <loki/AssocVector.h>
|
|
|
|
#include <loki/SmallObj.h>
|
|
|
|
#include <loki/Sequence.h>
|
2005-07-28 14:03:30 +00:00
|
|
|
|
2005-10-05 09:57:37 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable: 4702)
|
|
|
|
//unreachable code if OnUnknownType throws an exception
|
|
|
|
#endif
|
|
|
|
|
2006-10-27 18:05:03 +00:00
|
|
|
/**
|
|
|
|
* \defgroup FactoriesGroup Factories
|
|
|
|
* \defgroup FactoryGroup Factory
|
|
|
|
* \ingroup FactoriesGroup
|
|
|
|
* \brief Implements a generic object factory.
|
2010-04-19 03:09:59 +00:00
|
|
|
*
|
2006-10-27 18:05:03 +00:00
|
|
|
* <i>The Factory Method pattern is an object-oriented design pattern.
|
|
|
|
* Like other creational patterns, it deals with the problem of creating objects
|
|
|
|
* (products) without specifying the exact class of object that will be created.
|
|
|
|
* Factory Method, one of the patterns from the Design Patterns book, handles
|
|
|
|
* this problem by defining a separate method for creating the objects, which
|
|
|
|
* subclasses can then override to specify the derived type of product that will
|
|
|
|
* be created.
|
|
|
|
* <br>
|
|
|
|
* More generally, the term Factory Method is often used to refer to any method
|
|
|
|
* whose main purpose is creation of objects.</i>
|
|
|
|
* <div ALIGN="RIGHT"><a href="http://en.wikipedia.org/wiki/Factory_method_pattern">
|
|
|
|
* Wikipedia</a></div>
|
2010-04-19 03:09:59 +00:00
|
|
|
*
|
2006-10-27 18:05:03 +00:00
|
|
|
* Loki proposes a generic version of the Factory. Here is a typical use.<br>
|
|
|
|
* <code><br>
|
|
|
|
* 1. Factory< AbstractProduct, int > aFactory;<br>
|
|
|
|
* 2. aFactory.Register( 1, createProductNull );<br>
|
|
|
|
* 3. aFactory.CreateObject( 1 ); <br>
|
|
|
|
* </code><br>
|
|
|
|
* <br>
|
|
|
|
* - 1. The declaration<br>
|
|
|
|
* You want a Factory that produces AbstractProduct.<br>
|
|
|
|
* The client will refer to a creation method through an int.<br>
|
|
|
|
* - 2.The registration<br>
|
|
|
|
* The code that will contribute to the Factory will now need to declare its
|
|
|
|
* ProductCreator by registering them into the Factory.<br>
|
|
|
|
* A ProductCreator is a just a function that will return the right object. ie <br>
|
|
|
|
* <code>
|
2010-04-19 03:09:59 +00:00
|
|
|
* Product* createProductNull()<br>
|
2006-10-27 18:05:03 +00:00
|
|
|
* {<br>
|
|
|
|
* return new Product<br>
|
|
|
|
* }<br>
|
|
|
|
* </code><br>
|
|
|
|
* - 3. The use<br>
|
|
|
|
* Now the client can create object by calling the Factory's CreateObject method
|
|
|
|
* with the right identifier. If the ProductCreator were to have arguments
|
|
|
|
* (<i>ie :Product* createProductParm( int a, int b )</i>)
|
|
|
|
*/
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
namespace Loki
|
|
|
|
{
|
2005-07-28 14:13:46 +00:00
|
|
|
|
2006-10-27 18:05:03 +00:00
|
|
|
/**
|
|
|
|
* \defgroup FactoryErrorPoliciesGroup Factory Error Policies
|
|
|
|
* \ingroup FactoryGroup
|
|
|
|
* \brief Manages the "Unknown Type" error in an object factory
|
2010-04-19 03:09:59 +00:00
|
|
|
*
|
2006-10-27 18:05:03 +00:00
|
|
|
* \class DefaultFactoryError
|
|
|
|
* \ingroup FactoryErrorPoliciesGroup
|
2010-04-19 03:09:59 +00:00
|
|
|
* \brief Default policy that throws an exception
|
|
|
|
*
|
2006-10-27 18:05:03 +00:00
|
|
|
*/
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
template <typename IdentifierType, class AbstractProduct>
|
|
|
|
struct DefaultFactoryError
|
|
|
|
{
|
|
|
|
struct Exception : public std::exception
|
|
|
|
{
|
|
|
|
const char* what() const throw() { return "Unknown Type"; }
|
|
|
|
};
|
2006-10-27 18:05:03 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
static AbstractProduct* OnUnknownType(IdentifierType)
|
|
|
|
{
|
|
|
|
throw Exception();
|
|
|
|
}
|
|
|
|
};
|
2006-10-27 18:05:03 +00:00
|
|
|
|
|
|
|
|
2005-09-26 07:33:05 +00:00
|
|
|
#define LOKI_ENABLE_NEW_FACTORY_CODE
|
|
|
|
#ifdef LOKI_ENABLE_NEW_FACTORY_CODE
|
2005-07-28 14:03:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template FunctorImpl
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-10-27 18:05:03 +00:00
|
|
|
struct FactoryImplBase
|
2005-07-28 14:03:30 +00:00
|
|
|
{
|
|
|
|
typedef EmptyType Parm1;
|
|
|
|
typedef EmptyType Parm2;
|
|
|
|
typedef EmptyType Parm3;
|
|
|
|
typedef EmptyType Parm4;
|
|
|
|
typedef EmptyType Parm5;
|
|
|
|
typedef EmptyType Parm6;
|
|
|
|
typedef EmptyType Parm7;
|
|
|
|
typedef EmptyType Parm8;
|
|
|
|
typedef EmptyType Parm9;
|
|
|
|
typedef EmptyType Parm10;
|
|
|
|
typedef EmptyType Parm11;
|
|
|
|
typedef EmptyType Parm12;
|
|
|
|
typedef EmptyType Parm13;
|
|
|
|
typedef EmptyType Parm14;
|
|
|
|
typedef EmptyType Parm15;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename AP, typename Id, typename TList >
|
|
|
|
struct FactoryImpl;
|
|
|
|
|
|
|
|
template<typename AP, typename Id>
|
|
|
|
struct FactoryImpl<AP, Id, NullType>
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id & id ) = 0;
|
|
|
|
};
|
2005-10-30 13:49:44 +00:00
|
|
|
template <typename AP, typename Id, typename P1 >
|
|
|
|
struct FactoryImpl<AP,Id, Seq<P1> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id, typename P1,typename P2 >
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id, typename P1,typename P2,typename P3 >
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id, typename P1,typename P2,typename P3,typename P4 >
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5 >
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6 )
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7 )
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7, P8> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8,typename P9>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7, P8, P9> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8,typename P9,typename P10>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8,typename P9,typename P10,
|
|
|
|
typename P11>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10,
|
|
|
|
Parm11)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8,typename P9,typename P10,
|
|
|
|
typename P11,typename P12>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
|
|
|
typedef typename TypeTraits<P12>::ParameterType Parm12;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10,
|
|
|
|
Parm11,Parm12)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
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>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
|
|
|
typedef typename TypeTraits<P12>::ParameterType Parm12;
|
|
|
|
typedef typename TypeTraits<P13>::ParameterType Parm13;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10,
|
|
|
|
Parm11,Parm12,Parm13)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
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>
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
|
|
|
typedef typename TypeTraits<P12>::ParameterType Parm12;
|
|
|
|
typedef typename TypeTraits<P13>::ParameterType Parm13;
|
|
|
|
typedef typename TypeTraits<P14>::ParameterType Parm14;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm8,Parm10,
|
|
|
|
Parm11,Parm12,Parm13,Parm14)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
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 >
|
|
|
|
struct FactoryImpl<AP, Id, Seq<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15> >
|
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
|
|
|
typedef typename TypeTraits<P12>::ParameterType Parm12;
|
|
|
|
typedef typename TypeTraits<P13>::ParameterType Parm13;
|
|
|
|
typedef typename TypeTraits<P14>::ParameterType Parm14;
|
|
|
|
typedef typename TypeTraits<P15>::ParameterType Parm15;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-10-30 13:49:44 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10,
|
|
|
|
Parm11,Parm12,Parm13,Parm14,Parm15 )
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef LOKI_DISABLE_TYPELIST_MACROS
|
2005-07-28 14:03:30 +00:00
|
|
|
|
|
|
|
template <typename AP, typename Id, typename P1 >
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP,Id, LOKI_TYPELIST_1( P1 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id, typename P1,typename P2 >
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_2( P1, P2 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id, typename P1,typename P2,typename P3 >
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_3( P1, P2, P3 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id, typename P1,typename P2,typename P3,typename P4 >
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_4( P1, P2, P3, P4 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5 >
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_5( P1, P2, P3, P4, P5 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5 ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_6( P1, P2, P3, P4, P5, P6 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6 )
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_7( P1, P2, P3, P4, P5, P6, P7 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7 )
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_8( P1, P2, P3, P4, P5, P6, P7, P8 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8,typename P9>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_9( P1, P2, P3, P4, P5, P6, P7, P8, P9 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8,typename P9,typename P10>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_10( P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8,typename P9,typename P10,
|
|
|
|
typename P11>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_11( P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10,
|
|
|
|
Parm11)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
typename P1,typename P2,typename P3,typename P4,typename P5,
|
|
|
|
typename P6,typename P7,typename P8,typename P9,typename P10,
|
|
|
|
typename P11,typename P12>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_12( P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
|
|
|
typedef typename TypeTraits<P12>::ParameterType Parm12;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10,
|
|
|
|
Parm11,Parm12)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
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>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_13( P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
|
|
|
typedef typename TypeTraits<P12>::ParameterType Parm12;
|
|
|
|
typedef typename TypeTraits<P13>::ParameterType Parm13;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10,
|
|
|
|
Parm11,Parm12,Parm13)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
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>
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_14( P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
|
|
|
typedef typename TypeTraits<P12>::ParameterType Parm12;
|
|
|
|
typedef typename TypeTraits<P13>::ParameterType Parm13;
|
|
|
|
typedef typename TypeTraits<P14>::ParameterType Parm14;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm8,Parm10,
|
|
|
|
Parm11,Parm12,Parm13,Parm14)
|
|
|
|
= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename AP, typename Id,
|
|
|
|
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 >
|
2005-09-26 07:33:05 +00:00
|
|
|
struct FactoryImpl<AP, Id, LOKI_TYPELIST_15( P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15 )>
|
2005-07-28 14:03:30 +00:00
|
|
|
: public FactoryImplBase
|
|
|
|
{
|
|
|
|
typedef typename TypeTraits<P1>::ParameterType Parm1;
|
|
|
|
typedef typename TypeTraits<P2>::ParameterType Parm2;
|
|
|
|
typedef typename TypeTraits<P3>::ParameterType Parm3;
|
|
|
|
typedef typename TypeTraits<P4>::ParameterType Parm4;
|
|
|
|
typedef typename TypeTraits<P5>::ParameterType Parm5;
|
|
|
|
typedef typename TypeTraits<P6>::ParameterType Parm6;
|
|
|
|
typedef typename TypeTraits<P7>::ParameterType Parm7;
|
|
|
|
typedef typename TypeTraits<P8>::ParameterType Parm8;
|
|
|
|
typedef typename TypeTraits<P9>::ParameterType Parm9;
|
|
|
|
typedef typename TypeTraits<P10>::ParameterType Parm10;
|
|
|
|
typedef typename TypeTraits<P11>::ParameterType Parm11;
|
|
|
|
typedef typename TypeTraits<P12>::ParameterType Parm12;
|
|
|
|
typedef typename TypeTraits<P13>::ParameterType Parm13;
|
|
|
|
typedef typename TypeTraits<P14>::ParameterType Parm14;
|
|
|
|
typedef typename TypeTraits<P15>::ParameterType Parm15;
|
2006-01-04 23:45:08 +00:00
|
|
|
virtual ~FactoryImpl() {}
|
2005-07-28 14:03:30 +00:00
|
|
|
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
|
|
|
|
Parm6, Parm7, Parm8, Parm9,Parm10,
|
|
|
|
Parm11,Parm12,Parm13,Parm14,Parm15 )
|
|
|
|
= 0;
|
2005-10-30 14:03:23 +00:00
|
|
|
};
|
2005-07-28 14:03:30 +00:00
|
|
|
|
2005-10-30 13:49:44 +00:00
|
|
|
#endif //LOKI_DISABLE_TYPELIST_MACROS
|
2005-07-28 14:03:30 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2005-11-03 12:43:55 +00:00
|
|
|
/// \class Factory
|
|
|
|
///
|
|
|
|
/// \ingroup FactoryGroup
|
2006-10-27 18:05:03 +00:00
|
|
|
/// Implements a generic object factory.
|
|
|
|
///
|
2005-11-03 12:43:55 +00:00
|
|
|
/// Create functions can have up to 15 parameters.
|
2006-10-27 18:05:03 +00:00
|
|
|
///
|
2006-05-20 10:23:07 +00:00
|
|
|
/// \par Singleton lifetime when used with Loki::SingletonHolder
|
2006-10-27 18:05:03 +00:00
|
|
|
/// Because Factory uses internally Functors which inherits from
|
2006-05-20 10:23:07 +00:00
|
|
|
/// SmallObject you must use the singleton lifetime
|
|
|
|
/// \code Loki::LongevityLifetime::DieAsSmallObjectChild \endcode
|
2006-10-27 18:05:03 +00:00
|
|
|
/// Alternatively you could suppress for Functor the inheritance
|
2006-05-20 10:23:07 +00:00
|
|
|
/// from SmallObject by defining the macro:
|
|
|
|
/// \code LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT \endcode
|
2002-08-11 05:49:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2005-07-28 14:03:30 +00:00
|
|
|
template
|
|
|
|
<
|
|
|
|
class AbstractProduct,
|
|
|
|
typename IdentifierType,
|
|
|
|
typename CreatorParmTList = NullType,
|
|
|
|
template<typename, class> class FactoryErrorPolicy = DefaultFactoryError
|
|
|
|
>
|
|
|
|
class Factory : public FactoryErrorPolicy<IdentifierType, AbstractProduct>
|
|
|
|
{
|
2009-12-22 11:35:46 +00:00
|
|
|
protected:
|
2005-07-28 14:03:30 +00:00
|
|
|
typedef FactoryImpl< AbstractProduct, IdentifierType, CreatorParmTList > Impl;
|
|
|
|
|
|
|
|
typedef typename Impl::Parm1 Parm1;
|
|
|
|
typedef typename Impl::Parm2 Parm2;
|
|
|
|
typedef typename Impl::Parm3 Parm3;
|
|
|
|
typedef typename Impl::Parm4 Parm4;
|
|
|
|
typedef typename Impl::Parm5 Parm5;
|
|
|
|
typedef typename Impl::Parm6 Parm6;
|
|
|
|
typedef typename Impl::Parm7 Parm7;
|
|
|
|
typedef typename Impl::Parm8 Parm8;
|
|
|
|
typedef typename Impl::Parm9 Parm9;
|
|
|
|
typedef typename Impl::Parm10 Parm10;
|
|
|
|
typedef typename Impl::Parm11 Parm11;
|
|
|
|
typedef typename Impl::Parm12 Parm12;
|
|
|
|
typedef typename Impl::Parm13 Parm13;
|
|
|
|
typedef typename Impl::Parm14 Parm14;
|
|
|
|
typedef typename Impl::Parm15 Parm15;
|
|
|
|
|
2005-11-12 17:11:55 +00:00
|
|
|
typedef Functor<AbstractProduct*, CreatorParmTList> ProductCreator;
|
|
|
|
|
2009-12-22 11:35:46 +00:00
|
|
|
private:
|
2005-11-12 17:11:55 +00:00
|
|
|
typedef AssocVector<IdentifierType, ProductCreator> IdToProductMap;
|
|
|
|
|
|
|
|
IdToProductMap associations_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2005-07-28 14:13:46 +00:00
|
|
|
Factory()
|
2006-01-19 23:11:57 +00:00
|
|
|
: associations_()
|
2005-07-28 14:13:46 +00:00
|
|
|
{
|
|
|
|
}
|
2005-07-28 14:03:30 +00:00
|
|
|
|
2005-07-28 14:13:46 +00:00
|
|
|
~Factory()
|
|
|
|
{
|
|
|
|
associations_.erase(associations_.begin(), associations_.end());
|
|
|
|
}
|
2005-07-28 14:03:30 +00:00
|
|
|
|
|
|
|
bool Register(const IdentifierType& id, ProductCreator creator)
|
|
|
|
{
|
|
|
|
return associations_.insert(
|
|
|
|
typename IdToProductMap::value_type(id, creator)).second != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class PtrObj, typename CreaFn>
|
|
|
|
bool Register(const IdentifierType& id, const PtrObj& p, CreaFn fn)
|
|
|
|
{
|
|
|
|
ProductCreator creator( p, fn );
|
|
|
|
return associations_.insert(
|
2005-07-28 14:13:46 +00:00
|
|
|
typename IdToProductMap::value_type(id, creator)).second != 0;
|
2005-07-28 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Unregister(const IdentifierType& id)
|
|
|
|
{
|
|
|
|
return associations_.erase(id) != 0;
|
|
|
|
}
|
|
|
|
|
2009-12-22 11:35:46 +00:00
|
|
|
bool IsRegistered(const IdentifierType& id)
|
|
|
|
{
|
|
|
|
return associations_.find(id) != associations_.end();
|
|
|
|
}
|
|
|
|
|
2005-11-12 17:11:55 +00:00
|
|
|
std::vector<IdentifierType> RegisteredIds()
|
2005-11-12 16:52:36 +00:00
|
|
|
{
|
2005-11-12 17:11:55 +00:00
|
|
|
std::vector<IdentifierType> ids;
|
2006-10-27 18:05:03 +00:00
|
|
|
for(typename IdToProductMap::iterator it = associations_.begin();
|
2005-11-12 17:11:55 +00:00
|
|
|
it != associations_.end(); ++it)
|
|
|
|
{
|
|
|
|
ids.push_back(it->first);
|
|
|
|
}
|
|
|
|
return ids;
|
2005-11-12 16:52:36 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 14:03:30 +00:00
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7 )
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7, Parm8 p8)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7,p8 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7,p8,p9 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9,Parm10 p10)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10,
|
|
|
|
Parm11 p11)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10,
|
|
|
|
Parm11 p11, Parm12 p12)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10,
|
|
|
|
Parm11 p11, Parm12 p12, Parm13 p13)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10,
|
|
|
|
Parm11 p11, Parm12 p12, Parm13 p13, Parm14 p14)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id,
|
|
|
|
Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5,
|
|
|
|
Parm6 p6, Parm7 p7, Parm8 p8, Parm9 p9, Parm10 p10,
|
|
|
|
Parm11 p11, Parm12 p12, Parm13 p13, Parm14 p14, Parm15 p15)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
return (i->second)( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15 );
|
|
|
|
return this->OnUnknownType(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
template
|
|
|
|
<
|
2006-10-27 18:05:03 +00:00
|
|
|
class AbstractProduct,
|
2002-08-11 05:49:45 +00:00
|
|
|
typename IdentifierType,
|
|
|
|
typename ProductCreator = AbstractProduct* (*)(),
|
|
|
|
template<typename, class>
|
|
|
|
class FactoryErrorPolicy = DefaultFactoryError
|
|
|
|
>
|
2006-10-27 18:05:03 +00:00
|
|
|
class Factory
|
2002-08-11 05:49:45 +00:00
|
|
|
: public FactoryErrorPolicy<IdentifierType, AbstractProduct>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool Register(const IdentifierType& id, ProductCreator creator)
|
|
|
|
{
|
|
|
|
return associations_.insert(
|
2006-11-24 22:30:54 +00:00
|
|
|
typename IdToProductMap::value_type(id, creator)).second != 0;
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
2006-10-27 18:05:03 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
bool Unregister(const IdentifierType& id)
|
|
|
|
{
|
2006-11-24 22:30:54 +00:00
|
|
|
return associations_.erase(id) != 0;
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
2006-10-27 18:05:03 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
AbstractProduct* CreateObject(const IdentifierType& id)
|
|
|
|
{
|
|
|
|
typename IdToProductMap::iterator i = associations_.find(id);
|
|
|
|
if (i != associations_.end())
|
|
|
|
{
|
|
|
|
return (i->second)();
|
|
|
|
}
|
2003-02-02 16:35:14 +00:00
|
|
|
return this->OnUnknownType(id);
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
2006-10-27 18:05:03 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
private:
|
|
|
|
typedef AssocVector<IdentifierType, ProductCreator> IdToProductMap;
|
|
|
|
IdToProductMap associations_;
|
|
|
|
};
|
|
|
|
|
2005-07-31 14:23:24 +00:00
|
|
|
#endif //#define ENABLE_NEW_FACTORY_CODE
|
2005-07-28 14:03:30 +00:00
|
|
|
|
2006-10-27 18:05:03 +00:00
|
|
|
/**
|
|
|
|
* \defgroup CloneFactoryGroup Clone Factory
|
|
|
|
* \ingroup FactoriesGroup
|
|
|
|
* \brief Creates a copy from a polymorphic object.
|
|
|
|
*
|
|
|
|
* \class CloneFactory
|
|
|
|
* \ingroup CloneFactoryGroup
|
|
|
|
* \brief Creates a copy from a polymorphic object.
|
|
|
|
*/
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
template
|
|
|
|
<
|
2006-10-27 18:05:03 +00:00
|
|
|
class AbstractProduct,
|
|
|
|
class ProductCreator =
|
2002-08-11 05:49:45 +00:00
|
|
|
AbstractProduct* (*)(const AbstractProduct*),
|
|
|
|
template<typename, class>
|
|
|
|
class FactoryErrorPolicy = DefaultFactoryError
|
|
|
|
>
|
|
|
|
class CloneFactory
|
|
|
|
: public FactoryErrorPolicy<TypeInfo, AbstractProduct>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool Register(const TypeInfo& ti, ProductCreator creator)
|
|
|
|
{
|
|
|
|
return associations_.insert(
|
2006-11-24 22:30:54 +00:00
|
|
|
typename IdToProductMap::value_type(ti, creator)).second != 0;
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
2006-10-27 18:05:03 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
bool Unregister(const TypeInfo& id)
|
|
|
|
{
|
2006-11-24 22:30:54 +00:00
|
|
|
return associations_.erase(id) != 0;
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
2006-10-27 18:05:03 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
AbstractProduct* CreateObject(const AbstractProduct* model)
|
|
|
|
{
|
2006-11-24 22:30:54 +00:00
|
|
|
if (model == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-10-27 18:05:03 +00:00
|
|
|
|
2010-04-19 03:09:59 +00:00
|
|
|
typename IdToProductMap::iterator i =
|
2006-11-24 22:30:54 +00:00
|
|
|
associations_.find(typeid(*model));
|
2010-04-19 03:09:59 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
if (i != associations_.end())
|
|
|
|
{
|
|
|
|
return (i->second)(model);
|
|
|
|
}
|
2003-02-02 16:35:14 +00:00
|
|
|
return this->OnUnknownType(typeid(*model));
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
2006-10-27 18:05:03 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
private:
|
|
|
|
typedef AssocVector<TypeInfo, ProductCreator> IdToProductMap;
|
|
|
|
IdToProductMap associations_;
|
|
|
|
};
|
2010-04-19 03:09:59 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
} // namespace Loki
|
|
|
|
|
2006-11-24 22:30:54 +00:00
|
|
|
|
2005-10-05 09:57:37 +00:00
|
|
|
#ifdef _MSC_VER
|
2006-10-27 18:05:03 +00:00
|
|
|
#pragma warning( pop )
|
2005-10-05 09:57:37 +00:00
|
|
|
#endif
|
|
|
|
|
2006-10-17 19:31:33 +00:00
|
|
|
#endif // end file guardian
|
2005-07-28 14:13:46 +00:00
|
|
|
|