-
Notifications
You must be signed in to change notification settings - Fork 122
/
InterfaceFactory.cpp
104 lines (92 loc) · 3.07 KB
/
InterfaceFactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
//-----------------------------------------------
// Includes
//-----------------------------------------------
#include "MantidQtAPI/InterfaceFactory.h"
#include "MantidQtAPI/UserSubWindow.h"
using namespace MantidQt::API;
//*********************************************************
// UserSubWindow
//*********************************************************
//----------------------------------------
// Public member functions
//----------------------------------------
/**
* Create a raw pointer to the interface with the given name
* @param name :: The name of the interface that should have been registered into the factory
*/
UserSubWindow * UserSubWindowFactoryImpl::createUnwrapped(const std::string & name) const
{
// Try primary name as a start
UserSubWindow *window;
try
{
window = Mantid::Kernel::DynamicFactory<UserSubWindow>::createUnwrapped(name);
}
catch(Mantid::Kernel::Exception::NotFoundError&)
{
g_log.debug() << "\"" << name << "\" not registered as a real name, trying an alias.\n";
window = NULL;
}
if( !window )
{
window = createFromAlias(name);
}
if( !window )
{
g_log.error() << "UserSubWindowFactory: \""+ name + "\" is not registered as an interface name.\n";
throw Mantid::Kernel::Exception::NotFoundError("UserSubWindowFactory:"+ name + " is not registered or recognised as an alias of a known interface.\n", name);
}
return window;
}
/**
* Return the set of categories that the interface with the given name belongs to.
*
* @param name :: The name of the interface.
* @returns the set of category names if an interface with the given name has been registered,
* else an empty set.
*/
QSet<QString> UserSubWindowFactoryImpl::getInterfaceCategories(const QString & interfaceName) const
{
if( !m_categoryLookup.contains(interfaceName) )
return QSet<QString>();
return m_categoryLookup[interfaceName];
}
//----------------------------------------
// Public member functions
//----------------------------------------
/// Default constructor
UserSubWindowFactoryImpl::UserSubWindowFactoryImpl() : m_aliasLookup(), m_badAliases(), g_log(Mantid::Kernel::Logger::get("UserSubWindowFactory"))
{
}
/**
* Create a user sub window by searching for an alias name
* @param name :: The alias name to use to try and create an interface
* @returns A pointer to a created interface pointer if this alias exists and is not multiply defined
*/
UserSubWindow * UserSubWindowFactoryImpl::createFromAlias(const std::string & name) const
{
QString alias = QString::fromStdString(name);
if( m_badAliases.contains(alias) )
{
std::string error = "Alias \"" + name + "\" is defined for multiple real interfaces: \"";
QListIterator<std::string> itr(m_badAliases.value(alias));
while( itr.hasNext() )
{
error += itr.next();
if( itr.hasNext() )
{
error += ",";
}
}
g_log.error() << error << "\"\n";
return NULL;
}
if( m_aliasLookup.contains(alias) )
{
return this->createUnwrapped(m_aliasLookup.value(alias));
}
else
{
return NULL;
}
}