1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #if ! defined INCLUDED_CLI_BASE_H
25 #define INCLUDED_CLI_BASE_H
26 
27 #pragma unmanaged
28 // Workaround: osl/mutex.h contains only a forward declaration of _oslMutexImpls.
29 // When using the inline class in Mutex in osl/mutex.hxx, the loader needs to find
30 // a declaration for the struct. If not found a TypeLoadException is being thrown.
31 struct _oslMutexImpl
32 {
33 };
34 #pragma managed
35 #include <memory>
36 #include "rtl/ustring.hxx"
37 #include "typelib/typedescription.hxx"
38 
39 #using <mscorlib.dll>
40 #using <system.dll>
41 
42 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
43 
44 namespace cli_uno
45 {
46 System::Type* loadCliType(System::String * typeName);
47 System::Type* mapUnoType(typelib_TypeDescription const * pTD);
48 System::Type* mapUnoType(typelib_TypeDescriptionReference const * pTD);
49 typelib_TypeDescriptionReference* mapCliType(System::Type* cliType);
50 rtl::OUString mapCliString(System::String const * data);
51 System::String* mapUnoString(rtl_uString const * data);
52 System::String* mapUnoTypeName(rtl_uString const * typeName);
53 
54 __gc struct Constants
55 {
56     static const System::String* sXInterfaceName= new System::String(
57         S"unoidl.com.sun.star.uno.XInterface");
58     static const System::String* sObject= new System::String(S"System.Object");
59     static const System::String* sType= new System::String(S"System.Type");
60     static const System::String* sUnoidl= new System::String(S"unoidl.");
61     static const System::String* sVoid= new System::String(S"System.Void");
62     static const System::String* sAny= new System::String(S"uno.Any");
63     static const System::String* sArArray= new System::String(S"System.Array[]");
64     static const System::String* sBoolean= new System::String(S"System.Boolean");
65     static const System::String* sChar= new System::String(S"System.Char");
66     static const System::String* sByte= new System::String(S"System.Byte");
67     static const System::String* sInt16= new System::String(S"System.Int16");
68     static const System::String* sUInt16= new System::String(S"System.UInt16");
69     static const System::String* sInt32= new System::String(S"System.Int32");
70     static const System::String* sUInt32= new System::String(S"System.UInt32");
71     static const System::String* sInt64= new System::String(S"System.Int64");
72     static const System::String* sUInt64= new System::String(S"System.UInt64");
73     static const System::String* sString= new System::String(S"System.String");
74     static const System::String* sSingle= new System::String(S"System.Single");
75     static const System::String* sDouble= new System::String(S"System.Double");
76     static const System::String* sArBoolean= new System::String(S"System.Boolean[]");
77     static const System::String* sArChar= new System::String(S"System.Char[]");
78     static const System::String* sArByte= new System::String(S"System.Byte[]");
79     static const System::String* sArInt16= new System::String(S"System.Int16[]");
80     static const System::String* sArUInt16= new System::String(S"System.UInt16[]");
81     static const System::String* sArInt32= new System::String(S"System.Int32[]");
82     static const System::String* sArUInt32= new System::String(S"System.UInt32[]");
83     static const System::String* sArInt64= new System::String(S"System.Int64[]");
84     static const System::String* sArUInt64= new System::String(S"System.UInt64[]");
85     static const System::String* sArString= new System::String(S"System.String[]");
86     static const System::String* sArSingle= new System::String(S"System.Single[]");
87     static const System::String* sArDouble= new System::String(S"System.Double[]");
88     static const System::String* sArType= new System::String(S"System.Type[]");
89     static const System::String* sArObject= new System::String(S"System.Object[]");
90     static const System::String* sBrackets= new System::String(S"[]");
91     static const System::String* sAttributeSet= new System::String(S"set_");
92     static const System::String* sAttributeGet= new System::String(S"get_");
93 
94 	static const System::String* usXInterface = S"com.sun.star.uno.XInterface";
95 	static const System::String* usVoid = S"void";
96 	static const System::String* usType = S"type";
97 	static const System::String* usAny = S"any";
98 	static const System::String* usBrackets = S"[]";
99 	static const System::String* usBool = S"boolean";
100 	static const System::String* usByte = S"byte";
101 	static const System::String* usChar = S"char";
102 	static const System::String* usShort = S"short";
103 	static const System::String* usUShort = S"unsigned short";
104 	static const System::String* usLong = S"long";
105 	static const System::String* usULong = S"unsigned long";
106 	static const System::String* usHyper = S"hyper";
107 	static const System::String* usUHyper = S"unsigned hyper";
108 	static const System::String* usString = S"string";
109 	static const System::String* usFloat = S"float";
110 	static const System::String* usDouble = S"double";
111 };
112 
113 struct BridgeRuntimeError
114 {
115     ::rtl::OUString m_message;
116 
BridgeRuntimeErrorcli_uno::BridgeRuntimeError117     inline BridgeRuntimeError( ::rtl::OUString const & message )
118         : m_message( message )
119         {}
120 };
121 
122 //==================================================================================================
123 struct rtl_mem
124 {
operator newcli_uno::rtl_mem125 	inline static void * operator new ( size_t nSize )
126 		{ return rtl_allocateMemory( nSize ); }
operator deletecli_uno::rtl_mem127 	inline static void operator delete ( void * mem )
128 		{ if (mem) rtl_freeMemory( mem ); }
operator newcli_uno::rtl_mem129 	inline static void * operator new ( size_t, void * mem )
130 		{ return mem; }
operator deletecli_uno::rtl_mem131 	inline static void operator delete ( void *, void * )
132 		{}
133 
134     static inline ::std::auto_ptr< rtl_mem > allocate( ::std::size_t bytes );
135 };
136 //--------------------------------------------------------------------------------------------------
allocate(::std::size_t bytes)137 inline ::std::auto_ptr< rtl_mem > rtl_mem::allocate( ::std::size_t bytes )
138 {
139     void * p = rtl_allocateMemory( bytes );
140     if (0 == p)
141         throw BridgeRuntimeError(OUSTR("out of memory!") );
142     return ::std::auto_ptr< rtl_mem >( (rtl_mem *)p );
143 }
144 
145 //==================================================================================================
146 class TypeDescr
147 {
148     typelib_TypeDescription * m_td;
149 
150     TypeDescr( TypeDescr & ); // not impl
151     void operator = ( TypeDescr ); // not impl
152 
153 public:
154     inline explicit TypeDescr( typelib_TypeDescriptionReference * td_ref );
155     inline ~TypeDescr() SAL_THROW( () )
156         { TYPELIB_DANGER_RELEASE( m_td ); }
157 
get() const158     inline typelib_TypeDescription * get() const
159         { return m_td; }
160 };
161 
TypeDescr(typelib_TypeDescriptionReference * td_ref)162 inline TypeDescr::TypeDescr( typelib_TypeDescriptionReference * td_ref )
163     : m_td( 0 )
164 {
165     TYPELIB_DANGER_GET( &m_td, td_ref );
166     if (0 == m_td)
167     {
168         throw BridgeRuntimeError(
169             OUSTR("cannot get comprehensive type description for ") +
170             *reinterpret_cast< ::rtl::OUString const * >( &td_ref->pTypeName ) );
171     }
172 }
173 
174 
175 } //end namespace cli_uno
176  #endif
177