Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3698

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/98/3698/1

Proof of concept - conversion operator for uno::Reference

Change-Id: I589b57c0a54524460fc8518a456dc09797c3567a
---
M include/com/sun/star/uno/Reference.h
M include/com/sun/star/uno/Reference.hxx
2 files changed, 56 insertions(+), 5 deletions(-)



diff --git a/include/com/sun/star/uno/Reference.h b/include/com/sun/star/uno/Reference.h
index 94551a0..2b776b8 100644
--- a/include/com/sun/star/uno/Reference.h
+++ b/include/com/sun/star/uno/Reference.h
@@ -19,6 +19,8 @@
 #ifndef _COM_SUN_STAR_UNO_REFERENCE_H_
 #define _COM_SUN_STAR_UNO_REFERENCE_H_
 
+#include <boost/config.hpp> // for BOOST_NO_MEMBER_TEMPLATE_FRIENDS macro
+
 #include <rtl/alloc.h>
 
 
@@ -54,10 +56,6 @@
 class BaseReference
 {
 protected:
-    /** the interface pointer
-    */
-    XInterface * _pInterface;
-
     /** Queries given interface for type rType.
 
         @param pInterface interface pointer
@@ -77,6 +75,19 @@
     inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType )
         SAL_THROW( (RuntimeException) );
 #endif
+
+// if member template friends don't work, make protected _pInterface
+// public, to allow template copy constructor from Reference to access
+// them.
+#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
+    template<typename T> friend class Reference;
+#else
+public:
+#endif
+
+    /** the interface pointer
+    */
+    XInterface * _pInterface;
 
 public:
     /** Gets interface pointer. This call does not acquire the interface.
@@ -332,6 +343,15 @@
     inline Reference( interface_type * pInterface, UnoReference_SetThrow dummy ) SAL_THROW( 
(RuntimeException) );
 #endif
 
+    /* Constructor: copy-construct from derived interface
+
+       @param rRef
+       Interface reference that must be convertible to interface_type
+       (typically, this implies that interface_type is a basetype of
+       the passed type)
+     */
+    template< class Ifc > inline Reference( const Reference<Ifc>& rRef );
+
     /** Cast operator to Reference< XInterface >: Reference objects are binary compatible and
         any interface must be derived from com.sun.star.uno.XInterface.
         This a useful direct cast possibility.
@@ -485,6 +505,18 @@
     */
     inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & 
rRef ) SAL_THROW(());
 
+    /** Assignment operator for derived interfaces: Acquires given
+        interface reference and sets reference.  An interface already
+        set will be released.
+
+        @param rRef
+        Interface reference that must be convertible to interface_type
+        (typically, this implies that interface_type is a basetype of
+        the passed type)
+     */
+    template< class Ifc >
+    inline Reference< interface_type > & SAL_CALL operator = ( const Reference<Ifc>& rRef );
+
     /** Queries given interface reference for type interface_type.
 
         @param rRef interface reference
diff --git a/include/com/sun/star/uno/Reference.hxx b/include/com/sun/star/uno/Reference.hxx
index aa39810..9b84809 100644
--- a/include/com/sun/star/uno/Reference.hxx
+++ b/include/com/sun/star/uno/Reference.hxx
@@ -193,7 +193,16 @@
     _pInterface = castToXInterface( iset_throw( pInterface ) );
 }
 #endif
-
+//__________________________________________________________________________________________________
+template< class interface_type >
+template< class Ifc >
+inline Reference< interface_type >::Reference( const Reference<Ifc>& rRef )
+{
+    interface_type* pTmp = reinterpret_cast< Ifc* >(rRef._pInterface);
+    _pInterface = pTmp;
+    if (_pInterface)
+        _pInterface->acquire();
+}
 
//__________________________________________________________________________________________________
 template< class interface_type >
 inline void Reference< interface_type >::clear() SAL_THROW(())
@@ -332,6 +341,16 @@
     set( castFromXInterface( rRef._pInterface ) );
     return *this;
 }
+//__________________________________________________________________________________________________
+template< class interface_type >
+template< class Ifc >
+inline Reference< interface_type > & Reference< interface_type >::operator = (
+    const Reference<Ifc>& rRef )
+{
+    interface_type* pTmp = reinterpret_cast< Ifc* >(rRef._pInterface);
+    set( pTmp );
+    return *this;
+}
 
 
//__________________________________________________________________________________________________
 template< class interface_type >

-- 
To view, visit https://gerrit.libreoffice.org/3698
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I589b57c0a54524460fc8518a456dc09797c3567a
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Thorsten Behrens <tbehrens@suse.com>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.