[vlc-devel] commit: activex plugin: Replace duplicated get_object methods with calls to (JP Dinger )

git version control git at videolan.org
Wed Jan 20 10:46:41 CET 2010


vlc | branch: master | JP Dinger <jpd at m2x.nl> | Wed Jan 20 10:28:03 2010 +0100| [c7acc9f3f98ce182a1df10c730f5e1d2b2e73749] | committer: JP Dinger 

activex plugin: Replace duplicated get_object methods with calls to
a templated helper. The holder variables are not otherwise used so a
pointer to the (virtual) interface classes works fine.

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

 projects/activex/vlccontrol2.cpp |  117 ++++++++++----------------------------
 projects/activex/vlccontrol2.h   |   26 ++++----
 2 files changed, 43 insertions(+), 100 deletions(-)

diff --git a/projects/activex/vlccontrol2.cpp b/projects/activex/vlccontrol2.cpp
index 60006a7..ca3ab5f 100644
--- a/projects/activex/vlccontrol2.cpp
+++ b/projects/activex/vlccontrol2.cpp
@@ -76,6 +76,21 @@ BIND_INTERFACE( VLCSubtitle )
 
 #undef  BIND_INTERFACE
 
+template<class I> static inline
+HRESULT object_get(I **dst, I *src)
+{
+    if( NULL == dst )
+        return E_POINTER;
+
+    *dst = src;
+    if( NULL != src )
+    {
+        src->AddRef();
+        return NOERROR;
+    }
+    return E_OUTOFMEMORY;
+}
+
 // ---------
 
 
@@ -1663,30 +1678,12 @@ STDMETHODIMP VLCVideo::toggleTeletext()
 
 STDMETHODIMP VLCVideo::get_marquee(IVLCMarquee** obj)
 {
-    if( NULL == obj )
-        return E_POINTER;
-
-    *obj = _p_vlcmarquee;
-    if( NULL != _p_vlcmarquee )
-    {
-        _p_vlcmarquee->AddRef();
-        return NOERROR;
-    }
-    return E_OUTOFMEMORY;
-};
+    return object_get(obj,_p_vlcmarquee);
+}
 
 STDMETHODIMP VLCVideo::get_logo(IVLCLogo** obj)
 {
-    if( NULL == obj )
-        return E_POINTER;
-
-    *obj = _p_vlclogo;
-    if( NULL != _p_vlclogo )
-    {
-        _p_vlclogo->AddRef();
-        return NOERROR;
-    }
-    return E_OUTOFMEMORY;
+    return object_get(obj,_p_vlclogo);
 }
 
 
@@ -2048,84 +2045,30 @@ STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
 
 STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
 {
-    if( NULL == obj )
-        return E_POINTER;
-
-    *obj = _p_vlcaudio;
-    if( NULL != _p_vlcaudio )
-    {
-        _p_vlcaudio->AddRef();
-        return NOERROR;
-    }
-    return E_OUTOFMEMORY;
-};
+    return object_get(obj,_p_vlcaudio);
+}
 
 STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
 {
-    if( NULL == obj )
-        return E_POINTER;
-
-    *obj = _p_vlcinput;
-    if( NULL != _p_vlcinput )
-    {
-        _p_vlcinput->AddRef();
-        return NOERROR;
-    }
-    return E_OUTOFMEMORY;
-};
+    return object_get(obj,_p_vlcinput);
+}
 
 STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
 {
-    if( NULL == obj )
-        return E_POINTER;
-
-    *obj = _p_vlclog;
-    if( NULL != _p_vlclog )
-    {
-        _p_vlclog->AddRef();
-        return NOERROR;
-    }
-    return E_OUTOFMEMORY;
-};
+    return object_get(obj,_p_vlclog);
+}
 
 STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
 {
-    if( NULL == obj )
-        return E_POINTER;
-
-    *obj = _p_vlcplaylist;
-    if( NULL != _p_vlcplaylist )
-    {
-        _p_vlcplaylist->AddRef();
-        return NOERROR;
-    }
-    return E_OUTOFMEMORY;
-};
+    return object_get(obj,_p_vlcplaylist);
+}
 
 STDMETHODIMP VLCControl2::get_subtitle(IVLCSubtitle** obj)
 {
-    if( NULL == obj )
-        return E_POINTER;
-
-    *obj = _p_vlcsubtitle;
-    if( NULL != _p_vlcsubtitle )
-    {
-        _p_vlcsubtitle->AddRef();
-        return NOERROR;
-    }
-    return E_OUTOFMEMORY;
-};
+    return object_get(obj,_p_vlcsubtitle);
+}
 
 STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
 {
-    if( NULL == obj )
-        return E_POINTER;
-
-    *obj = _p_vlcvideo;
-    if( NULL != _p_vlcvideo )
-    {
-        _p_vlcvideo->AddRef();
-        return NOERROR;
-    }
-    return E_OUTOFMEMORY;
-};
+    return object_get(obj,_p_vlcvideo);
+}
diff --git a/projects/activex/vlccontrol2.h b/projects/activex/vlccontrol2.h
index 7d4067c..496f8b0 100644
--- a/projects/activex/vlccontrol2.h
+++ b/projects/activex/vlccontrol2.h
@@ -276,8 +276,8 @@ public:
     STDMETHODIMP put_verbosity(long);
 
 protected:
-    libvlc_log_t    *_p_log;
-    VLCMessages*    _p_vlcmessages;
+    libvlc_log_t *_p_log;
+    IVLCMessages *_p_vlcmessages;
 };
 
 class VLCMarquee: public VLCInterface<VLCMarquee,IVLCMarquee>
@@ -425,8 +425,8 @@ public:
     STDMETHODIMP toggleTeletext();
 
 private:
-    VLCMarquee*     _p_vlcmarquee;
-    VLCLogo*        _p_vlclogo;
+    IVLCMarquee *_p_vlcmarquee;
+    IVLCLogo    *_p_vlclogo;
 };
 
 class VLCControl2 : public IVLCControl2
@@ -493,15 +493,15 @@ protected:
     HRESULT loadTypeInfo();
 
 private:
-    VLCPlugin*      _p_instance;
-    ITypeInfo*      _p_typeinfo;
-
-    VLCAudio*       _p_vlcaudio;
-    VLCInput*       _p_vlcinput;
-    VLCLog  *       _p_vlclog;
-    VLCPlaylist*    _p_vlcplaylist;
-    VLCSubtitle*    _p_vlcsubtitle;
-    VLCVideo*       _p_vlcvideo;
+    VLCPlugin    *_p_instance;
+    ITypeInfo    *_p_typeinfo;
+
+    IVLCAudio    *_p_vlcaudio;
+    IVLCInput    *_p_vlcinput;
+    IVLCLog      *_p_vlclog;
+    IVLCPlaylist *_p_vlcplaylist;
+    IVLCSubtitle *_p_vlcsubtitle;
+    IVLCVideo    *_p_vlcvideo;
 };
 
 #endif




More information about the vlc-devel mailing list