Add missing instantion for identity_traits<std::mutex>, refactor code shared with fstream identity

develop
lethosor 2023-05-28 13:07:21 -04:00
parent 7c4d9364a2
commit 6fbb22e912
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 12 additions and 7 deletions

@ -17,6 +17,9 @@ namespace df {
category##_identity<type> identity_traits<type>::identity(name); category##_identity<type> identity_traits<type>::identity(name);
#define INTEGER_IDENTITY_TRAITS(type, name) NUMBER_IDENTITY_TRAITS(integer, type, name) #define INTEGER_IDENTITY_TRAITS(type, name) NUMBER_IDENTITY_TRAITS(integer, type, name)
#define FLOAT_IDENTITY_TRAITS(type) NUMBER_IDENTITY_TRAITS(float, type, #type) #define FLOAT_IDENTITY_TRAITS(type) NUMBER_IDENTITY_TRAITS(float, type, #type)
#define OPAQUE_IDENTITY_TRAITS_NAME(type, name) \
opaque_identity identity_traits<type>::identity(sizeof(type), allocator_noassign_fn<type>, name)
#define STL_OPAQUE_IDENTITY_TRAITS(type) OPAQUE_IDENTITY_TRAITS_NAME(std::type, #type)
#ifndef STATIC_FIELDS_GROUP #ifndef STATIC_FIELDS_GROUP
INTEGER_IDENTITY_TRAITS(char, "char"); INTEGER_IDENTITY_TRAITS(char, "char");
@ -42,13 +45,8 @@ namespace df {
stl_bit_vector_identity identity_traits<std::vector<bool> >::identity; stl_bit_vector_identity identity_traits<std::vector<bool> >::identity;
bit_array_identity identity_traits<BitArray<int> >::identity; bit_array_identity identity_traits<BitArray<int> >::identity;
static void *fstream_allocator_fn(void *out, const void *in) { STL_OPAQUE_IDENTITY_TRAITS(fstream);
if (out) { /* *(T*)out = *(const T*)in;*/ return NULL; } STL_OPAQUE_IDENTITY_TRAITS(mutex);
else if (in) { delete (std::fstream*)in; return (std::fstream*)in; }
else return new std::fstream();
}
opaque_identity identity_traits<std::fstream>::identity(
sizeof(std::fstream), fstream_allocator_fn, "fstream");
buffer_container_identity buffer_container_identity::base_instance; buffer_container_identity buffer_container_identity::base_instance;
#endif #endif

@ -528,6 +528,13 @@ namespace df
else return new T(); else return new T();
} }
template<class T>
void *allocator_noassign_fn(void *out, const void *in) {
if (out) { return NULL; }
else if (in) { delete (T*)in; return (T*)in; }
else return new T();
}
template<class T> template<class T>
struct identity_traits { struct identity_traits {
static compound_identity *get() { return &T::_identity; } static compound_identity *get() { return &T::_identity; }