/src/libreoffice/cppu/source/uno/prim.hxx
Line | Count | Source |
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 | | #pragma once |
20 | | |
21 | | #include <typelib/typedescription.h> |
22 | | #include <typelib/typeclass.h> |
23 | | #include <uno/sequence2.h> |
24 | | #include <uno/any2.h> |
25 | | #include <uno/data.h> |
26 | | #include <uno/mapping.h> |
27 | | #include <uno/dispatcher.h> |
28 | | |
29 | | #include <osl/interlck.h> |
30 | | #include <stdint.h> |
31 | | |
32 | | namespace cppu |
33 | | { |
34 | | |
35 | | extern uno_Sequence g_emptySeq; |
36 | | extern typelib_TypeDescriptionReference * g_pVoidType; |
37 | | |
38 | | |
39 | | inline void * _map( |
40 | | void * p, |
41 | | typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr, |
42 | | uno_Mapping * mapping ) |
43 | | |
44 | 118k | { |
45 | 118k | void * pRet = nullptr; |
46 | 118k | if (p) |
47 | 30.7k | { |
48 | 30.7k | if (pTypeDescr) |
49 | 22.7k | { |
50 | 22.7k | (*mapping->mapInterface)( |
51 | 22.7k | mapping, &pRet, p, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); |
52 | 22.7k | } |
53 | 8.01k | else |
54 | 8.01k | { |
55 | 8.01k | TYPELIB_DANGER_GET( &pTypeDescr, pType ); |
56 | 8.01k | (*mapping->mapInterface)( |
57 | 8.01k | mapping, &pRet, p, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) ); |
58 | 8.01k | TYPELIB_DANGER_RELEASE( pTypeDescr ); |
59 | 8.01k | } |
60 | 30.7k | } |
61 | 118k | return pRet; |
62 | 118k | } |
63 | | |
64 | | inline void _acquire( void * p, uno_AcquireFunc acquire ) |
65 | 270M | { |
66 | 270M | if (p) |
67 | 266M | { |
68 | 266M | if (acquire) |
69 | 266M | { |
70 | 266M | (*acquire)( p ); |
71 | 266M | } |
72 | 0 | else |
73 | 0 | { |
74 | 0 | (*static_cast<uno_Interface *>(p)->acquire)( static_cast<uno_Interface *>(p) ); |
75 | 0 | } |
76 | 266M | } |
77 | 270M | } |
78 | | |
79 | | inline void _release( void * p, uno_ReleaseFunc release ) |
80 | 272M | { |
81 | 272M | if (p) |
82 | 40.2M | { |
83 | 40.2M | if (release) |
84 | 40.2M | { |
85 | 40.2M | (*release)( p ); |
86 | 40.2M | } |
87 | 25.0k | else |
88 | 25.0k | { |
89 | 25.0k | (*static_cast<uno_Interface *>(p)->release)( static_cast<uno_Interface *>(p) ); |
90 | 25.0k | } |
91 | 40.2M | } |
92 | 272M | } |
93 | | |
94 | | |
95 | | inline sal_uInt32 calcSeqMemSize( |
96 | | sal_Int32 nElementSize, sal_Int32 nElements ) |
97 | 25.4M | { |
98 | 25.4M | sal_uInt64 nSize = |
99 | 25.4M | static_cast<sal_uInt64>(SAL_SEQUENCE_HEADER_SIZE) + |
100 | 25.4M | (static_cast<sal_uInt64>(nElementSize) * static_cast<sal_uInt64>(nElements)); |
101 | 25.4M | if (nSize > 0xffffffffU) |
102 | 0 | return 0; |
103 | 25.4M | else |
104 | 25.4M | return static_cast<sal_uInt32>(nSize); |
105 | 25.4M | } |
106 | | |
107 | | |
108 | | inline uno_Sequence * createEmptySequence() |
109 | 214M | { |
110 | 214M | osl_atomic_increment( &g_emptySeq.nRefCount ); |
111 | 214M | return &g_emptySeq; |
112 | 214M | } |
113 | | |
114 | | inline typelib_TypeDescriptionReference * _getVoidType() |
115 | 896M | { |
116 | 896M | if (! g_pVoidType) |
117 | 106 | { |
118 | 106 | g_pVoidType = * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID ); |
119 | 106 | } |
120 | 896M | ::typelib_typedescriptionreference_acquire( g_pVoidType ); |
121 | 896M | return g_pVoidType; |
122 | 896M | } |
123 | | |
124 | 891M | inline void CONSTRUCT_EMPTY_ANY(uno_Any * pAny) { |
125 | 891M | pAny->pType = _getVoidType(); |
126 | | #if OSL_DEBUG_LEVEL > 0 |
127 | | pAny->pData = reinterpret_cast<void *>(uintptr_t(0xdeadbeef)); |
128 | | #else |
129 | 891M | pAny->pData = pAny; |
130 | 891M | #endif |
131 | 891M | } |
132 | | |
133 | | #define TYPE_ACQUIRE( pType ) \ |
134 | 875M | osl_atomic_increment( &(pType)->nRefCount ); |
135 | | |
136 | | |
137 | | extern "C" void * binuno_queryInterface( |
138 | | void * pUnoI, typelib_TypeDescriptionReference * pDestType ); |
139 | | |
140 | | |
141 | | inline bool _type_equals( |
142 | | typelib_TypeDescriptionReference const * pType1, typelib_TypeDescriptionReference const * pType2 ) |
143 | | |
144 | 35.3M | { |
145 | 35.3M | return (pType1 == pType2 || |
146 | 2.59M | (pType1->eTypeClass == pType2->eTypeClass && |
147 | 2.45M | pType1->pTypeName->length == pType2->pTypeName->length && |
148 | 1.09k | ::rtl_ustr_compare( pType1->pTypeName->buffer, pType2->pTypeName->buffer ) == 0)); |
149 | 35.3M | } |
150 | | |
151 | | } |
152 | | |
153 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |