Re: [PATCH spice-streaming-agent 4/4] gst-plugin: reduce number of templates being used

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]