CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkAbstractLibraryFactory.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkAbstractLibraryFactory_h
22 #define __ctkAbstractLibraryFactory_h
23 
24 // Qt includes
25 #include <QFileInfo>
26 #include <QLibrary>
27 #include <QStringList>
28 
29 // CTK includes
31 
32 //----------------------------------------------------------------------------
34 template<typename BaseClassType>
36 {
37 
38 public:
39 
40 #if QT_VERSION < 0x50000
41  typedef void* SymbolAddressType;
42 #else
43  typedef QFunctionPointer SymbolAddressType;
44 #endif
45 
46 protected:
49 
50 public:
51  //explicit ctkFactoryLibraryItem(const QString& path);
52 
53  virtual bool load();
54 
57  void setSymbols(const QStringList& symbols);
58 
60  void setLoadHints(QLibrary::LoadHints hints);
61 
66  bool resolve();
67 
70  SymbolAddressType symbolAddress(const QString& symbol)const;
71 
72 protected:
73  mutable QLibrary Library;
75  QStringList Symbols;
76 };
77 
78 //----------------------------------------------------------------------------
80 template<typename BaseClassType>
82  : public ctkAbstractFileBasedFactory<BaseClassType>
83 {
84 public:
86  void setSymbols(const QStringList& symbols);
87 
88 protected:
89  virtual bool isValidFile(const QFileInfo& file)const;
91 
92 private:
93  QStringList Symbols;
94 };
95 
96 #include "ctkAbstractLibraryFactory.tpp"
97 
98 #endif
ctkAbstractFactoryItem< BaseClassType > * item(const QString &itemKey) const
Get a Factory item given its itemKey. Return 0 if any.
virtual bool isValidFile(const QFileInfo &file) const
void setSymbols(const QStringList &symbols)
Set the list of symbols.
virtual void initItem(ctkAbstractFactoryItem< BaseClassType > *item)
void setSymbols(const QStringList &symbols)
Set list of required symbols.
bool resolve()
Resolve symbols.
SymbolAddressType symbolAddress(const QString &symbol) const
Get symbol address.
QHash< QString, SymbolAddressType > ResolvedSymbols
QHash< QString, SymbolAddressType >::const_iterator ConstIterator
virtual bool load()
QHash< QString, SymbolAddressType >::iterator Iterator
void setLoadHints(QLibrary::LoadHints hints)
Set lookup hints for symbol resolution. See QLibrary documentation.