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