Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / cli_ure / source / native / native_share.h
blob7106f0daf8208837377e1317cf100ba238a8d09a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #using <mscorlib.dll>
30 #using "cli_ure.dll"
31 #using "cli_uretypes.dll"
33 #include "rtl/ustring.hxx"
34 #include "uno/mapping.hxx"
36 #include <vcclr.h>
38 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
41 namespace uno
43 namespace util
46 //------------------------------------------------------------------------------
47 inline ::System::String * ustring_to_String( ::rtl::OUString const & ustr )
49 return new ::System::String( ustr.getStr(), 0, ustr.getLength() );
51 //------------------------------------------------------------------------------
52 inline ::rtl::OUString String_to_ustring( ::System::String * str )
54 OSL_ASSERT( sizeof (wchar_t) == sizeof (sal_Unicode) );
55 wchar_t const __pin * chars = PtrToStringChars( str );
56 return ::rtl::OUString( chars, str->get_Length() );
59 template< typename T >
60 inline ::System::Object * to_cli(
61 ::com::sun::star::uno::Reference< T > const & x )
63 ::com::sun::star::uno::Mapping mapping(
64 OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME), OUSTR(UNO_LB_CLI) );
65 OSL_ASSERT( mapping.is() );
66 if (! mapping.is())
68 throw ::com::sun::star::uno::RuntimeException(
69 OUSTR("cannot get mapping from C++ to CLI!"),
70 ::com::sun::star::uno::Reference<
71 ::com::sun::star::uno::XInterface >() );
74 intptr_t intptr =
75 reinterpret_cast< intptr_t >(
76 mapping.mapInterface( x.get(), ::getCppuType( &x ) ) );
77 ::System::Runtime::InteropServices::GCHandle handle(
78 ::System::Runtime::InteropServices::GCHandle::op_Explicit( intptr ) );
79 ::System::Object * ret = handle.get_Target();
80 handle.Free();
81 return ret;
84 template< typename T >
85 inline void to_uno(
86 ::com::sun::star::uno::Reference< T > * pRet, ::System::Object * x )
88 ::com::sun::star::uno::Mapping mapping(
89 OUSTR(UNO_LB_CLI), OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
90 OSL_ASSERT( mapping.is() );
91 if (! mapping.is())
93 throw ::com::sun::star::uno::RuntimeException(
94 OUSTR("cannot get mapping from CLI to C++!"),
95 ::com::sun::star::uno::Reference<
96 ::com::sun::star::uno::XInterface >() );
99 ::System::Runtime::InteropServices::GCHandle handle(
100 ::System::Runtime::InteropServices::GCHandle::Alloc( x ) );
101 T * ret = 0;
102 mapping.mapInterface(
103 reinterpret_cast< void ** >( &ret ),
104 reinterpret_cast< void * >(
105 ::System::Runtime::InteropServices::GCHandle::op_Explicit( handle )
106 #if defined _WIN32
107 .ToInt32()
108 #elif defined _WIN64
109 .ToInt64()
110 #else
111 #error ERROR: either _WIN64 or _WIN32 must be defined
112 ERROR: either _WIN64 or _WIN32 must be defined
113 #endif
115 ::getCppuType( pRet ) );
116 handle.Free();
117 pRet->set( ret, SAL_NO_ACQUIRE /* takeover ownership */ );
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */