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