Newer
Older
Russell Taylor
committed
#ifndef MANTID_KERNEL_ALGORITHMMANAGER_H_
#define MANTID_KERNEL_ALGORITHMMANAGER_H_
Dickon Champion
committed
/* Used to register classes into the factory. creates a global object in an
* anonymous namespace. The object itself does nothing, but the comma operator
* is used in the call to its constructor to effect a call to the factory's
* subscribe method.
*/
Russell Taylor
committed
#define DECLARE_NAMESPACED_ALGORITHM(ns, classname) \
namespace { \
Mantid::Kernel::RegistrationHelper register_alg_##classname( \
((Mantid::Kernel::AlgorithmManager::Instance()->subscribe<ns::classname>(#classname)) \
, 0)); \
}
Dickon Champion
committed
#define DECLARE_ALGORITHM(classname) \
namespace { \
Russell Taylor
committed
Mantid::Kernel::RegistrationHelper register_alg_##classname( \
((Mantid::Kernel::AlgorithmManager::Instance()->subscribe<classname>(#classname)) \
Dickon Champion
committed
, 0)); \
}
Russell Taylor
committed
Dickon Champion
committed
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "AlgorithmFactory.h"
#include <vector>
Russell Taylor
committed
Dickon Champion
committed
namespace Mantid
{
Russell Taylor
committed
namespace Kernel
{
Dickon Champion
committed
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
/** @class AlgorithmManager AlgorithmManager.h Kernel/AlgorithmManager.h
The Algorithm Manager class is responsible for controlling algorithm
instances. It provides a facade for the factory, it initializes and
finalizes algorithms.
@author Dickon Champion, ISIS, RAL
@date 30/10/2007
Copyright © 2007 ???RAL???
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
*/
class DLLExport AlgorithmManager : public AlgorithmFactory
{
public:
/** A static method which retrieves the single instance of the Algorithm Manager
*
* @returns A pointer to the Algorithm Manager instance
*/
static AlgorithmManager* Instance();
/** Creates an instance of an algorithm
*
* @param algName The name of the algorithm required
* @return A pointer to the created algorithm
*
* @throw runtime_error Thrown if algorithm requested is not registered
*/
IAlgorithm* createAlgorithm(const std::string& algName);
/// finalizes and deletes all registered algorithms
void clear();
private:
/// Private Constructor for singleton class
AlgorithmManager();
/** Private destructor
* Prevents client from calling 'delete' on the pointer handed
* out by Instance
*/
virtual ~AlgorithmManager();
///static reference to the logger class
static Logger& g_log;
/// internal counter of registered algorithms
static int m_no_of_alg;
/// vector containing pointers to registered algorithms
std::vector<IAlgorithm*> list;
/// Pointer to the Algorithm Manager instance
static AlgorithmManager* m_instance;
};
Russell Taylor
committed
} // namespace Kernel
Dickon Champion
committed
} //Namespace Mantid
Russell Taylor
committed
#endif /* MANTID_KERNEL_ALGORITHMMANAGER_H_ */