1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #ifndef _TYPELIB_TYPEDESCRIPTION_HXX_
24 #define _TYPELIB_TYPEDESCRIPTION_HXX_
25
26 #include <rtl/alloc.h>
27 #include <rtl/ustring.hxx>
28 #include <com/sun/star/uno/Type.h>
29 #ifndef _TYPELIB_TYPEDESCRIPTION_H
30 #include <typelib/typedescription.h>
31 #endif
32
33
34 namespace com
35 {
36 namespace sun
37 {
38 namespace star
39 {
40 namespace uno
41 {
42
43 /** C++ wrapper for typelib_TypeDescription.
44 Constructors by name, type, type description reference will get the full type description.
45
46 @see typelib_TypeDescription
47 */
48 class TypeDescription
49 {
50 /** C typelib type description
51 */
52 mutable typelib_TypeDescription * _pTypeDescr;
53
54 public:
55 // these are here to force memory de/allocation to sal lib.
56 /** @internal */
operator new(size_t nSize)57 inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () )
58 { return ::rtl_allocateMemory( nSize ); }
59 /** @internal */
operator delete(void * pMem)60 inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () )
61 { ::rtl_freeMemory( pMem ); }
62 /** @internal */
operator new(size_t,void * pMem)63 inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () )
64 { return pMem; }
65 /** @internal */
operator delete(void *,void *)66 inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () )
67 {}
68
69 /** Constructor:
70
71 @param pTypeDescr a type description
72 */
73 inline TypeDescription( typelib_TypeDescription * pTypeDescr = 0 ) SAL_THROW( () );
74 /** Constructor:
75
76 @param pTypeDescrRef a type description reference
77 */
78 inline TypeDescription( typelib_TypeDescriptionReference * pTypeDescrRef ) SAL_THROW( () );
79 /** Constructor:
80
81 @param rType a type
82 */
83 inline TypeDescription( const ::com::sun::star::uno::Type & rType ) SAL_THROW( () );
84 /** Copy constructor:
85
86 @param rDescr another TypeDescription
87 */
88 inline TypeDescription( const TypeDescription & rDescr ) SAL_THROW( () );
89 /** Constructor:
90
91 @param pTypeName a type name
92 */
93 inline TypeDescription( rtl_uString * pTypeName ) SAL_THROW( () );
94 /** Constructor:
95
96 @param rTypeName a type name
97 */
98 inline TypeDescription( const ::rtl::OUString & rTypeName ) SAL_THROW( () );
99 /** Destructor: releases type description
100 */
101 inline ~TypeDescription() SAL_THROW( () );
102
103 /** Assignment operator: acquires given type description and releases a set one.
104
105 @param pTypeDescr another type description
106 @return this TypeDescription
107 */
108 inline TypeDescription & SAL_CALL operator = ( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () );
109 /** Assignment operator: acquires given type description and releases a set one.
110
111 @param rTypeDescr another type description
112 @return this TypeDescription
113 */
operator =(const TypeDescription & rTypeDescr)114 inline TypeDescription & SAL_CALL operator =( const TypeDescription & rTypeDescr ) SAL_THROW( () )
115 { return this->operator =( rTypeDescr.get() ); }
116
117 /** Tests whether two type descriptions are equal.
118
119 @param pTypeDescr another type description
120 @return true, if both type descriptions are equal, false otherwise
121 */
122 inline sal_Bool SAL_CALL equals( const typelib_TypeDescription * pTypeDescr ) const SAL_THROW( () );
123 /** Tests whether two type descriptions are equal.
124
125 @param rTypeDescr another type description
126 @return true, if both type descriptions are equal, false otherwise
127 */
equals(const TypeDescription & rTypeDescr) const128 inline sal_Bool SAL_CALL equals( const TypeDescription & rTypeDescr ) const SAL_THROW( () )
129 { return equals( rTypeDescr._pTypeDescr ); }
130
131 /** Makes stored type description complete.
132 */
133 inline void SAL_CALL makeComplete() const SAL_THROW( () );
134
135 /** Gets the UNacquired type description pointer.
136
137 @return stored pointer of type description
138 */
get() const139 inline typelib_TypeDescription * SAL_CALL get() const SAL_THROW( () )
140 { return _pTypeDescr; }
141 /** Tests if a type description is set.
142
143 @return true, if a type description is set, false otherwise
144 */
is() const145 inline sal_Bool SAL_CALL is() const SAL_THROW( () )
146 { return (_pTypeDescr != 0); }
147 };
148 //__________________________________________________________________________________________________
TypeDescription(typelib_TypeDescription * pTypeDescr)149 inline TypeDescription::TypeDescription( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () )
150 : _pTypeDescr( pTypeDescr )
151 {
152 if (_pTypeDescr)
153 typelib_typedescription_acquire( _pTypeDescr );
154 }
155 //__________________________________________________________________________________________________
TypeDescription(typelib_TypeDescriptionReference * pTypeDescrRef)156 inline TypeDescription::TypeDescription( typelib_TypeDescriptionReference * pTypeDescrRef ) SAL_THROW( () )
157 : _pTypeDescr( 0 )
158 {
159 if (pTypeDescrRef)
160 typelib_typedescriptionreference_getDescription( &_pTypeDescr, pTypeDescrRef );
161 }
162 //__________________________________________________________________________________________________
TypeDescription(const::com::sun::star::uno::Type & rType)163 inline TypeDescription::TypeDescription( const ::com::sun::star::uno::Type & rType ) SAL_THROW( () )
164 : _pTypeDescr( 0 )
165 {
166 if (rType.getTypeLibType())
167 typelib_typedescriptionreference_getDescription( &_pTypeDescr, rType.getTypeLibType() );
168 }
169 //__________________________________________________________________________________________________
TypeDescription(const TypeDescription & rTypeDescr)170 inline TypeDescription::TypeDescription( const TypeDescription & rTypeDescr ) SAL_THROW( () )
171 : _pTypeDescr( rTypeDescr._pTypeDescr )
172 {
173 if (_pTypeDescr)
174 typelib_typedescription_acquire( _pTypeDescr );
175 }
176 //__________________________________________________________________________________________________
TypeDescription(rtl_uString * pTypeName)177 inline TypeDescription::TypeDescription( rtl_uString * pTypeName ) SAL_THROW( () )
178 : _pTypeDescr( 0 )
179 {
180 typelib_typedescription_getByName( &_pTypeDescr , pTypeName );
181 }
182 //__________________________________________________________________________________________________
TypeDescription(const::rtl::OUString & rTypeName)183 inline TypeDescription::TypeDescription( const ::rtl::OUString & rTypeName ) SAL_THROW( () )
184 : _pTypeDescr( 0 )
185 {
186 typelib_typedescription_getByName( &_pTypeDescr , rTypeName.pData );
187 }
188 //__________________________________________________________________________________________________
~TypeDescription()189 inline TypeDescription::~TypeDescription() SAL_THROW( () )
190 {
191 if (_pTypeDescr)
192 typelib_typedescription_release( _pTypeDescr );
193 }
194 //__________________________________________________________________________________________________
operator =(typelib_TypeDescription * pTypeDescr)195 inline TypeDescription & TypeDescription::operator = ( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () )
196 {
197 if (pTypeDescr)
198 typelib_typedescription_acquire( pTypeDescr );
199 if (_pTypeDescr)
200 typelib_typedescription_release( _pTypeDescr );
201 _pTypeDescr = pTypeDescr;
202 return *this;
203 }
204 //__________________________________________________________________________________________________
equals(const typelib_TypeDescription * pTypeDescr) const205 inline sal_Bool TypeDescription::equals( const typelib_TypeDescription * pTypeDescr ) const SAL_THROW( () )
206 {
207 return (_pTypeDescr && pTypeDescr &&
208 typelib_typedescription_equals( _pTypeDescr, pTypeDescr ));
209 }
210 //__________________________________________________________________________________________________
makeComplete() const211 inline void TypeDescription::makeComplete() const SAL_THROW( () )
212 {
213 if (_pTypeDescr && !_pTypeDescr->bComplete)
214 ::typelib_typedescription_complete( &_pTypeDescr );
215 }
216
217 }
218 }
219 }
220 }
221
222 #endif
223