Files
libreoffice/cppu/source/uno/prim.hxx

159 lines
4.1 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-13 14:17:57 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2014-04-18 18:25:29 +02:00
#ifndef INCLUDED_CPPU_SOURCE_UNO_PRIM_HXX
#define INCLUDED_CPPU_SOURCE_UNO_PRIM_HXX
2000-09-18 14:29:57 +00:00
#include "typelib/typedescription.h"
#include "typelib/typeclass.h"
#include "uno/sequence2.h"
#include "uno/any2.h"
#include "uno/data.h"
#include "uno/mapping.h"
#include "uno/dispatcher.h"
2000-09-18 14:29:57 +00:00
#include "osl/interlck.h"
#include "osl/diagnose.h"
#include "rtl/ustring.hxx"
#include "rtl/alloc.h"
2000-09-18 14:29:57 +00:00
namespace cppu
{
2001-08-22 10:03:23 +00:00
extern uno_Sequence g_emptySeq;
extern typelib_TypeDescriptionReference * g_pVoidType;
2002-08-21 08:19:40 +00:00
inline void * _map(
2000-09-18 14:29:57 +00:00
void * p,
typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
2001-03-09 11:10:57 +00:00
uno_Mapping * mapping )
2000-09-18 14:29:57 +00:00
{
void * pRet = nullptr;
2000-09-18 14:29:57 +00:00
if (p)
{
if (pTypeDescr)
{
(*mapping->mapInterface)(
mapping, &pRet, p, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) );
2000-09-18 14:29:57 +00:00
}
else
{
TYPELIB_DANGER_GET( &pTypeDescr, pType );
(*mapping->mapInterface)(
mapping, &pRet, p, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTypeDescr) );
2000-09-18 14:29:57 +00:00
TYPELIB_DANGER_RELEASE( pTypeDescr );
}
}
return pRet;
}
inline void _acquire( void * p, uno_AcquireFunc acquire )
2000-09-18 14:29:57 +00:00
{
if (p)
{
if (acquire)
{
2000-09-18 14:29:57 +00:00
(*acquire)( p );
}
2000-09-18 14:29:57 +00:00
else
{
(*static_cast<uno_Interface *>(p)->acquire)( static_cast<uno_Interface *>(p) );
}
2000-09-18 14:29:57 +00:00
}
}
inline void _release( void * p, uno_ReleaseFunc release )
2000-09-18 14:29:57 +00:00
{
if (p)
2000-09-18 14:29:57 +00:00
{
if (release)
{
(*release)( p );
}
2000-09-18 14:29:57 +00:00
else
{
(*static_cast<uno_Interface *>(p)->release)( static_cast<uno_Interface *>(p) );
}
2000-09-18 14:29:57 +00:00
}
}
inline sal_uInt32 calcSeqMemSize(
sal_Int32 nElementSize, sal_Int32 nElements )
{
sal_uInt64 nSize =
(sal_uInt64) SAL_SEQUENCE_HEADER_SIZE +
((sal_uInt64) nElementSize * (sal_uInt64) nElements);
if (nSize > 0xffffffffU)
return 0;
else
return (sal_uInt32) nSize;
}
inline uno_Sequence * createEmptySequence()
2000-09-18 14:29:57 +00:00
{
osl_atomic_increment( &g_emptySeq.nRefCount );
2001-08-22 10:03:23 +00:00
return &g_emptySeq;
2000-09-18 14:29:57 +00:00
}
2002-08-21 08:19:40 +00:00
inline typelib_TypeDescriptionReference * _getVoidType()
2000-09-18 14:29:57 +00:00
{
2001-08-22 10:03:23 +00:00
if (! g_pVoidType)
2000-09-18 14:29:57 +00:00
{
2001-08-22 10:03:23 +00:00
g_pVoidType = * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID );
2000-09-18 14:29:57 +00:00
}
2001-08-22 10:03:23 +00:00
::typelib_typedescriptionreference_acquire( g_pVoidType );
return g_pVoidType;
2000-09-18 14:29:57 +00:00
}
inline void CONSTRUCT_EMPTY_ANY(uno_Any * pAny) {
pAny->pType = _getVoidType();
#if OSL_DEBUG_LEVEL > 0
pAny->pData = reinterpret_cast<void *>((uintptr_t)0xdeadbeef);
2000-09-18 14:29:57 +00:00
#else
pAny->pData = pAny;
2000-09-18 14:29:57 +00:00
#endif
}
2002-08-21 08:19:40 +00:00
#define TYPE_ACQUIRE( pType ) \
osl_atomic_increment( &(pType)->nRefCount );
2000-09-18 14:29:57 +00:00
extern "C" void * binuno_queryInterface(
void * pUnoI, typelib_TypeDescriptionReference * pDestType );
2000-09-18 14:29:57 +00:00
inline bool _type_equals(
2000-12-21 13:39:29 +00:00
typelib_TypeDescriptionReference * pType1, typelib_TypeDescriptionReference * pType2 )
2000-09-18 14:29:57 +00:00
{
return (pType1 == pType2 ||
(pType1->eTypeClass == pType2->eTypeClass &&
pType1->pTypeName->length == pType2->pTypeName->length &&
::rtl_ustr_compare( pType1->pTypeName->buffer, pType2->pTypeName->buffer ) == 0));
}
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */