xref: /trunk/main/cli_ure/source/uno_bridge/cli_base.h (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 ^ data);
51 System::String ^ mapUnoString(rtl_uString const * data);
52 System::String ^ mapUnoTypeName(rtl_uString const * typeName);
53 
54 ref struct Constants
55 {
56     static const System::String ^ sXInterfaceName= gcnew System::String(
57         "unoidl.com.sun.star.uno.XInterface");
58     static const System::String ^ sObject= gcnew System::String("System.Object");
59     static const System::String ^ sType= gcnew System::String("System.Type");
60     static const System::String ^ sUnoidl= gcnew System::String("unoidl.");
61     static const System::String ^ sVoid= gcnew System::String("System.Void");
62     static const System::String ^ sAny= gcnew System::String("uno.Any");
63     static const System::String ^ sArArray= gcnew System::String("System.Array[]");
64     static const System::String ^ sBoolean= gcnew System::String("System.Boolean");
65     static const System::String ^ sChar= gcnew System::String("System.Char");
66     static const System::String ^ sByte= gcnew System::String("System.Byte");
67     static const System::String ^ sInt16= gcnew System::String("System.Int16");
68     static const System::String ^ sUInt16= gcnew System::String("System.UInt16");
69     static const System::String ^ sInt32= gcnew System::String("System.Int32");
70     static const System::String ^ sUInt32= gcnew System::String("System.UInt32");
71     static const System::String ^ sInt64= gcnew System::String("System.Int64");
72     static const System::String ^ sUInt64= gcnew System::String("System.UInt64");
73     static const System::String ^ sString= gcnew System::String("System.String");
74     static const System::String ^ sSingle= gcnew System::String("System.Single");
75     static const System::String ^ sDouble= gcnew System::String("System.Double");
76     static const System::String ^ sArBoolean= gcnew System::String("System.Boolean[]");
77     static const System::String ^ sArChar= gcnew System::String("System.Char[]");
78     static const System::String ^ sArByte= gcnew System::String("System.Byte[]");
79     static const System::String ^ sArInt16= gcnew System::String("System.Int16[]");
80     static const System::String ^ sArUInt16= gcnew System::String("System.UInt16[]");
81     static const System::String ^ sArInt32= gcnew System::String("System.Int32[]");
82     static const System::String ^ sArUInt32= gcnew System::String("System.UInt32[]");
83     static const System::String ^ sArInt64= gcnew System::String("System.Int64[]");
84     static const System::String ^ sArUInt64= gcnew System::String("System.UInt64[]");
85     static const System::String ^ sArString= gcnew System::String("System.String[]");
86     static const System::String ^ sArSingle= gcnew System::String("System.Single[]");
87     static const System::String ^ sArDouble= gcnew System::String("System.Double[]");
88     static const System::String ^ sArType= gcnew System::String("System.Type[]");
89     static const System::String ^ sArObject= gcnew System::String("System.Object[]");
90     static const System::String ^ sBrackets= gcnew System::String("[]");
91     static const System::String ^ sAttributeSet= gcnew System::String("set_");
92     static const System::String ^ sAttributeGet= gcnew System::String("get_");
93 
94     static const System::String ^ usXInterface = "com.sun.star.uno.XInterface";
95     static const System::String ^ usVoid = "void";
96     static const System::String ^ usType = "type";
97     static const System::String ^ usAny = "any";
98     static const System::String ^ usBrackets = "[]";
99     static const System::String ^ usBool = "boolean";
100     static const System::String ^ usByte = "byte";
101     static const System::String ^ usChar = "char";
102     static const System::String ^ usShort = "short";
103     static const System::String ^ usUShort = "unsigned short";
104     static const System::String ^ usLong = "long";
105     static const System::String ^ usULong = "unsigned long";
106     static const System::String ^ usHyper = "hyper";
107     static const System::String ^ usUHyper = "unsigned hyper";
108     static const System::String ^ usString = "string";
109     static const System::String ^ usFloat = "float";
110     static const System::String ^ usDouble = "double";
111 };
112 
113 struct BridgeRuntimeError
114 {
115     ::rtl::OUString m_message;
116 
BridgeRuntimeErrorBridgeRuntimeError117     inline BridgeRuntimeError( ::rtl::OUString const & message )
118         : m_message( message )
119         {}
120 };
121 
122 //==================================================================================================
123 struct rtl_mem
124 {
newrtl_mem125     inline static void * operator new ( size_t nSize )
126         { return rtl_allocateMemory( nSize ); }
deletertl_mem127     inline static void operator delete ( void * mem )
128         { if (mem) rtl_freeMemory( mem ); }
newrtl_mem129     inline static void * operator new ( size_t, void * mem )
130         { return mem; }
deletertl_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()158     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