Ticket #32: Instantiator.h

File Instantiator.h, 2.2 KB (added by Nick Draper, 13 years ago)

instantiator code

Line 
1#ifndef INSTANTIATOR_H_
2#define INSTANTIATOR_H_
3
4namespace 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*/
31template <class Base>
32class AbstractInstantiator
33        /// The common base class for all Instantiator instantiations.
34        /// Used by DynamicFactory.
35{
36public:
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
50private:
51        AbstractInstantiator(const AbstractInstantiator&);
52        AbstractInstantiator& operator = (const AbstractInstantiator&);
53};
54
55
56template <class C, class Base>
57class 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{
65public:
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_