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