瀏覽代碼

ENH: Add path(itemKey) method to ctkAbstractFactory

This method allows to return the path associated with an item registered
in the factory.
It could be either the path of a library or a plugin. (By default, it will
return an empty string if the factory is ctkAbstract(QObject|Object}Factory)
Jean-Christophe Fillion-Robin 14 年之前
父節點
當前提交
e61c2fbaf1

+ 14 - 16
Libs/Core/ctkAbstractFactory.h

@@ -64,9 +64,9 @@ private:
 };
 
 //----------------------------------------------------------------------------
-/// ctkAbstractFactory is the base class of all the factory where items need
+/// \brief ctkAbstractFactory is the base class of all the factory where items need
 /// to be registered before being instantiated.
-/// ctkAbstractFactory contains a collection of ctkAbstractFactoryItems that
+/// \paragraph ctkAbstractFactory contains a collection of ctkAbstractFactoryItems that
 /// are uniquely identifyed by a key. Subclasses of ctkAbstractFactory are
 /// responsible for populating the list of ctkAbstractFactoryItems.
 /// BaseClassType could be any type (most probably a QObject) 
@@ -74,44 +74,42 @@ template<typename BaseClassType>
 class ctkAbstractFactory
 {
 public:
-  /// 
+
   /// Constructor/Desctructor
   explicit ctkAbstractFactory();
   virtual ~ctkAbstractFactory();
   virtual void printAdditionalInfo();
 
-  /// 
-  /// Create an instance of the object. The item corresponding to the key
-  /// should have been registered before.
+  /// \brief Create an instance of the object.
+  /// The item corresponding to the key should have been registered before.
   virtual BaseClassType * instantiate(const QString& itemKey);
 
-  /// 
-  /// Uninstanciate the object. Do nothing if the item given by the key has
-  /// not be instantiated nor registered.
+  /// \brief Uninstanciate the object.
+  /// Do nothing if the item given by the key has not be instantiated nor registered.
   void uninstantiate(const QString& itemKey);
 
-  /// 
+  /// \brief Get path associated with the item identified by \a itemKey
+  /// Should be overloaded in subclasse
+  virtual QString path(const QString& itemKey){ Q_UNUSED(itemKey); return QString(); }
+
   /// Get list of all registered item keys.
   QStringList keys() const;
 
-  /// 
-  /// Register items with the factory
+  /// \brief Register items with the factory
   /// Method provided for convenience - Should be overloaded in subclasse
   virtual void registerItems(){}
 
-  /// Enabled verbose output
+  /// \brief Enabled verbose output
   /// Warning and error message will be printed to standard outputs
   void setVerbose(bool value);
   bool verbose()const;
 
 protected:
 
-  /// 
-  /// Call the load method associated with the item.
+  /// \brief Call the load method associated with the item.
   /// If succesfully loaded, add it to the internal map.
   bool registerItem(const QString& key, const QSharedPointer<ctkAbstractFactoryItem<BaseClassType> > & item);
 
-  /// 
   /// Get a Factory item given its itemKey. Return 0 if any.
   ctkAbstractFactoryItem<BaseClassType> * item(const QString& itemKey)const;
 

+ 7 - 7
Libs/Core/ctkAbstractLibraryFactory.h

@@ -49,8 +49,8 @@ public:
   void setSymbols(const QStringList& symbols);
 
   /// 
-  /// Resolve symbols
-  /// Note that the function will return False if it fails to resolve on
+  /// \brief Resolve symbols
+  /// \note The function will return False if it fails to resolve one
   /// of the required symbols set using ::setSymbols
   bool resolve();
   
@@ -75,20 +75,20 @@ public:
   explicit ctkAbstractLibraryFactory();
   virtual ~ctkAbstractLibraryFactory();
 
-  /// 
   /// Set the list of symbols
   void setSymbols(const QStringList& symbols);
   
-  /// 
-  /// Register a plugin in the factory
+  /// \brief Register a plugin in the factory
   /// The parameter \a key must be unique
   bool registerLibrary(const QString& key, const QFileInfo& file);
 
-  /// 
-  /// Utility function to register a QLibrary
+  /// \brief Utility function to register a QLibrary
   /// The parameter \a key must be unique
   bool registerQLibrary(const QString& key, const QFileInfo& file);
 
+  /// Get path associated with the library identified by \a key
+  virtual QString path(const QString& key);
+
 protected:
   virtual ctkFactoryLibraryItem<BaseClassType>* createFactoryLibraryItem(
     const QFileInfo& library)const;

+ 11 - 1
Libs/Core/ctkAbstractLibraryFactory.tpp

@@ -22,7 +22,7 @@
 #define __ctkAbstractLibraryFactory_tpp
 
 // CTK includes
-#include "ctkAbstractFactory.h"
+#include "ctkAbstractLibraryFactory.h"
 
 //----------------------------------------------------------------------------
 // ctkFactoryLibraryItem methods
@@ -178,6 +178,16 @@ bool ctkAbstractLibraryFactory<BaseClassType>::registerQLibrary(
   return this->registerLibrary(key, file);
 }
 
+//----------------------------------------------------------------------------
+template<typename BaseClassType>
+QString ctkAbstractLibraryFactory<BaseClassType>::path(const QString& key)
+{
+  ctkFactoryLibraryItem<BaseClassType>* _item =
+      dynamic_cast<ctkFactoryLibraryItem<BaseClassType>*>(this->item(key));
+  Q_ASSERT(_item);
+  return _item->path();
+}
+
 //-----------------------------------------------------------------------------
 template<typename BaseClassType>
 ctkFactoryLibraryItem<BaseClassType>* ctkAbstractLibraryFactory<BaseClassType>::

+ 1 - 1
Libs/Core/ctkAbstractObjectFactory.h

@@ -58,7 +58,7 @@ class ctkAbstractObjectFactory : public ctkAbstractFactory<BaseClassType>
 {
 public:
   explicit ctkAbstractObjectFactory();
-  /// 
+
   /// Register an object in the factory
   template<typename ClassType>
   bool registerObject(const QString& key);

+ 3 - 3
Libs/Core/ctkAbstractPluginFactory.h

@@ -54,12 +54,12 @@ public:
   /// Constructor
   explicit ctkAbstractPluginFactory();
 
-  ///
   /// Register a plugin in the factory
-  /// The parameter \a key passed by reference will be updated with the
-  /// associated object name obtained using ::fileNameToKey()
   virtual bool registerLibrary(const QString& key, const QFileInfo& file);
 
+  /// Get path associated with the plugin identified by \a key
+  virtual QString path(const QString& key);
+
 protected:
   virtual ctkAbstractFactoryItem<BaseClassType>* createFactoryPluginItem(const QFileInfo& file);
 

+ 10 - 0
Libs/Core/ctkAbstractPluginFactory.tpp

@@ -121,6 +121,16 @@ bool ctkAbstractPluginFactory<BaseClassType>::registerLibrary(const QString& key
 
 //----------------------------------------------------------------------------
 template<typename BaseClassType>
+QString ctkAbstractPluginFactory<BaseClassType>::path(const QString& key)
+{
+  ctkFactoryPluginItem<BaseClassType>* _item =
+      dynamic_cast<ctkFactoryPluginItem<BaseClassType>*>(this->item(key));
+  Q_ASSERT(_item);
+  return _item->path();
+}
+
+//----------------------------------------------------------------------------
+template<typename BaseClassType>
 ctkAbstractFactoryItem<BaseClassType>* ctkAbstractPluginFactory<BaseClassType>::createFactoryPluginItem(const QFileInfo& file)
 {
   return new ctkFactoryPluginItem<BaseClassType>(file.filePath());

+ 3 - 7
Libs/Core/ctkAbstractQObjectFactory.h

@@ -32,26 +32,22 @@ template<typename BaseClassType>
 class ctkAbstractQObjectFactory : public ctkAbstractObjectFactory<BaseClassType>
 {
 public:
-  /// 
+
   /// Constructor/Desctructor
   explicit ctkAbstractQObjectFactory();
   virtual ~ctkAbstractQObjectFactory();
 
-  /// 
   /// Create an instance of the object identified by \a itemKey
   virtual BaseClassType * instantiate(const QString& itemKey);
 
-  /// 
   /// Uninstanciate the object identified by \a itemKey
   virtual void uninstantiate(const QString& itemKey);
 
-  ///
-  /// Return a name allowing to uniquely identify the QObject
+  /// \brief Return a name allowing to uniquely identify the QObject
   /// By default, it return \a objectName obtained using staticMetaObject.className()
   virtual QString objectNameToKey(const QString& objectName);
   
-  /// 
-  /// Register an object in the factory
+  /// \brief Register an object in the factory
   /// The parameter \a key passed by reference will be updated with the
   /// associated object name obtained using ::objectNameToKey()
   template<typename ClassType>