TSingleFactory.h
Go to the documentation of this file.
1 #ifndef istd_TSingleFactory_included
2 #define istd_TSingleFactory_included
3 
4 
5 // Qt includes
6 #include <QtCore/QByteArray>
7 
8 // ACF includes
9 #include <istd/TIFactory.h>
10 
11 
12 namespace istd
13 {
14 
15 
19 template <class Interface, class Implementation>
20 class TSingleFactory: virtual public TIFactory<Interface>
21 {
22 public:
23  typedef Implementation ImplementationType;
25 
26  explicit TSingleFactory(const QByteArray& keyId);
27 
28  // reimplemented (istd::IFactoryInfo)
29  virtual IFactoryInfo::KeyList GetFactoryKeys() const;
30 
31  // reimplemented (istd::TIFactory)
32  virtual Interface* CreateInstance(const QByteArray& keyId = "") const;
33 
34 private:
35  QByteArray m_keyId;
36 };
37 
38 
39 // public methods
40 
41 template <class Interface, class Implementation>
43 : m_keyId(keyId)
44 {
45 
46 }
47 
48 
49 // reimplemented (istd::TIFactory)
50 
51 template <class Interface, class Implementation>
53 {
54  typename TIFactory<Interface>::KeyList retVal;
55 
56  retVal.insert(m_keyId);
57 
58  return retVal;
59 }
60 
61 
62 template <class Interface, class Implementation>
63 Interface* TSingleFactory<Interface, Implementation>::CreateInstance(const QByteArray& keyId) const
64 {
65  if (keyId.isEmpty() || (keyId == m_keyId)){
66  return new Implementation;
67  }
68 
69  return NULL;
70 }
71 
72 
73 } // namespace istd
74 
75 
76 #endif // !istd_TSingleFactory_included
77 
78 
QSet< QByteArray > KeyList
Definition: IFactoryInfo.h:23
Implementation ImplementationType
virtual IFactoryInfo::KeyList GetFactoryKeys() const
Returns all posible keys for this factory.
virtual Interface * CreateInstance(const QByteArray &keyId="") const
Create an instance of the object, mapped to the keyId keyId.
TIFactory< Interface > FactoryInterface
Generic interface for a factory.
Definition: TIFactory.h:17
Template based object factory interface.
#define NULL
Definition: istd.h:64
TSingleFactory(const QByteArray &keyId)

© 2007-2017 Witold Gantzke and Kirill Lepskiy