[vlc-commits] Instance: Add missing pointer management & simplify existing ones

Hugo Beauzée-Luyssen git at videolan.org
Mon May 18 00:26:08 CEST 2015


libvlcpp | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu May  7 01:32:46 2015 +0200| [a05b6942a89a90839ff6c8b7bba3d6cd120785c2] | committer: Hugo Beauzée-Luyssen

Instance: Add missing pointer management & simplify existing ones

The lambda was unnecessary overhead since we can easily provide a
function pointer instead

> http://git.videolan.org/gitweb.cgi/libvlcpp.git/?a=commit;h=a05b6942a89a90839ff6c8b7bba3d6cd120785c2
---

 vlcpp/Instance.hpp |   30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/vlcpp/Instance.hpp b/vlcpp/Instance.hpp
index 57299fb..0ba78e5 100644
--- a/vlcpp/Instance.hpp
+++ b/vlcpp/Instance.hpp
@@ -225,8 +225,8 @@ public:
      */
     std::vector<ModuleDescription> audioFilterList()
     {
-        auto releaser = [](libvlc_module_description_t* ptr) { libvlc_module_description_list_release(ptr); };
-        auto ptr = std::unique_ptr<libvlc_module_description_t, decltype(releaser)>( libvlc_audio_filter_list_get(*this), releaser );
+        std::unique_ptr<libvlc_module_description_t, decltype(&libvlc_module_description_list_release)>
+                ptr( libvlc_audio_filter_list_get(*this), libvlc_module_description_list_release );
         if ( ptr == nullptr )
             return {};
         libvlc_module_description_t* p = ptr.get();
@@ -247,8 +247,8 @@ public:
      */
     std::vector<ModuleDescription> videoFilterList()
     {
-        auto releaser = [](libvlc_module_description_t* ptr) { libvlc_module_description_list_release(ptr); };
-        auto ptr = std::unique_ptr<libvlc_module_description_t, decltype(releaser)>( libvlc_video_filter_list_get(*this), releaser );
+        std::unique_ptr<libvlc_module_description_t, decltype(&libvlc_module_description_list_release)>
+                ptr( libvlc_video_filter_list_get(*this), &libvlc_module_description_list_release );
         if ( ptr == nullptr )
             return {};
         libvlc_module_description_t* p = ptr.get();
@@ -268,17 +268,18 @@ public:
      */
     std::vector<AudioOutputDescription> audioOutputList()
     {
-        libvlc_audio_output_t* result = libvlc_audio_output_list_get(*this);
+        std::unique_ptr<libvlc_audio_output_t, decltype(&libvlc_audio_output_list_release)>
+                result( libvlc_audio_output_list_get(*this), libvlc_audio_output_list_release );
+        if ( result == nullptr )
+            return {};
         std::vector<AudioOutputDescription> res;
-        if ( result == NULL )
-            return res;
-        libvlc_audio_output_t* p = result;
+
+        libvlc_audio_output_t* p = result.get();
         while ( p != NULL )
         {
             res.emplace_back( p );
             p = p->p_next;
         }
-        libvlc_audio_output_list_release(result);
         return res;
     }
 
@@ -306,13 +307,14 @@ public:
      */
     std::vector<AudioOutputDeviceDescription> audioOutputDeviceList(const std::string& aout)
     {
-        libvlc_audio_output_device_t* devices = libvlc_audio_output_device_list_get( *this, aout.c_str() );
+        std::unique_ptr<libvlc_audio_output_device_t, decltype(&libvlc_audio_output_device_list_release)>
+                devices(  libvlc_audio_output_device_list_get( *this, aout.c_str() ), libvlc_audio_output_device_list_release );
+        if ( devices == nullptr )
+            return {};
         std::vector<AudioOutputDeviceDescription> res;
-        if ( devices == NULL )
-            return res;
-        for ( libvlc_audio_output_device_t* p = devices; p != NULL; p = p->p_next )
+
+        for ( auto p = devices.get(); p != nullptr; p = p->p_next )
             res.emplace_back( p );
-        libvlc_audio_output_device_list_release( devices );
         return res;
     }
 



More information about the vlc-commits mailing list