GenericFactory.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_GenericFactory_h
  6. #define mozilla_GenericFactory_h
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/Module.h"
  9. namespace mozilla {
  10. /**
  11. * A generic factory which uses a constructor function to create instances.
  12. * This class is intended for use by the component manager and the generic
  13. * module.
  14. */
  15. class GenericFactory final : public nsIFactory
  16. {
  17. ~GenericFactory() {}
  18. public:
  19. typedef Module::ConstructorProcPtr ConstructorProcPtr;
  20. NS_DECL_THREADSAFE_ISUPPORTS
  21. NS_DECL_NSIFACTORY
  22. explicit GenericFactory(ConstructorProcPtr aCtor)
  23. : mCtor(aCtor)
  24. {
  25. NS_ASSERTION(mCtor, "GenericFactory with no constructor");
  26. }
  27. private:
  28. ConstructorProcPtr mCtor;
  29. };
  30. } // namespace mozilla
  31. #endif // mozilla_GenericFactory_h