/usr/include/loki/Factory.h is in libloki-dev 0.1.7-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | ////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// Copyright (c) 2005 by Peter Kuemmel
// This code DOES NOT accompany the book:
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
//
// Code covered by the MIT License
// The authors make no representations about the suitability of this software
// for any purpose. It is provided "as is" without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
#ifndef LOKI_FACTORYPARM_INC_
#define LOKI_FACTORYPARM_INC_
// $Id: Factory.h 788 2006-11-24 22:30:54Z clitte_bbt $
#include "LokiTypeInfo.h"
#include "Functor.h"
#include "AssocVector.h"
#include "SmallObj.h"
#include "Sequence.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4702)
//unreachable code if OnUnknownType throws an exception
#endif
/**
* \defgroup FactoriesGroup Factories
* \defgroup FactoryGroup Factory
* \ingroup FactoriesGroup
* \brief Implements a generic object factory.
*
* <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>
*
* 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>
* Product* createProductNull()<br>
* {<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>)
*/
namespace Loki
{
/**
* \defgroup FactoryErrorPoliciesGroup Factory Error Policies
* \ingroup FactoryGroup
* \brief Manages the "Unknown Type" error in an object factory
*
* \class DefaultFactoryError
* \ingroup FactoryErrorPoliciesGroup
* \brief Default policy that throws an exception
*
*/
template <typename IdentifierType, class AbstractProduct>
struct DefaultFactoryError
{
struct Exception : public std::exception
{
const char* what() const throw() { return "Unknown Type"; }
};
static AbstractProduct* OnUnknownType(IdentifierType)
{
throw Exception();
}
};
#define LOKI_ENABLE_NEW_FACTORY_CODE
#ifdef LOKI_ENABLE_NEW_FACTORY_CODE
////////////////////////////////////////////////////////////////////////////////
// class template FunctorImpl
////////////////////////////////////////////////////////////////////////////////
struct FactoryImplBase
{
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
{
virtual ~FactoryImpl() {}
virtual AP* CreateObject(const Id & id ) = 0;
};
template <typename AP, typename Id, typename P1 >
struct FactoryImpl<AP,Id, Seq<P1> >
: public FactoryImplBase
{
typedef typename TypeTraits<P1>::ParameterType Parm1;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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;
virtual ~FactoryImpl() {}
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
template <typename AP, typename Id, typename P1 >
struct FactoryImpl<AP,Id, LOKI_TYPELIST_1( P1 )>
: public FactoryImplBase
{
typedef typename TypeTraits<P1>::ParameterType Parm1;
virtual ~FactoryImpl() {}
virtual AP* CreateObject(const Id& id,Parm1 ) = 0;
};
template<typename AP, typename Id, typename P1,typename P2 >
struct FactoryImpl<AP, Id, LOKI_TYPELIST_2( P1, P2 )>
: public FactoryImplBase
{
typedef typename TypeTraits<P1>::ParameterType Parm1;
typedef typename TypeTraits<P2>::ParameterType Parm2;
virtual ~FactoryImpl() {}
virtual AP* CreateObject(const Id& id,Parm1, Parm2 ) = 0;
};
template<typename AP, typename Id, typename P1,typename P2,typename P3 >
struct FactoryImpl<AP, Id, LOKI_TYPELIST_3( P1, P2, P3 )>
: public FactoryImplBase
{
typedef typename TypeTraits<P1>::ParameterType Parm1;
typedef typename TypeTraits<P2>::ParameterType Parm2;
typedef typename TypeTraits<P3>::ParameterType Parm3;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_4( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_5( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_6( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_7( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_8( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_9( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_10( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_11( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_12( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_13( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_14( 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;
virtual ~FactoryImpl() {}
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, LOKI_TYPELIST_15( 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;
virtual ~FactoryImpl() {}
virtual AP* CreateObject(const Id& id,Parm1, Parm2, Parm3, Parm4, Parm5,
Parm6, Parm7, Parm8, Parm9,Parm10,
Parm11,Parm12,Parm13,Parm14,Parm15 )
= 0;
};
#endif //LOKI_DISABLE_TYPELIST_MACROS
////////////////////////////////////////////////////////////////////////////////
/// \class Factory
///
/// \ingroup FactoryGroup
/// Implements a generic object factory.
///
/// Create functions can have up to 15 parameters.
///
/// \par Singleton lifetime when used with Loki::SingletonHolder
/// Because Factory uses internally Functors which inherits from
/// SmallObject you must use the singleton lifetime
/// \code Loki::LongevityLifetime::DieAsSmallObjectChild \endcode
/// Alternatively you could suppress for Functor the inheritance
/// from SmallObject by defining the macro:
/// \code LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT \endcode
////////////////////////////////////////////////////////////////////////////////
template
<
class AbstractProduct,
typename IdentifierType,
typename CreatorParmTList = NullType,
template<typename, class> class FactoryErrorPolicy = DefaultFactoryError
>
class Factory : public FactoryErrorPolicy<IdentifierType, AbstractProduct>
{
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;
typedef Functor<AbstractProduct*, CreatorParmTList> ProductCreator;
typedef AssocVector<IdentifierType, ProductCreator> IdToProductMap;
IdToProductMap associations_;
public:
Factory()
: associations_()
{
}
~Factory()
{
associations_.erase(associations_.begin(), associations_.end());
}
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(
typename IdToProductMap::value_type(id, creator)).second != 0;
}
bool Unregister(const IdentifierType& id)
{
return associations_.erase(id) != 0;
}
std::vector<IdentifierType> RegisteredIds()
{
std::vector<IdentifierType> ids;
for(typename IdToProductMap::iterator it = associations_.begin();
it != associations_.end(); ++it)
{
ids.push_back(it->first);
}
return ids;
}
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
template
<
class AbstractProduct,
typename IdentifierType,
typename ProductCreator = AbstractProduct* (*)(),
template<typename, class>
class FactoryErrorPolicy = DefaultFactoryError
>
class Factory
: public FactoryErrorPolicy<IdentifierType, AbstractProduct>
{
public:
bool Register(const IdentifierType& id, ProductCreator creator)
{
return associations_.insert(
typename IdToProductMap::value_type(id, creator)).second != 0;
}
bool Unregister(const IdentifierType& id)
{
return associations_.erase(id) != 0;
}
AbstractProduct* CreateObject(const IdentifierType& id)
{
typename IdToProductMap::iterator i = associations_.find(id);
if (i != associations_.end())
{
return (i->second)();
}
return this->OnUnknownType(id);
}
private:
typedef AssocVector<IdentifierType, ProductCreator> IdToProductMap;
IdToProductMap associations_;
};
#endif //#define ENABLE_NEW_FACTORY_CODE
/**
* \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.
*/
template
<
class AbstractProduct,
class ProductCreator =
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(
typename IdToProductMap::value_type(ti, creator)).second != 0;
}
bool Unregister(const TypeInfo& id)
{
return associations_.erase(id) != 0;
}
AbstractProduct* CreateObject(const AbstractProduct* model)
{
if (model == NULL)
{
return NULL;
}
typename IdToProductMap::iterator i =
associations_.find(typeid(*model));
if (i != associations_.end())
{
return (i->second)(model);
}
return this->OnUnknownType(typeid(*model));
}
private:
typedef AssocVector<TypeInfo, ProductCreator> IdToProductMap;
IdToProductMap associations_;
};
} // namespace Loki
#ifdef _MSC_VER
#pragma warning( pop )
#endif
#endif // end file guardian
|