build fix
[LibreOffice.git] / cli_ure / source / native / native_share.h
blob1be1b3a082b3ccb95cbafb705fc8cd06f0c11e5b
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/lbnames.h>
25 #include "uno/mapping.hxx"
27 #include <vcclr.h>
30 namespace uno
32 namespace util
36 inline ::System::String ^ ustring_to_String( OUString const & ustr )
38 return gcnew ::System::String( ustr.getStr(), 0, ustr.getLength() );
41 inline OUString String_to_ustring( ::System::String ^ str )
43 OSL_ASSERT( sizeof (wchar_t) == sizeof (sal_Unicode) );
44 pin_ptr<wchar_t const> chars = PtrToStringChars( str );
45 return OUString( chars, str->Length );
48 template< typename T >
49 inline ::System::Object ^ to_cli(
50 css::uno::Reference< T > const & x )
52 css::uno::Mapping mapping(
53 CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_CLI );
54 OSL_ASSERT( mapping.is() );
55 if (! mapping.is())
57 throw css::uno::RuntimeException(
58 "cannot get mapping from C++ to CLI!",
59 css::uno::Reference<
60 css::uno::XInterface >() );
63 intptr_t intptr =
64 reinterpret_cast< intptr_t >(
65 mapping.mapInterface( x.get(), cppu::UnoType<decltype(x)>::get() ) );
66 ::System::Runtime::InteropServices::GCHandle ^ handle = ::System::Runtime::InteropServices::GCHandle::FromIntPtr(::System::IntPtr(intptr));
67 ::System::Object ^ ret = handle->Target;
68 handle->Free();
69 return ret;
72 template< typename T >
73 inline void to_uno(
74 css::uno::Reference< T > * pRet, ::System::Object ^ x )
76 css::uno::Mapping mapping(
77 UNO_LB_CLI, CPPU_CURRENT_LANGUAGE_BINDING_NAME );
78 OSL_ASSERT( mapping.is() );
79 if (! mapping.is())
81 throw css::uno::RuntimeException(
82 "cannot get mapping from CLI to C++!",
83 css::uno::Reference<
84 css::uno::XInterface >() );
87 ::System::Runtime::InteropServices::GCHandle handle(
88 ::System::Runtime::InteropServices::GCHandle::Alloc( x ) );
89 T * ret = 0;
90 mapping.mapInterface(
91 reinterpret_cast< void ** >( &ret ),
92 reinterpret_cast< void * >(
93 ::System::Runtime::InteropServices::GCHandle::op_Explicit( handle )
94 #if defined _WIN64
95 .ToInt64()
96 #elif defined _WIN32
97 .ToInt32()
98 #else
99 #error ERROR: either _WIN64 or _WIN32 must be defined
100 ERROR: either _WIN64 or _WIN32 must be defined
101 #endif
103 cppu::UnoType<T>::get() );
104 handle.Free();
105 pRet->set( ret, SAL_NO_ACQUIRE /* takeover ownership */ );
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */