1 | #ifndef INSTANTIATOR_H_ |
---|
2 | #define INSTANTIATOR_H_ |
---|
3 | |
---|
4 | namespace Mantid { |
---|
5 | /** @class Instantiator Instantiator.h Kernel/Instantiator.h |
---|
6 | |
---|
7 | The instantiator is a generic clss for creating objects of the template type. |
---|
8 | |
---|
9 | @author Nick Draper, Tessella Support Services plc |
---|
10 | @date 10/10/2007 |
---|
11 | |
---|
12 | Copyright © 2007 ???RAL??? |
---|
13 | |
---|
14 | This file is part of Mantid. |
---|
15 | |
---|
16 | Mantid is free software; you can redistribute it and/or modify |
---|
17 | it under the terms of the GNU General Public License as published by |
---|
18 | the Free Software Foundation; either version 3 of the License, or |
---|
19 | (at your option) any later version. |
---|
20 | |
---|
21 | Mantid is distributed in the hope that it will be useful, |
---|
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | GNU General Public License for more details. |
---|
25 | |
---|
26 | You should have received a copy of the GNU General Public License |
---|
27 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
28 | |
---|
29 | File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> |
---|
30 | */ |
---|
31 | template <class Base> |
---|
32 | class AbstractInstantiator |
---|
33 | /// The common base class for all Instantiator instantiations. |
---|
34 | /// Used by DynamicFactory. |
---|
35 | { |
---|
36 | public: |
---|
37 | AbstractInstantiator() |
---|
38 | /// Creates the AbstractInstantiator. |
---|
39 | { |
---|
40 | } |
---|
41 | |
---|
42 | virtual ~AbstractInstantiator() |
---|
43 | /// Destroys the AbstractInstantiator. |
---|
44 | { |
---|
45 | } |
---|
46 | |
---|
47 | virtual Base* createInstance() const = 0; |
---|
48 | /// Creates an instance of a concrete subclass of Base. |
---|
49 | |
---|
50 | private: |
---|
51 | AbstractInstantiator(const AbstractInstantiator&); |
---|
52 | AbstractInstantiator& operator = (const AbstractInstantiator&); |
---|
53 | }; |
---|
54 | |
---|
55 | |
---|
56 | template <class C, class Base> |
---|
57 | class Instantiator: public AbstractInstantiator<Base> |
---|
58 | /// A template class for the easy instantiation of |
---|
59 | /// instantiators. |
---|
60 | /// |
---|
61 | /// For the Instantiator to work, the class of which |
---|
62 | /// instances are to be instantiated must have a no-argument |
---|
63 | /// constructor. |
---|
64 | { |
---|
65 | public: |
---|
66 | Instantiator() |
---|
67 | /// Creates the Instantiator. |
---|
68 | { |
---|
69 | } |
---|
70 | |
---|
71 | virtual ~Instantiator() |
---|
72 | /// Destroys the Instantiator. |
---|
73 | { |
---|
74 | } |
---|
75 | |
---|
76 | Base* createInstance() const |
---|
77 | { |
---|
78 | return new C; |
---|
79 | } |
---|
80 | }; |
---|
81 | |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | #endif // INSTANTIATOR_H_ |
---|