LibreOffice Module cppu (master) 1
prim.hxx
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#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
32namespace cppu
33{
34
35extern uno_Sequence g_emptySeq;
36extern typelib_TypeDescriptionReference * g_pVoidType;
37
38
39inline void * _map(
40 void * p,
41 typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
42 uno_Mapping * mapping )
43
44{
45 void * pRet = nullptr;
46 if (p)
47 {
48 if (pTypeDescr)
49 {
50 (*mapping->mapInterface)(
51 mapping, &pRet, p, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) );
52 }
53 else
54 {
55 TYPELIB_DANGER_GET( &pTypeDescr, pType );
56 (*mapping->mapInterface)(
57 mapping, &pRet, p, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) );
58 TYPELIB_DANGER_RELEASE( pTypeDescr );
59 }
60 }
61 return pRet;
62}
63
64inline void _acquire( void * p, uno_AcquireFunc acquire )
65{
66 if (p)
67 {
68 if (acquire)
69 {
70 (*acquire)( p );
71 }
72 else
73 {
74 (*static_cast<uno_Interface *>(p)->acquire)( static_cast<uno_Interface *>(p) );
75 }
76 }
77}
78
79inline void _release( void * p, uno_ReleaseFunc release )
80{
81 if (p)
82 {
83 if (release)
84 {
85 (*release)( p );
86 }
87 else
88 {
89 (*static_cast<uno_Interface *>(p)->release)( static_cast<uno_Interface *>(p) );
90 }
91 }
92}
93
94
95inline sal_uInt32 calcSeqMemSize(
96 sal_Int32 nElementSize, sal_Int32 nElements )
97{
98 sal_uInt64 nSize =
99 static_cast<sal_uInt64>(SAL_SEQUENCE_HEADER_SIZE) +
100 (static_cast<sal_uInt64>(nElementSize) * static_cast<sal_uInt64>(nElements));
101 if (nSize > 0xffffffffU)
102 return 0;
103 else
104 return static_cast<sal_uInt32>(nSize);
105}
106
107
108inline uno_Sequence * createEmptySequence()
109{
110 osl_atomic_increment( &g_emptySeq.nRefCount );
111 return &g_emptySeq;
112}
113
114inline typelib_TypeDescriptionReference * _getVoidType()
115{
116 if (! g_pVoidType)
117 {
118 g_pVoidType = * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID );
119 }
121 return g_pVoidType;
122}
123
124inline void CONSTRUCT_EMPTY_ANY(uno_Any * pAny) {
125 pAny->pType = _getVoidType();
126#if OSL_DEBUG_LEVEL > 0
127 pAny->pData = reinterpret_cast<void *>(uintptr_t(0xdeadbeef));
128#else
129 pAny->pData = pAny;
130#endif
131}
132
133#define TYPE_ACQUIRE( pType ) \
134 osl_atomic_increment( &(pType)->nRefCount );
135
136
137extern "C" void * binuno_queryInterface(
138 void * pUnoI, typelib_TypeDescriptionReference * pDestType );
139
140
141inline bool _type_equals(
142 typelib_TypeDescriptionReference const * pType1, typelib_TypeDescriptionReference const * pType2 )
143
144{
145 return (pType1 == pType2 ||
146 (pType1->eTypeClass == pType2->eTypeClass &&
147 pType1->pTypeName->length == pType2->pTypeName->length &&
148 ::rtl_ustr_compare( pType1->pTypeName->buffer, pType2->pTypeName->buffer ) == 0));
149}
150
151}
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nElements
Definition: copy.hxx:39
void * p
struct _uno_Mapping uno_Mapping
struct _typelib_TypeDescription typelib_TypeDescription
struct _uno_Any uno_Any
void _release(void *p, uno_ReleaseFunc release)
Definition: prim.hxx:79
typelib_TypeDescriptionReference * g_pVoidType
Definition: data.cxx:37
void _acquire(void *p, uno_AcquireFunc acquire)
Definition: prim.hxx:64
typelib_TypeDescriptionReference * _getVoidType()
Definition: prim.hxx:114
void * _map(void *p, typelib_TypeDescriptionReference *pType, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping)
Definition: prim.hxx:39
uno_Sequence g_emptySeq
Definition: data.cxx:36
void CONSTRUCT_EMPTY_ANY(uno_Any *pAny)
Definition: prim.hxx:124
sal_uInt32 calcSeqMemSize(sal_Int32 nElementSize, sal_Int32 nElements)
Definition: prim.hxx:95
void * binuno_queryInterface(void *pUnoI, typelib_TypeDescriptionReference *pDestType)
Definition: data.cxx:40
bool _type_equals(typelib_TypeDescriptionReference const *pType1, typelib_TypeDescriptionReference const *pType2)
Definition: prim.hxx:141
uno_Sequence * createEmptySequence()
Definition: prim.hxx:108
typelib_TypeDescriptionReference **SAL_CALL typelib_static_type_getByTypeClass(typelib_TypeClass eTypeClass) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescriptionreference_acquire(typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Definition: typelib.cxx:2133
#define SAL_SEQUENCE_HEADER_SIZE