xref: /AOO41X/main/cli_ure/source/uno_bridge/cli_base.h (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #if ! defined INCLUDED_CLI_BASE_H
29*cdf0e10cSrcweir #define INCLUDED_CLI_BASE_H
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #pragma unmanaged
32*cdf0e10cSrcweir // Workaround: osl/mutex.h contains only a forward declaration of _oslMutexImpls.
33*cdf0e10cSrcweir // When using the inline class in Mutex in osl/mutex.hxx, the loader needs to find
34*cdf0e10cSrcweir // a declaration for the struct. If not found a TypeLoadException is being thrown.
35*cdf0e10cSrcweir struct _oslMutexImpl
36*cdf0e10cSrcweir {
37*cdf0e10cSrcweir };
38*cdf0e10cSrcweir #pragma managed
39*cdf0e10cSrcweir #include <memory>
40*cdf0e10cSrcweir #include "rtl/ustring.hxx"
41*cdf0e10cSrcweir #include "typelib/typedescription.hxx"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #using <mscorlib.dll>
44*cdf0e10cSrcweir #using <system.dll>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir namespace cli_uno
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir System::Type* loadCliType(System::String * typeName);
51*cdf0e10cSrcweir System::Type* mapUnoType(typelib_TypeDescription const * pTD);
52*cdf0e10cSrcweir System::Type* mapUnoType(typelib_TypeDescriptionReference const * pTD);
53*cdf0e10cSrcweir typelib_TypeDescriptionReference* mapCliType(System::Type* cliType);
54*cdf0e10cSrcweir rtl::OUString mapCliString(System::String const * data);
55*cdf0e10cSrcweir System::String* mapUnoString(rtl_uString const * data);
56*cdf0e10cSrcweir System::String* mapUnoTypeName(rtl_uString const * typeName);
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir __gc struct Constants
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir     static const System::String* sXInterfaceName= new System::String(
61*cdf0e10cSrcweir         S"unoidl.com.sun.star.uno.XInterface");
62*cdf0e10cSrcweir     static const System::String* sObject= new System::String(S"System.Object");
63*cdf0e10cSrcweir     static const System::String* sType= new System::String(S"System.Type");
64*cdf0e10cSrcweir     static const System::String* sUnoidl= new System::String(S"unoidl.");
65*cdf0e10cSrcweir     static const System::String* sVoid= new System::String(S"System.Void");
66*cdf0e10cSrcweir     static const System::String* sAny= new System::String(S"uno.Any");
67*cdf0e10cSrcweir     static const System::String* sArArray= new System::String(S"System.Array[]");
68*cdf0e10cSrcweir     static const System::String* sBoolean= new System::String(S"System.Boolean");
69*cdf0e10cSrcweir     static const System::String* sChar= new System::String(S"System.Char");
70*cdf0e10cSrcweir     static const System::String* sByte= new System::String(S"System.Byte");
71*cdf0e10cSrcweir     static const System::String* sInt16= new System::String(S"System.Int16");
72*cdf0e10cSrcweir     static const System::String* sUInt16= new System::String(S"System.UInt16");
73*cdf0e10cSrcweir     static const System::String* sInt32= new System::String(S"System.Int32");
74*cdf0e10cSrcweir     static const System::String* sUInt32= new System::String(S"System.UInt32");
75*cdf0e10cSrcweir     static const System::String* sInt64= new System::String(S"System.Int64");
76*cdf0e10cSrcweir     static const System::String* sUInt64= new System::String(S"System.UInt64");
77*cdf0e10cSrcweir     static const System::String* sString= new System::String(S"System.String");
78*cdf0e10cSrcweir     static const System::String* sSingle= new System::String(S"System.Single");
79*cdf0e10cSrcweir     static const System::String* sDouble= new System::String(S"System.Double");
80*cdf0e10cSrcweir     static const System::String* sArBoolean= new System::String(S"System.Boolean[]");
81*cdf0e10cSrcweir     static const System::String* sArChar= new System::String(S"System.Char[]");
82*cdf0e10cSrcweir     static const System::String* sArByte= new System::String(S"System.Byte[]");
83*cdf0e10cSrcweir     static const System::String* sArInt16= new System::String(S"System.Int16[]");
84*cdf0e10cSrcweir     static const System::String* sArUInt16= new System::String(S"System.UInt16[]");
85*cdf0e10cSrcweir     static const System::String* sArInt32= new System::String(S"System.Int32[]");
86*cdf0e10cSrcweir     static const System::String* sArUInt32= new System::String(S"System.UInt32[]");
87*cdf0e10cSrcweir     static const System::String* sArInt64= new System::String(S"System.Int64[]");
88*cdf0e10cSrcweir     static const System::String* sArUInt64= new System::String(S"System.UInt64[]");
89*cdf0e10cSrcweir     static const System::String* sArString= new System::String(S"System.String[]");
90*cdf0e10cSrcweir     static const System::String* sArSingle= new System::String(S"System.Single[]");
91*cdf0e10cSrcweir     static const System::String* sArDouble= new System::String(S"System.Double[]");
92*cdf0e10cSrcweir     static const System::String* sArType= new System::String(S"System.Type[]");
93*cdf0e10cSrcweir     static const System::String* sArObject= new System::String(S"System.Object[]");
94*cdf0e10cSrcweir     static const System::String* sBrackets= new System::String(S"[]");
95*cdf0e10cSrcweir     static const System::String* sAttributeSet= new System::String(S"set_");
96*cdf0e10cSrcweir     static const System::String* sAttributeGet= new System::String(S"get_");
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	static const System::String* usXInterface = S"com.sun.star.uno.XInterface";
99*cdf0e10cSrcweir 	static const System::String* usVoid = S"void";
100*cdf0e10cSrcweir 	static const System::String* usType = S"type";
101*cdf0e10cSrcweir 	static const System::String* usAny = S"any";
102*cdf0e10cSrcweir 	static const System::String* usBrackets = S"[]";
103*cdf0e10cSrcweir 	static const System::String* usBool = S"boolean";
104*cdf0e10cSrcweir 	static const System::String* usByte = S"byte";
105*cdf0e10cSrcweir 	static const System::String* usChar = S"char";
106*cdf0e10cSrcweir 	static const System::String* usShort = S"short";
107*cdf0e10cSrcweir 	static const System::String* usUShort = S"unsigned short";
108*cdf0e10cSrcweir 	static const System::String* usLong = S"long";
109*cdf0e10cSrcweir 	static const System::String* usULong = S"unsigned long";
110*cdf0e10cSrcweir 	static const System::String* usHyper = S"hyper";
111*cdf0e10cSrcweir 	static const System::String* usUHyper = S"unsigned hyper";
112*cdf0e10cSrcweir 	static const System::String* usString = S"string";
113*cdf0e10cSrcweir 	static const System::String* usFloat = S"float";
114*cdf0e10cSrcweir 	static const System::String* usDouble = S"double";
115*cdf0e10cSrcweir };
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir struct BridgeRuntimeError
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     ::rtl::OUString m_message;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     inline BridgeRuntimeError( ::rtl::OUString const & message )
122*cdf0e10cSrcweir         : m_message( message )
123*cdf0e10cSrcweir         {}
124*cdf0e10cSrcweir };
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //==================================================================================================
127*cdf0e10cSrcweir struct rtl_mem
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir 	inline static void * operator new ( size_t nSize )
130*cdf0e10cSrcweir 		{ return rtl_allocateMemory( nSize ); }
131*cdf0e10cSrcweir 	inline static void operator delete ( void * mem )
132*cdf0e10cSrcweir 		{ if (mem) rtl_freeMemory( mem ); }
133*cdf0e10cSrcweir 	inline static void * operator new ( size_t, void * mem )
134*cdf0e10cSrcweir 		{ return mem; }
135*cdf0e10cSrcweir 	inline static void operator delete ( void *, void * )
136*cdf0e10cSrcweir 		{}
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     static inline ::std::auto_ptr< rtl_mem > allocate( ::std::size_t bytes );
139*cdf0e10cSrcweir };
140*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
141*cdf0e10cSrcweir inline ::std::auto_ptr< rtl_mem > rtl_mem::allocate( ::std::size_t bytes )
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     void * p = rtl_allocateMemory( bytes );
144*cdf0e10cSrcweir     if (0 == p)
145*cdf0e10cSrcweir         throw BridgeRuntimeError(OUSTR("out of memory!") );
146*cdf0e10cSrcweir     return ::std::auto_ptr< rtl_mem >( (rtl_mem *)p );
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir //==================================================================================================
150*cdf0e10cSrcweir class TypeDescr
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir     typelib_TypeDescription * m_td;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     TypeDescr( TypeDescr & ); // not impl
155*cdf0e10cSrcweir     void operator = ( TypeDescr ); // not impl
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir public:
158*cdf0e10cSrcweir     inline explicit TypeDescr( typelib_TypeDescriptionReference * td_ref );
159*cdf0e10cSrcweir     inline ~TypeDescr() SAL_THROW( () )
160*cdf0e10cSrcweir         { TYPELIB_DANGER_RELEASE( m_td ); }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     inline typelib_TypeDescription * get() const
163*cdf0e10cSrcweir         { return m_td; }
164*cdf0e10cSrcweir };
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir inline TypeDescr::TypeDescr( typelib_TypeDescriptionReference * td_ref )
167*cdf0e10cSrcweir     : m_td( 0 )
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir     TYPELIB_DANGER_GET( &m_td, td_ref );
170*cdf0e10cSrcweir     if (0 == m_td)
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         throw BridgeRuntimeError(
173*cdf0e10cSrcweir             OUSTR("cannot get comprehensive type description for ") +
174*cdf0e10cSrcweir             *reinterpret_cast< ::rtl::OUString const * >( &td_ref->pTypeName ) );
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir } //end namespace cli_uno
180*cdf0e10cSrcweir  #endif
181