1//
2// Instantiator.h
3//
4// Library: Foundation
5// Package: Core
6// Module: Instantiator
7//
8// Definition of the Instantiator class.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_Instantiator_INCLUDED
18#define Foundation_Instantiator_INCLUDED
19
20
21#include "Poco/Foundation.h"
22
23
24namespace Poco {
25
26
27template <class Base>
28class AbstractInstantiator
29 /// The common base class for all Instantiator instantiations.
30 /// Used by DynamicFactory.
31{
32public:
33 AbstractInstantiator()
34 /// Creates the AbstractInstantiator.
35 {
36 }
37
38 virtual ~AbstractInstantiator()
39 /// Destroys the AbstractInstantiator.
40 {
41 }
42
43 virtual Base* createInstance() const = 0;
44 /// Creates an instance of a concrete subclass of Base.
45
46private:
47 AbstractInstantiator(const AbstractInstantiator&);
48 AbstractInstantiator& operator = (const AbstractInstantiator&);
49};
50
51
52template <class C, class Base>
53class Instantiator: public AbstractInstantiator<Base>
54 /// A template class for the easy instantiation of
55 /// instantiators.
56 ///
57 /// For the Instantiator to work, the class of which
58 /// instances are to be instantiated must have a no-argument
59 /// constructor.
60{
61public:
62 Instantiator()
63 /// Creates the Instantiator.
64 {
65 }
66
67 virtual ~Instantiator()
68 /// Destroys the Instantiator.
69 {
70 }
71
72 Base* createInstance() const
73 {
74 return new C;
75 }
76};
77
78
79} // namespace Poco
80
81
82#endif // Foundation_Instantiator_INCLUDED
83