ClassLibrary.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // ClassLibrary.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/ClassLibrary.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: SharedLibrary
  8. // Module: ClassLoader
  9. //
  10. // Definitions for class libraries.
  11. //
  12. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_ClassLibrary_INCLUDED
  18. #define Foundation_ClassLibrary_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/Manifest.h"
  21. #include <typeinfo>
  22. #if defined(_WIN32)
  23. #define POCO_LIBRARY_API __declspec(dllexport)
  24. #else
  25. #define POCO_LIBRARY_API
  26. #endif
  27. //
  28. // the entry points for every class library
  29. //
  30. extern "C"
  31. {
  32. bool POCO_LIBRARY_API pocoBuildManifest(Poco::ManifestBase* pManifest);
  33. void POCO_LIBRARY_API pocoInitializeLibrary();
  34. void POCO_LIBRARY_API pocoUninitializeLibrary();
  35. }
  36. //
  37. // additional support for named manifests
  38. //
  39. #define POCO_DECLARE_NAMED_MANIFEST(name) \
  40. extern "C" \
  41. { \
  42. bool POCO_LIBRARY_API POCO_JOIN(pocoBuildManifest, name)(Poco::ManifestBase* pManifest); \
  43. }
  44. //
  45. // Macros to automatically implement pocoBuildManifest
  46. //
  47. // usage:
  48. //
  49. // POCO_BEGIN_MANIFEST(MyBaseClass)
  50. // POCO_EXPORT_CLASS(MyFirstClass)
  51. // POCO_EXPORT_CLASS(MySecondClass)
  52. // ...
  53. // POCO_END_MANIFEST
  54. //
  55. #define POCO_BEGIN_MANIFEST_IMPL(fnName, base) \
  56. bool fnName(Poco::ManifestBase* pManifest_) \
  57. { \
  58. typedef base _Base; \
  59. typedef Poco::Manifest<_Base> _Manifest; \
  60. std::string requiredType(typeid(_Manifest).name()); \
  61. std::string actualType(pManifest_->className()); \
  62. if (requiredType == actualType) \
  63. { \
  64. Poco::Manifest<_Base>* pManifest = static_cast<_Manifest*>(pManifest_);
  65. #define POCO_BEGIN_MANIFEST(base) \
  66. POCO_BEGIN_MANIFEST_IMPL(pocoBuildManifest, base)
  67. #define POCO_BEGIN_NAMED_MANIFEST(name, base) \
  68. POCO_DECLARE_NAMED_MANIFEST(name) \
  69. POCO_BEGIN_MANIFEST_IMPL(POCO_JOIN(pocoBuildManifest, name), base)
  70. #define POCO_END_MANIFEST \
  71. return true; \
  72. } \
  73. else return false; \
  74. }
  75. #define POCO_EXPORT_CLASS(cls) \
  76. pManifest->insert(new Poco::MetaObject<cls, _Base>(#cls));
  77. #define POCO_EXPORT_SINGLETON(cls) \
  78. pManifest->insert(new Poco::MetaSingleton<cls, _Base>(#cls));
  79. #endif // Foundation_ClassLibrary_INCLUDED