LibreOffice
LibreOffice 5.2 SDK C/C++ API Reference
typedescription.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 #ifndef INCLUDED_TYPELIB_TYPEDESCRIPTION_HXX
20 #define INCLUDED_TYPELIB_TYPEDESCRIPTION_HXX
21 
22 #include <sal/config.h>
23 
24 #include <cstddef>
25 
26 #include <rtl/alloc.h>
27 #include <rtl/ustring.hxx>
28 #include <com/sun/star/uno/Type.h>
30 
31 
32 namespace com
33 {
34 namespace sun
35 {
36 namespace star
37 {
38 namespace uno
39 {
40 
47 {
50  mutable typelib_TypeDescription * _pTypeDescr;
51 
52 public:
54  // these are here to force memory de/allocation to sal lib.
55  inline static void * SAL_CALL operator new ( size_t nSize )
56  { return ::rtl_allocateMemory( nSize ); }
57  inline static void SAL_CALL operator delete ( void * pMem )
58  { ::rtl_freeMemory( pMem ); }
59  inline static void * SAL_CALL operator new ( size_t, void * pMem )
60  { return pMem; }
61  inline static void SAL_CALL operator delete ( void *, void * )
62  {}
64 
69  inline TypeDescription( typelib_TypeDescription * pTypeDescr = NULL );
74  inline TypeDescription( typelib_TypeDescriptionReference * pTypeDescrRef );
79  inline TypeDescription( const css::uno::Type & rType );
84  inline TypeDescription( const TypeDescription & rDescr );
89  inline TypeDescription( rtl_uString * pTypeName );
94  inline TypeDescription( const ::rtl::OUString & rTypeName );
97  inline ~TypeDescription();
98 
104  inline TypeDescription & SAL_CALL operator = ( typelib_TypeDescription * pTypeDescr );
110  inline TypeDescription & SAL_CALL operator =( const TypeDescription & rTypeDescr )
111  { return this->operator =( rTypeDescr.get() ); }
112 
118  inline bool SAL_CALL equals( const typelib_TypeDescription * pTypeDescr ) const;
124  inline bool SAL_CALL equals( const TypeDescription & rTypeDescr ) const
125  { return equals( rTypeDescr._pTypeDescr ); }
126 
129  inline void SAL_CALL makeComplete() const;
130 
135  inline typelib_TypeDescription * SAL_CALL get() const
136  { return _pTypeDescr; }
141  inline bool SAL_CALL is() const
142  { return (_pTypeDescr != NULL); }
143 };
144 
146  : _pTypeDescr( pTypeDescr )
147 {
148  if (_pTypeDescr)
149  typelib_typedescription_acquire( _pTypeDescr );
150 }
151 
153  : _pTypeDescr( NULL )
154 {
155  if (pTypeDescrRef)
156  typelib_typedescriptionreference_getDescription( &_pTypeDescr, pTypeDescrRef );
157 }
158 
159 inline TypeDescription::TypeDescription( const css::uno::Type & rType )
160  : _pTypeDescr( NULL )
161 {
162  if (rType.getTypeLibType())
163  typelib_typedescriptionreference_getDescription( &_pTypeDescr, rType.getTypeLibType() );
164 }
165 
167  : _pTypeDescr( rTypeDescr._pTypeDescr )
168 {
169  if (_pTypeDescr)
170  typelib_typedescription_acquire( _pTypeDescr );
171 }
172 
173 inline TypeDescription::TypeDescription( rtl_uString * pTypeName )
174  : _pTypeDescr( NULL )
175 {
176  typelib_typedescription_getByName( &_pTypeDescr , pTypeName );
177 }
178 
179 inline TypeDescription::TypeDescription( const ::rtl::OUString & rTypeName )
180  : _pTypeDescr( NULL )
181 {
182  typelib_typedescription_getByName( &_pTypeDescr , rTypeName.pData );
183 }
184 
186 {
187  if (_pTypeDescr)
188  typelib_typedescription_release( _pTypeDescr );
189 }
190 
192 {
193  if (pTypeDescr)
194  typelib_typedescription_acquire( pTypeDescr );
195  if (_pTypeDescr)
196  typelib_typedescription_release( _pTypeDescr );
197  _pTypeDescr = pTypeDescr;
198  return *this;
199 }
200 
201 inline bool TypeDescription::equals( const typelib_TypeDescription * pTypeDescr ) const
202 {
203  return (_pTypeDescr && pTypeDescr &&
204  typelib_typedescription_equals( _pTypeDescr, pTypeDescr ));
205 }
206 
207 inline void TypeDescription::makeComplete() const
208 {
209  if (_pTypeDescr && !_pTypeDescr->bComplete)
210  ::typelib_typedescription_complete( &_pTypeDescr );
211 }
212 
213 }
214 }
215 }
216 }
217 
218 #endif
219 
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
C++ wrapper for typelib_TypeDescription.
Definition: typedescription.hxx:46
CPPU_DLLPUBLIC void typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
Retrieves the type description for a given reference.
CPPU_DLLPUBLIC sal_Bool typelib_typedescription_complete(typelib_TypeDescription **ppTypeDescr) SAL_THROW_EXTERN_C()
Completes a typedescription to be used for, e.g., marshalling values.
TypeDescription(typelib_TypeDescription *pTypeDescr=NULL)
Constructor:
Definition: typedescription.hxx:145
CPPU_DLLPUBLIC void typelib_typedescription_acquire(typelib_TypeDescription *pDesc) SAL_THROW_EXTERN_C()
Increments reference count of given type description.
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
typelib_TypeDescription * get() const
Gets the UNacquired type description pointer.
Definition: typedescription.hxx:135
Definition: types.h:391
~TypeDescription()
Destructor: releases type description.
Definition: typedescription.hxx:185
CPPU_DLLPUBLIC void typelib_typedescription_release(typelib_TypeDescription *pDesc) SAL_THROW_EXTERN_C()
Decrements reference count of given type.
bool equals(const typelib_TypeDescription *pTypeDescr) const
Tests whether two type descriptions are equal.
Definition: typedescription.hxx:201
bool equals(const TypeDescription &rTypeDescr) const
Tests whether two type descriptions are equal.
Definition: typedescription.hxx:124
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescription typelib_TypeDescription
Full type description of a type.
void makeComplete() const
Makes stored type description complete.
Definition: typedescription.hxx:207
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescriptionReference typelib_TypeDescriptionReference
Holds a weak reference to a type description.
TypeDescription & operator=(typelib_TypeDescription *pTypeDescr)
Assignment operator: acquires given type description and releases a set one.
Definition: typedescription.hxx:191
bool is() const
Tests if a type description is set.
Definition: typedescription.hxx:141
CPPU_DLLPUBLIC void typelib_typedescription_getByName(typelib_TypeDescription **ppRet, rtl_uString *pName) SAL_THROW_EXTERN_C()
Retrieves a type description via its fully qualified name.
CPPU_DLLPUBLIC sal_Bool typelib_typedescription_equals(const typelib_TypeDescription *p1, const typelib_TypeDescription *p2) SAL_THROW_EXTERN_C()
Tests whether two types descriptions are equal, i.e.