ctkAbstractLibraryFactory.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 
00021 #ifndef __ctkAbstractLibraryFactory_h
00022 #define __ctkAbstractLibraryFactory_h
00023 
00024 // Qt includes
00025 #include <QFileInfo>
00026 #include <QLibrary>
00027 #include <QStringList>
00028 
00029 // CTK includes
00030 #include "ctkAbstractFactory.h"
00031 
00032 //----------------------------------------------------------------------------
00033 template<typename BaseClassType>
00034 class ctkFactoryLibraryItem : public ctkAbstractFactoryItem<BaseClassType>
00035 {
00036 protected:
00037   typedef typename QHash<QString, void*>::const_iterator ConstIterator;
00038   typedef typename QHash<QString, void*>::iterator       Iterator;
00039 
00040 public:
00041   explicit ctkFactoryLibraryItem(const QString& key, const QString& path);
00042   virtual bool load();
00043   QString path()const;
00044   virtual QString loadErrorString()const;
00045 
00048   void setSymbols(const QStringList& symbols);
00049 
00054   bool resolve();
00055   
00058   void* symbolAddress(const QString& symbol)const;
00059 
00060 private:
00061   QLibrary              Library;
00062   QString               Path;
00063   QHash<QString, void*> ResolvedSymbols;
00064   QStringList           Symbols;
00065 };
00066 
00067 //----------------------------------------------------------------------------
00068 template<typename BaseClassType, typename FactoryItemType>
00069 class ctkAbstractLibraryFactory : public ctkAbstractFactory<BaseClassType>
00070 {
00071 public:
00074   explicit ctkAbstractLibraryFactory();
00075   virtual ~ctkAbstractLibraryFactory();
00076 
00079   void setSymbols(const QStringList& symbols);
00080 
00084   virtual QString fileNameToKey(const QString& fileName);
00085   
00090   virtual bool registerLibrary(const QFileInfo& file, QString& key);
00091 
00092 private:
00093   ctkAbstractLibraryFactory(const ctkAbstractLibraryFactory &);  
00094   void operator=(const ctkAbstractLibraryFactory&); 
00095 
00096   QStringList Symbols;
00097 };
00098 
00099 #include "ctkAbstractLibraryFactory.tpp"
00100 
00101 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1