LibreOffice Module cli_ure (master) 1
cli_base.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_CLI_URE_SOURCE_UNO_BRIDGE_CLI_BASE_H
21#define INCLUDED_CLI_URE_SOURCE_UNO_BRIDGE_CLI_BASE_H
22
23#pragma unmanaged
24// Workaround: osl/mutex.h contains only a forward declaration of _oslMutexImpls.
25// When using the inline class in Mutex in osl/mutex.hxx, the loader needs to find
26// a declaration for the struct. If not found a TypeLoadException is being thrown.
28{
29};
30#pragma managed
31#include <memory>
32#include "rtl/ustring.hxx"
33#include "typelib/typedescription.hxx"
34
35#using <system.dll>
36
37namespace cli_uno
38{
39System::Type^ loadCliType(System::String ^ typeName);
40System::Type^ mapUnoType(typelib_TypeDescription const * pTD);
41System::Type^ mapUnoType(typelib_TypeDescriptionReference const * pTD);
42typelib_TypeDescriptionReference* mapCliType(System::Type^ cliType);
43OUString mapCliString(System::String ^ data);
44System::String^ mapUnoString(rtl_uString const * data);
45System::String^ mapUnoTypeName(rtl_uString const * typeName);
46
47ref struct Constants
48{
49 static System::String^ sXInterfaceName= gcnew System::String(
50 "unoidl.com.sun.star.uno.XInterface");
51 static System::String^ sObject= gcnew System::String("System.Object");
52 static System::String^ sType= gcnew System::String("System.Type");
53 static System::String^ sUnoidl= gcnew System::String("unoidl.");
54 static System::String^ sVoid= gcnew System::String("System.Void");
55 static System::String^ sAny= gcnew System::String("uno.Any");
56 static System::String^ sArArray= gcnew System::String("System.Array[]");
57 static System::String^ sBoolean= gcnew System::String("System.Boolean");
58 static System::String^ sChar= gcnew System::String("System.Char");
59 static System::String^ sByte= gcnew System::String("System.Byte");
60 static System::String^ sInt16= gcnew System::String("System.Int16");
61 static System::String^ sUInt16= gcnew System::String("System.UInt16");
62 static System::String^ sInt32= gcnew System::String("System.Int32");
63 static System::String^ sUInt32= gcnew System::String("System.UInt32");
64 static System::String^ sInt64= gcnew System::String("System.Int64");
65 static System::String^ sUInt64= gcnew System::String("System.UInt64");
66 static System::String^ sString= gcnew System::String("System.String");
67 static System::String^ sSingle= gcnew System::String("System.Single");
68 static System::String^ sDouble= gcnew System::String("System.Double");
69 static System::String^ sArBoolean= gcnew System::String("System.Boolean[]");
70 static System::String^ sArChar= gcnew System::String("System.Char[]");
71 static System::String^ sArByte= gcnew System::String("System.Byte[]");
72 static System::String^ sArInt16= gcnew System::String("System.Int16[]");
73 static System::String^ sArUInt16= gcnew System::String("System.UInt16[]");
74 static System::String^ sArInt32= gcnew System::String("System.Int32[]");
75 static System::String^ sArUInt32= gcnew System::String("System.UInt32[]");
76 static System::String^ sArInt64= gcnew System::String("System.Int64[]");
77 static System::String^ sArUInt64= gcnew System::String("System.UInt64[]");
78 static System::String^ sArString= gcnew System::String("System.String[]");
79 static System::String^ sArSingle= gcnew System::String("System.Single[]");
80 static System::String^ sArDouble= gcnew System::String("System.Double[]");
81 static System::String^ sArType= gcnew System::String("System.Type[]");
82 static System::String^ sArObject= gcnew System::String("System.Object[]");
83 static System::String^ sBrackets= gcnew System::String("[]");
84 static System::String^ sAttributeSet= gcnew System::String("set_");
85 static System::String^ sAttributeGet= gcnew System::String("get_");
86
87 static System::String^ usXInterface = "com.sun.star.uno.XInterface";
88 static System::String^ usVoid = "void";
89 static System::String^ usType = "type";
90 static System::String^ usAny = "any";
91 static System::String^ usBrackets = "[]";
92 static System::String^ usBool = "boolean";
93 static System::String^ usByte = "byte";
94 static System::String^ usChar = "char";
95 static System::String^ usShort = "short";
96 static System::String^ usUShort = "unsigned short";
97 static System::String^ usLong = "long";
98 static System::String^ usULong = "unsigned long";
99 static System::String^ usHyper = "hyper";
100 static System::String^ usUHyper = "unsigned hyper";
101 static System::String^ usString = "string";
102 static System::String^ usFloat = "float";
103 static System::String^ usDouble = "double";
104};
105
107{
108 OUString m_message;
109
110 inline BridgeRuntimeError( OUString const & message )
111 : m_message( message )
112 {}
113};
114
115
117{
118 inline static void * operator new ( size_t nSize )
119 { return std::malloc( nSize ); }
120 inline static void operator delete ( void * mem )
121 { std::free( mem ); }
122 inline static void * operator new ( size_t, void * mem )
123 { return mem; }
124 inline static void operator delete ( void *, void * )
125 {}
126
127 static inline std::unique_ptr< rtl_mem > allocate( std::size_t bytes );
128};
129
130inline std::unique_ptr< rtl_mem > rtl_mem::allocate( std::size_t bytes )
131{
132 void * p = std::malloc( bytes );
133 if (0 == p)
134 throw BridgeRuntimeError("out of memory!" );
135 return std::unique_ptr< rtl_mem >( (rtl_mem *)p );
136}
137
138
140{
142
143 TypeDescr( TypeDescr const & ) = delete;
144 TypeDescr& operator = ( TypeDescr const & ) = delete;
145
146public:
147 inline explicit TypeDescr( typelib_TypeDescriptionReference * td_ref );
148 inline ~TypeDescr()
149 { TYPELIB_DANGER_RELEASE( m_td ); }
150
152 { return m_td; }
153};
154
155inline TypeDescr::TypeDescr( typelib_TypeDescriptionReference * td_ref )
156 : m_td( 0 )
157{
158 TYPELIB_DANGER_GET( &m_td, td_ref );
159 if (0 == m_td)
160 {
161 throw BridgeRuntimeError(
162 "cannot get comprehensive type description for " +
163 OUString::unacquired(&td_ref->pTypeName) );
164 }
165}
166
167
168} //end namespace cli_uno
169 #endif
170
171/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
typelib_TypeDescription * get() const
Definition: cli_base.h:151
TypeDescr & operator=(TypeDescr const &)=delete
TypeDescr(TypeDescr const &)=delete
typelib_TypeDescription * m_td
Definition: cli_base.h:141
void * p
struct _typelib_TypeDescription typelib_TypeDescription
System::Type loadCliType(System::String ^ typeName)
Definition: cli_data.cxx:141
OUString mapCliString(System::String ^ data)
Definition: cli_data.cxx:715
System::String mapUnoTypeName(rtl_uString const *typeName)
Otherwise a leading "unoidl." is removed.
Definition: cli_data.cxx:455
System::Type mapUnoType(typelib_TypeDescription const *pTD)
Definition: cli_data.cxx:186
System::String mapUnoString(rtl_uString const *data)
Maps uno types to dot net types.
Definition: cli_data.cxx:709
typelib_TypeDescriptionReference * mapCliType(System::Type^ cliType)
Returns an acquired td.
Definition: cli_data.cxx:312
std::vector< sal_uInt8 > bytes
OUString typeName
BridgeRuntimeError(OUString const &message)
Definition: cli_base.h:110
static System::String sArUInt32
Definition: cli_base.h:75
static System::String usHyper
Definition: cli_base.h:99
static System::String sChar
Definition: cli_base.h:58
static System::String sDouble
Definition: cli_base.h:68
static System::String sAttributeGet
Definition: cli_base.h:85
static System::String sArByte
Definition: cli_base.h:71
static System::String sArObject
Definition: cli_base.h:82
static System::String sArType
Definition: cli_base.h:81
static System::String sArInt64
Definition: cli_base.h:76
static System::String usShort
Definition: cli_base.h:95
static System::String usBrackets
Definition: cli_base.h:91
static System::String sArUInt16
Definition: cli_base.h:73
static System::String usXInterface
Definition: cli_base.h:87
static System::String sType
Definition: cli_base.h:52
static System::String sInt32
Definition: cli_base.h:62
static System::String sInt64
Definition: cli_base.h:64
static System::String sArString
Definition: cli_base.h:78
static System::String usVoid
Definition: cli_base.h:88
static System::String usULong
Definition: cli_base.h:98
static System::String usUHyper
Definition: cli_base.h:100
static System::String sArDouble
Definition: cli_base.h:80
static System::String usLong
Definition: cli_base.h:97
static System::String usDouble
Definition: cli_base.h:103
static System::String sUInt16
Definition: cli_base.h:61
static System::String sAttributeSet
Definition: cli_base.h:84
static System::String sAny
Definition: cli_base.h:55
static System::String sUnoidl
Definition: cli_base.h:53
static System::String sSingle
Definition: cli_base.h:67
static System::String sString
Definition: cli_base.h:66
static System::String sArInt16
Definition: cli_base.h:72
static System::String usType
Definition: cli_base.h:89
static System::String sArSingle
Definition: cli_base.h:79
static System::String usByte
Definition: cli_base.h:93
static System::String sArBoolean
Definition: cli_base.h:69
static System::String usBool
Definition: cli_base.h:92
static System::String sArUInt64
Definition: cli_base.h:77
static System::String sBoolean
Definition: cli_base.h:57
static System::String sArArray
Definition: cli_base.h:56
static System::String usUShort
Definition: cli_base.h:96
static System::String sUInt64
Definition: cli_base.h:65
static System::String sBrackets
Definition: cli_base.h:83
static System::String sObject
Definition: cli_base.h:51
static System::String usString
Definition: cli_base.h:101
static System::String usChar
Definition: cli_base.h:94
static System::String sXInterfaceName
Definition: cli_base.h:49
static System::String sVoid
Definition: cli_base.h:54
static System::String usAny
Definition: cli_base.h:90
static System::String sArInt32
Definition: cli_base.h:74
static System::String sInt16
Definition: cli_base.h:60
static System::String sByte
Definition: cli_base.h:59
static System::String sUInt32
Definition: cli_base.h:63
static System::String usFloat
Definition: cli_base.h:102
static System::String sArChar
Definition: cli_base.h:70
static std::unique_ptr< rtl_mem > allocate(std::size_t bytes)
Definition: cli_base.h:130