ccExternalFactory.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_EXTERNAL_FACTORY_HEADER
  18. #define CC_EXTERNAL_FACTORY_HEADER
  19. //Local
  20. #include "ccHObject.h"
  21. //Qt
  22. #include <QMap>
  23. /** Provides new objects with an external factory
  24. * This is intended to be used into plugins.
  25. * Each plugin may define a new factory by subclassing this class.
  26. * Factories are then stored in a unique container and used to load custom types.
  27. **/
  28. class QCC_DB_LIB_API ccExternalFactory
  29. {
  30. public:
  31. //! A convenience holder for all factories
  32. class QCC_DB_LIB_API Container
  33. {
  34. public:
  35. //! Default constructor
  36. Container() {}
  37. //! Returns factory using its (unique) name as key
  38. /** \param factoryName unique name
  39. \return corresponding factory (or null pointer if not found)
  40. **/
  41. ccExternalFactory* getFactoryByName(const QString& factoryName) const;
  42. //! Adds a new factory to the container
  43. /** Any previously existing factory with the same name will be overwritten.
  44. **/
  45. void addFactory(ccExternalFactory* factory);
  46. //! Shared pointer type
  47. typedef QSharedPointer<Container> Shared;
  48. //! Returns the unique static instance of the external factories container
  49. static Container::Shared GetUniqueInstance();
  50. //! Sets the unique static instance of the external factories container
  51. /** A default static instance is provided for convenience but another user defined instance
  52. can be declared here instead.
  53. **/
  54. static void SetUniqueInstance(Container::Shared container);
  55. protected:
  56. //! Set of factories
  57. QMap< QString, ccExternalFactory* > m_factories;
  58. };
  59. //! Default constructor
  60. /** \param factoryName unique name
  61. **/
  62. ccExternalFactory(QString factoryName);
  63. //! Returns the (unique) name of the factory
  64. inline QString getFactoryName() const {return m_factoryName; }
  65. //! Custom object building method
  66. /** Similar to ccHObject::New but virtual so as to be reimplemented by the plugin.
  67. \param metaName custom object name
  68. \return corresponding instance (or 0 if an error occurred)
  69. **/
  70. virtual ccHObject* buildObject(const QString& metaName) = 0;
  71. protected:
  72. //! Name
  73. QString m_factoryName;
  74. };
  75. #endif // CC_EXTERNAL_FACTORY_HEADER