xpcom/glue/nsIInterfaceRequestorUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/glue/nsIInterfaceRequestorUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef __nsInterfaceRequestorUtils_h
    1.11 +#define __nsInterfaceRequestorUtils_h
    1.12 +
    1.13 +#include "nsCOMPtr.h"
    1.14 +
    1.15 +// a type-safe shortcut for calling the |GetInterface()| member function
    1.16 +// T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous.
    1.17 +template <class T, class DestinationType>
    1.18 +inline
    1.19 +nsresult
    1.20 +CallGetInterface( T* aSource, DestinationType** aDestination )
    1.21 +  {
    1.22 +    NS_PRECONDITION(aSource, "null parameter");
    1.23 +    NS_PRECONDITION(aDestination, "null parameter");
    1.24 +
    1.25 +    return aSource->GetInterface(NS_GET_TEMPLATE_IID(DestinationType),
    1.26 +                                 reinterpret_cast<void**>(aDestination));
    1.27 +  }
    1.28 +
    1.29 +class NS_COM_GLUE nsGetInterface : public nsCOMPtr_helper
    1.30 +  {
    1.31 +    public:
    1.32 +      nsGetInterface( nsISupports* aSource, nsresult* error )
    1.33 +          : mSource(aSource),
    1.34 +            mErrorPtr(error)
    1.35 +        {
    1.36 +          // nothing else to do here
    1.37 +        }
    1.38 +
    1.39 +      virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
    1.40 +
    1.41 +    private:
    1.42 +      nsISupports*          mSource;
    1.43 +      nsresult*             mErrorPtr;
    1.44 +  };
    1.45 +
    1.46 +inline
    1.47 +const nsGetInterface
    1.48 +do_GetInterface( nsISupports* aSource, nsresult* error = 0 )
    1.49 +  {
    1.50 +    return nsGetInterface(aSource, error);
    1.51 +  }
    1.52 +
    1.53 +#endif // __nsInterfaceRequestorUtils_h
    1.54 +

mercurial