1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 * This file is part of LibreOffice published API.
23 #ifndef INCLUDED_TYPELIB_TYPEDESCRIPTION_HXX
24 #define INCLUDED_TYPELIB_TYPEDESCRIPTION_HXX
26 #include "sal/config.h"
30 #include "rtl/alloc.h"
31 #include "rtl/ustring.hxx"
32 #include "com/sun/star/uno/Type.h"
33 #include "typelib/typedescription.h"
45 /** C++ wrapper for typelib_TypeDescription.
46 Constructors by name, type, type description reference will get the full type description.
48 @see typelib_TypeDescription
52 /** C typelib type description
54 mutable typelib_TypeDescription
* _pTypeDescr
;
58 // these are here to force memory de/allocation to sal lib.
59 static void * SAL_CALL
operator new ( size_t nSize
)
60 { return ::rtl_allocateMemory( nSize
); }
61 static void SAL_CALL
operator delete ( void * pMem
)
62 { ::rtl_freeMemory( pMem
); }
63 static void * SAL_CALL
operator new ( size_t, void * pMem
)
65 static void SAL_CALL
operator delete ( void *, void * )
71 @param pTypeDescr a type description
73 inline TypeDescription( typelib_TypeDescription
* pTypeDescr
= NULL
);
76 @param pTypeDescrRef a type description reference
78 inline TypeDescription( typelib_TypeDescriptionReference
* pTypeDescrRef
);
83 inline TypeDescription( const css::uno::Type
& rType
);
86 @param rDescr another TypeDescription
88 inline TypeDescription( const TypeDescription
& rDescr
);
89 #if defined LIBO_INTERNAL_ONLY
90 TypeDescription(TypeDescription
&& other
) noexcept
: _pTypeDescr(other
._pTypeDescr
)
91 { other
._pTypeDescr
= nullptr; }
95 @param pTypeName a type name
97 inline TypeDescription( rtl_uString
* pTypeName
);
100 @param rTypeName a type name
102 inline TypeDescription( const ::rtl::OUString
& rTypeName
);
103 /** Destructor: releases type description
105 inline ~TypeDescription();
107 /** Assignment operator: acquires given type description and releases a set one.
109 @param pTypeDescr another type description
110 @return this TypeDescription
112 inline TypeDescription
& SAL_CALL
operator = ( typelib_TypeDescription
* pTypeDescr
);
113 /** Assignment operator: acquires given type description and releases a set one.
115 @param rTypeDescr another type description
116 @return this TypeDescription
118 TypeDescription
& SAL_CALL
operator =( const TypeDescription
& rTypeDescr
)
119 { return this->operator =( rTypeDescr
.get() ); }
121 #if defined LIBO_INTERNAL_ONLY
122 TypeDescription
& operator =(TypeDescription
&& other
) noexcept
{
123 if (_pTypeDescr
!= nullptr) {
124 typelib_typedescription_release(_pTypeDescr
);
126 _pTypeDescr
= other
._pTypeDescr
;
127 other
._pTypeDescr
= nullptr;
132 /** Tests whether two type descriptions are equal.
134 @param pTypeDescr another type description
135 @return true, if both type descriptions are equal, false otherwise
137 inline bool SAL_CALL
equals( const typelib_TypeDescription
* pTypeDescr
) const;
138 /** Tests whether two type descriptions are equal.
140 @param rTypeDescr another type description
141 @return true, if both type descriptions are equal, false otherwise
143 bool SAL_CALL
equals( const TypeDescription
& rTypeDescr
) const
144 { return equals( rTypeDescr
._pTypeDescr
); }
146 /** Makes stored type description complete.
148 inline void SAL_CALL
makeComplete() const;
150 /** Gets the UNacquired type description pointer.
152 @return stored pointer of type description
154 typelib_TypeDescription
* SAL_CALL
get() const
155 { return _pTypeDescr
; }
156 /** Tests if a type description is set.
158 @return true, if a type description is set, false otherwise
160 bool SAL_CALL
is() const
161 { return (_pTypeDescr
!= NULL
); }
164 inline TypeDescription::TypeDescription( typelib_TypeDescription
* pTypeDescr
)
165 : _pTypeDescr( pTypeDescr
)
168 typelib_typedescription_acquire( _pTypeDescr
);
171 inline TypeDescription::TypeDescription( typelib_TypeDescriptionReference
* pTypeDescrRef
)
172 : _pTypeDescr( NULL
)
175 typelib_typedescriptionreference_getDescription( &_pTypeDescr
, pTypeDescrRef
);
178 inline TypeDescription::TypeDescription( const css::uno::Type
& rType
)
179 : _pTypeDescr( NULL
)
181 if (rType
.getTypeLibType())
182 typelib_typedescriptionreference_getDescription( &_pTypeDescr
, rType
.getTypeLibType() );
185 inline TypeDescription::TypeDescription( const TypeDescription
& rTypeDescr
)
186 : _pTypeDescr( rTypeDescr
._pTypeDescr
)
189 typelib_typedescription_acquire( _pTypeDescr
);
192 inline TypeDescription::TypeDescription( rtl_uString
* pTypeName
)
193 : _pTypeDescr( NULL
)
195 typelib_typedescription_getByName( &_pTypeDescr
, pTypeName
);
198 inline TypeDescription::TypeDescription( const ::rtl::OUString
& rTypeName
)
199 : _pTypeDescr( NULL
)
201 typelib_typedescription_getByName( &_pTypeDescr
, rTypeName
.pData
);
204 inline TypeDescription::~TypeDescription()
207 typelib_typedescription_release( _pTypeDescr
);
210 inline TypeDescription
& TypeDescription::operator = ( typelib_TypeDescription
* pTypeDescr
)
213 typelib_typedescription_acquire( pTypeDescr
);
215 typelib_typedescription_release( _pTypeDescr
);
216 _pTypeDescr
= pTypeDescr
;
220 inline bool TypeDescription::equals( const typelib_TypeDescription
* pTypeDescr
) const
222 return (_pTypeDescr
&& pTypeDescr
&&
223 typelib_typedescription_equals( _pTypeDescr
, pTypeDescr
));
226 inline void TypeDescription::makeComplete() const
228 if (_pTypeDescr
&& !_pTypeDescr
->bComplete
)
229 ::typelib_typedescription_complete( &_pTypeDescr
);
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */