Add dap::initialize() and terminate() functions

Can be used to explicitly control when the TypeInfo static initializers / destructors are called.
Usually not needed.

Issue: #40
This commit is contained in:
Ben Clayton
2020-06-15 17:00:50 +01:00
parent c9630a9aee
commit 7b02b9f73a
5 changed files with 221 additions and 57 deletions

View File

@@ -37,6 +37,21 @@ struct TypeInfo {
virtual void destruct(void*) const = 0;
virtual bool deserialize(const Deserializer*, void*) const = 0;
virtual bool serialize(Serializer*, const void*) const = 0;
// create() allocates and constructs the TypeInfo of type T, registers the
// pointer for deletion on cppdap library termination, and returns the pointer
// to T.
template <typename T, typename... ARGS>
static T* create(ARGS&&... args) {
auto typeinfo = new T(std::forward<ARGS>(args)...);
deleteOnExit(typeinfo);
return typeinfo;
}
private:
// deleteOnExit() ensures that the TypeInfo is destructed and deleted on
// library termination.
static void deleteOnExit(TypeInfo*);
};
} // namespace dap