improve plugin facing api with c++ helpers

This commit is contained in:
2024-01-18 18:23:24 +01:00
parent 87b3d15a2b
commit 9c54a50810
3 changed files with 90 additions and 23 deletions

View File

@@ -21,29 +21,7 @@ void g_provideInstance__internal(const char* id, const char* version, const char
} // extern C
namespace internal {
template<typename T>
class g_type_version {
typedef char yes[1];
typedef char no [2];
template<typename C> static yes& test_version(decltype(&C::version));
template<typename C> static no& test_version(...);
static bool const has_version = sizeof(test_version<T>(nullptr)) == sizeof(yes);
static constexpr const char* get_version(void) {
if constexpr (has_version) {
return T::version;
} else {
return "UNK"; // default version
}
}
public:
static constexpr const char* version = get_version();
};
} // internal
#include "./version_helper.inl"
// templated helper, use or make sure vtable is right
template<typename T>