[Spice-devel] [PATCH spice-streaming-agent 4/4] gst-plugin: reduce number of templates being used
Uri Lublin
uril at redhat.com
Thu Aug 8 14:42:31 UTC 2019
On 8/4/19 10:53 AM, Snir Sheriber wrote:
>
> On 8/1/19 7:17 PM, Frediano Ziglio wrote:
>>>> ---
>>>>
>>>> This patch is not really necessary, just a suggestion, it's a bit hacky
>>>> but would save some code.
>>>> Other options would be to use explicit template specialization or to
>>>> leave it as is.
>>>>
>>> Sure, what I don't like is that is surely not type safe, you can
>>> instantiate
>>> a GstMiniObjectUPtr of whatever, even an "int" type and compiler won't
>>> complain at all, witch is a good thing of C++.
>>> I'm thinking possible changes to this patch like traits and/or macros to
>>> declare allowed types.
>>> Certain the type is getting a bit long ("GstMiniObjectUPtr<GstSample>"),
>>> but this could be solve by typedefs (well, this was solved by using
>>> lines).
>>>
>> What about:
>>
>>
>> template <typename T>
>> struct is_gst_mini_type {
>> };
>>
>> template <typename T, typename = typename is_gst_mini_type<T>::type>
>> struct GstMiniObjectDeleter {
>> void operator()(T* p)
>> {
>> gst_mini_object_unref(GST_MINI_OBJECT_CAST(p));
>> }
>> };
>>
>> template <typename T>
>> using GstMiniObjectUPtr = std::unique_ptr<T, GstMiniObjectDeleter<T>>;
>>
>> #define DECLARE_GST_MINI_TYPE(name) \
>> template <> struct is_gst_mini_type<name> { \
>> typedef name *type; \
>> }; \
>> using name ## UPtr = GstMiniObjectUPtr<name>;
>>
>> DECLARE_GST_MINI_TYPE(GstSample)
>>
>
> Actually also the GstObjectUPtr is not really type safe
>
> I'm not sure i wouldn't prefer to just do something like this for
> simplicity:
>
> template <typename T>
> struct GstDeleter {
> void operator()(T* p)
> {
> gst_object_unref(p);
> }
> };
Can we somehow pass the unref-function in the template ?
template <typename T, function f>
struct GstDeleter {
...
Uri.
More information about the Spice-devel
mailing list