// Factory.h // // Defines an interface for generic object factories. // // // IFactory, IFactory1, .. IFactory5 pass 0, 1, ... 5 parameters respectively // to the sorce class'es constructor. // // Factory* are the actual IFactory implementations. // // Parameters: // T the type of the destination class // S the type of the source class // P* the types of the constructor parameters // template class IFactory { public: virtual Ptr create()=0; }; template class IFactory1 { public: virtual Ptr create(P1)=0; }; template class IFactory2 { public: virtual Ptr create(P1, P2)=0; }; template class IFactory3 { public: virtual Ptr create(P1, P2, P3)=0; }; template class IFactory4 { public: virtual Ptr create(P1, P2, P3, P4)=0; }; template class IFactory5 { public: virtual Ptr create(P1, P2, P3, P4, P5)=0; }; template class Factory : public IFactory { public: virtual Ptr create() { return new S; }; }; template class Factory1 : public IFactory1 { public: virtual Ptr create(P1 p1) { return new S(p1); }; }; template class Factory2 : public IFactory2 { public: virtual Ptr create(P1 p1, P2 p2) { return new S(p1, p2); }; }; template class Factory3 : public IFactory3 { public: virtual Ptr create(P1 p1, P2 p2, P3 p3) { return new S(p1, p2, p3); }; }; template class Factory4 : public IFactory4 { public: virtual Ptr create(P1 p1, P2 p2, P3 p3, P4 p4) { return new S(p1, p2, p3, p4); }; }; template class Factory5 : public IFactory5 { public: virtual Ptr create(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { return new S(p1, p2, p3, p4, p5); }; };