GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / cli_ure / source / native / native_share.h
blob7c97153264ef279c16329007411960334a2b48e8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #using "cli_ure.dll"
21 #using "cli_uretypes.dll"
23 #include "rtl/ustring.hxx"
24 #include "uno/mapping.hxx"
26 #include <vcclr.h>
29 namespace uno
31 namespace util
34 //------------------------------------------------------------------------------
35 inline ::System::String ^ ustring_to_String( OUString const & ustr )
37 return gcnew ::System::String( ustr.getStr(), 0, ustr.getLength() );
39 //------------------------------------------------------------------------------
40 inline OUString String_to_ustring( ::System::String ^ str )
42 OSL_ASSERT( sizeof (wchar_t) == sizeof (sal_Unicode) );
43 pin_ptr<wchar_t const> chars = PtrToStringChars( str );
44 return OUString( chars, str->Length );
47 template< typename T >
48 inline ::System::Object ^ to_cli(
49 ::com::sun::star::uno::Reference< T > const & x )
51 ::com::sun::star::uno::Mapping mapping(
52 CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_CLI );
53 OSL_ASSERT( mapping.is() );
54 if (! mapping.is())
56 throw ::com::sun::star::uno::RuntimeException(
57 "cannot get mapping from C++ to CLI!",
58 ::com::sun::star::uno::Reference<
59 ::com::sun::star::uno::XInterface >() );
62 intptr_t intptr =
63 reinterpret_cast< intptr_t >(
64 mapping.mapInterface( x.get(), ::getCppuType( &x ) ) );
65 ::System::Runtime::InteropServices::GCHandle ^ handle = ::System::Runtime::InteropServices::GCHandle::FromIntPtr(::System::IntPtr(intptr));
66 ::System::Object ^ ret = handle->Target;
67 handle->Free();
68 return ret;
71 template< typename T >
72 inline void to_uno(
73 ::com::sun::star::uno::Reference< T > * pRet, ::System::Object ^ x )
75 ::com::sun::star::uno::Mapping mapping(
76 UNO_LB_CLI, CPPU_CURRENT_LANGUAGE_BINDING_NAME );
77 OSL_ASSERT( mapping.is() );
78 if (! mapping.is())
80 throw ::com::sun::star::uno::RuntimeException(
81 "cannot get mapping from CLI to C++!",
82 ::com::sun::star::uno::Reference<
83 ::com::sun::star::uno::XInterface >() );
86 ::System::Runtime::InteropServices::GCHandle handle(
87 ::System::Runtime::InteropServices::GCHandle::Alloc( x ) );
88 T * ret = 0;
89 mapping.mapInterface(
90 reinterpret_cast< void ** >( &ret ),
91 reinterpret_cast< void * >(
92 ::System::Runtime::InteropServices::GCHandle::op_Explicit( handle )
93 #if defined _WIN32
94 .ToInt32()
95 #elif defined _WIN64
96 .ToInt64()
97 #else
98 #error ERROR: either _WIN64 or _WIN32 must be defined
99 ERROR: either _WIN64 or _WIN32 must be defined
100 #endif
102 ::getCppuType( pRet ) );
103 handle.Free();
104 pRet->set( ret, SAL_NO_ACQUIRE /* takeover ownership */ );
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */