LibreOffice LibreOffice 4.1 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Reference.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 _COM_SUN_STAR_UNO_REFERENCE_HXX_
20 #define _COM_SUN_STAR_UNO_REFERENCE_HXX_
21
22 #include <com/sun/star/uno/Reference.h>
23 #include <com/sun/star/uno/RuntimeException.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
25 #include <com/sun/star/uno/genfunc.hxx>
26
27 namespace com
28 {
29 namespace sun
30 {
31 namespace star
32 {
33 namespace uno
34 {
35
36 //__________________________________________________________________________________________________
37 inline XInterface * BaseReference::iquery(
38 XInterface * pInterface, const Type & rType )
39 SAL_THROW( (RuntimeException) )
40 {
41 if (pInterface)
42 {
43 Any aRet( pInterface->queryInterface( rType ) );
44 if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass)
45 {
46 XInterface * pRet = static_cast< XInterface * >( aRet.pReserved );
47 aRet.pReserved = 0;
48 return pRet;
49 }
50 }
51 return 0;
52 }
53 //__________________________________________________________________________________________________
54 template< class interface_type >
55 inline XInterface * Reference< interface_type >::iquery(
56 XInterface * pInterface ) SAL_THROW( (RuntimeException) )
57 {
58 return BaseReference::iquery(pInterface, interface_type::static_type());
59 }
60 #ifndef EXCEPTIONS_OFF
61 extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg(
62 typelib_TypeDescriptionReference * pType )
63 SAL_THROW_EXTERN_C();
64 extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg(
65 typelib_TypeDescriptionReference * pType )
66 SAL_THROW_EXTERN_C();
67 //__________________________________________________________________________________________________
68 inline XInterface * BaseReference::iquery_throw(
69 XInterface * pInterface, const Type & rType )
70 SAL_THROW( (RuntimeException) )
71 {
72 XInterface * pQueried = iquery( pInterface, rType );
73 if (pQueried)
74 return pQueried;
75 throw RuntimeException(
76 ::rtl::OUString( cppu_unsatisfied_iquery_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ),
77 Reference< XInterface >( pInterface ) );
78 }
79 //__________________________________________________________________________________________________
80 template< class interface_type >
81 inline XInterface * Reference< interface_type >::iquery_throw(
82 XInterface * pInterface ) SAL_THROW( (RuntimeException) )
83 {
84 return BaseReference::iquery_throw(
85 pInterface, interface_type::static_type());
86 }
87 //__________________________________________________________________________________________________
88 template< class interface_type >
89 inline interface_type * Reference< interface_type >::iset_throw(
90 interface_type * pInterface ) SAL_THROW( (RuntimeException) )
91 {
92 if (pInterface)
93 {
94 castToXInterface(pInterface)->acquire();
95 return pInterface;
96 }
97 throw RuntimeException(
98 ::rtl::OUString( cppu_unsatisfied_iset_msg( interface_type::static_type().getTypeLibType() ), SAL_NO_ACQUIRE ),
99 NULL );
100 }
101 #endif
102
103 //__________________________________________________________________________________________________
104 template< class interface_type >
105 inline Reference< interface_type >::~Reference() SAL_THROW(())
106 {
107 if (_pInterface)
108 _pInterface->release();
109 }
110 //__________________________________________________________________________________________________
111 template< class interface_type >
112 inline Reference< interface_type >::Reference() SAL_THROW(())
113 {
114 _pInterface = 0;
115 }
116 //__________________________________________________________________________________________________
117 template< class interface_type >
118 inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW(())
119 {
120 _pInterface = rRef._pInterface;
121 if (_pInterface)
122 _pInterface->acquire();
123 }
124 //__________________________________________________________________________________________________
125 template< class interface_type > template< class derived_type >
126 inline Reference< interface_type >::Reference(
127 const Reference< derived_type > & rRef,
128 typename detail::UpCast< interface_type, derived_type >::t )
129 SAL_THROW(())
130 {
131 interface_type * p = rRef.get();
132 _pInterface = p;
133 if (_pInterface)
134 _pInterface->acquire();
135 }
136 //__________________________________________________________________________________________________
137 template< class interface_type >
138 inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW(())
139 {
140 _pInterface = castToXInterface(pInterface);
141 if (_pInterface)
142 _pInterface->acquire();
143 }
144 //__________________________________________________________________________________________________
145 template< class interface_type >
146 inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
147 {
148 _pInterface = castToXInterface(pInterface);
149 }
150 //__________________________________________________________________________________________________
151 template< class interface_type >
152 inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
153 {
154 _pInterface = castToXInterface(pInterface);
155 }
156 //__________________________________________________________________________________________________
157 template< class interface_type >
158 inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
159 {
160 _pInterface = iquery( rRef.get() );
161 }
162 //__________________________________________________________________________________________________
163 template< class interface_type >
164 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
165 {
166 _pInterface = iquery( pInterface );
167 }
168 //__________________________________________________________________________________________________
169 template< class interface_type >
170 inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_Query ) SAL_THROW( (RuntimeException) )
171 {
172 _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
173 ? iquery( static_cast< XInterface * >( rAny.pReserved ) ) : 0);
174 }
175 #ifndef EXCEPTIONS_OFF
176 //__________________________________________________________________________________________________
177 template< class interface_type >
178 inline Reference< interface_type >::Reference( const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
179 {
180 _pInterface = iquery_throw( rRef.get() );
181 }
182 //__________________________________________________________________________________________________
183 template< class interface_type >
184 inline Reference< interface_type >::Reference( XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
185 {
186 _pInterface = iquery_throw( pInterface );
187 }
188 //__________________________________________________________________________________________________
189 template< class interface_type >
190 inline Reference< interface_type >::Reference( const Any & rAny, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
191 {
192 _pInterface = iquery_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass
193 ? static_cast< XInterface * >( rAny.pReserved ) : 0 );
194 }
195 //__________________________________________________________________________________________________
196 template< class interface_type >
197 inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
198 {
199 _pInterface = castToXInterface( iset_throw( rRef.get() ) );
200 }
201 //__________________________________________________________________________________________________
202 template< class interface_type >
203 inline Reference< interface_type >::Reference( interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
204 {
205 _pInterface = castToXInterface( iset_throw( pInterface ) );
206 }
207 #endif
208
209 //__________________________________________________________________________________________________
210 template< class interface_type >
211 inline void Reference< interface_type >::clear() SAL_THROW(())
212 {
213 if (_pInterface)
214 {
215 XInterface * const pOld = _pInterface;
216 _pInterface = 0;
217 pOld->release();
218 }
219 }
220 //__________________________________________________________________________________________________
221 template< class interface_type >
222 inline sal_Bool Reference< interface_type >::set(
223 interface_type * pInterface ) SAL_THROW(())
224 {
225 if (pInterface)
226 castToXInterface(pInterface)->acquire();
227 XInterface * const pOld = _pInterface;
228 _pInterface = castToXInterface(pInterface);
229 if (pOld)
230 pOld->release();
231 return (0 != pInterface);
232 }
233 //__________________________________________________________________________________________________
234 template< class interface_type >
235 inline sal_Bool Reference< interface_type >::set(
236 interface_type * pInterface, __sal_NoAcquire ) SAL_THROW(())
237 {
238 XInterface * const pOld = _pInterface;
239 _pInterface = castToXInterface(pInterface);
240 if (pOld)
241 pOld->release();
242 return (0 != pInterface);
243 }
244 //__________________________________________________________________________________________________
245 template< class interface_type >
246 inline sal_Bool Reference< interface_type >::set(
247 interface_type * pInterface, UnoReference_NoAcquire ) SAL_THROW(())
248 {
249 return set( pInterface, SAL_NO_ACQUIRE );
250 }
251
252 //__________________________________________________________________________________________________
253 template< class interface_type >
254 inline sal_Bool Reference< interface_type >::set(
255 const Reference< interface_type > & rRef ) SAL_THROW(())
256 {
257 return set( castFromXInterface( rRef._pInterface ) );
258 }
259 //__________________________________________________________________________________________________
260 template< class interface_type >
261 inline sal_Bool Reference< interface_type >::set(
262 XInterface * pInterface, UnoReference_Query ) SAL_THROW( (RuntimeException) )
263 {
264 return set( castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
265 }
266 //__________________________________________________________________________________________________
267 template< class interface_type >
268 inline sal_Bool Reference< interface_type >::set(
269 const BaseReference & rRef, UnoReference_Query ) SAL_THROW( (RuntimeException) )
270 {
271 return set( castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
272 }
273
274 //______________________________________________________________________________
275 template< class interface_type >
276 inline bool Reference< interface_type >::set(
277 Any const & rAny, UnoReference_Query )
278 {
279 return set(
280 castFromXInterface(
281 iquery(
282 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
283 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
284 SAL_NO_ACQUIRE );
285 }
286
287 #ifndef EXCEPTIONS_OFF
288 //__________________________________________________________________________________________________
289 template< class interface_type >
290 inline void Reference< interface_type >::set(
291 XInterface * pInterface, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
292 {
293 set( castFromXInterface(iquery_throw( pInterface )), SAL_NO_ACQUIRE );
294 }
295 //__________________________________________________________________________________________________
296 template< class interface_type >
297 inline void Reference< interface_type >::set(
298 const BaseReference & rRef, UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) )
299 {
300 set( castFromXInterface(iquery_throw( rRef.get() )), SAL_NO_ACQUIRE );
301 }
302
303 //______________________________________________________________________________
304 template< class interface_type >
305 inline void Reference< interface_type >::set(
306 Any const & rAny, UnoReference_QueryThrow )
307 {
308 set( castFromXInterface(
309 iquery_throw(
310 rAny.pType->eTypeClass == typelib_TypeClass_INTERFACE
311 ? static_cast< XInterface * >( rAny.pReserved ) : 0 )),
312 SAL_NO_ACQUIRE );
313 }
314 //__________________________________________________________________________________________________
315 template< class interface_type >
316 inline void Reference< interface_type >::set(
317 interface_type * pInterface, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
318 {
319 set( iset_throw( pInterface ), SAL_NO_ACQUIRE );
320 }
321 //__________________________________________________________________________________________________
322 template< class interface_type >
323 inline void Reference< interface_type >::set(
324 const Reference< interface_type > & rRef, UnoReference_SetThrow ) SAL_THROW( (RuntimeException) )
325 {
326 set( rRef.get(), UNO_SET_THROW );
327 }
328
329 #endif
330
331 //__________________________________________________________________________________________________
332 template< class interface_type >
333 inline Reference< interface_type > & Reference< interface_type >::operator = (
334 interface_type * pInterface ) SAL_THROW(())
335 {
336 set( pInterface );
337 return *this;
338 }
339 //__________________________________________________________________________________________________
340 template< class interface_type >
341 inline Reference< interface_type > & Reference< interface_type >::operator = (
342 const Reference< interface_type > & rRef ) SAL_THROW(())
343 {
344 set( castFromXInterface( rRef._pInterface ) );
345 return *this;
346 }
347
348 //__________________________________________________________________________________________________
349 template< class interface_type >
350 inline Reference< interface_type > Reference< interface_type >::query(
351 const BaseReference & rRef ) SAL_THROW( (RuntimeException) )
352 {
353 return Reference< interface_type >(
354 castFromXInterface(iquery( rRef.get() )), SAL_NO_ACQUIRE );
355 }
356 //__________________________________________________________________________________________________
357 template< class interface_type >
358 inline Reference< interface_type > Reference< interface_type >::query(
359 XInterface * pInterface ) SAL_THROW( (RuntimeException) )
360 {
361 return Reference< interface_type >(
362 castFromXInterface(iquery( pInterface )), SAL_NO_ACQUIRE );
363 }
364
365 //##################################################################################################
366
367 //__________________________________________________________________________________________________
368 inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW(())
369 {
370 if (_pInterface == pInterface)
371 return sal_True;
372 #ifndef EXCEPTIONS_OFF
373 try
374 {
375 #endif
376 // only the query to XInterface must return the same pointer if they belong to same objects
377 Reference< XInterface > x1( _pInterface, UNO_QUERY );
378 Reference< XInterface > x2( pInterface, UNO_QUERY );
379 return (x1._pInterface == x2._pInterface);
380 #ifndef EXCEPTIONS_OFF
381 }
382 catch (RuntimeException &)
383 {
384 return sal_False;
385 }
386 #endif
387 }
388
389 //______________________________________________________________________________
390 inline sal_Bool BaseReference::operator < (
391 const BaseReference & rRef ) const SAL_THROW(())
392 {
393 if (_pInterface == rRef._pInterface)
394 return sal_False;
395 #if ! defined EXCEPTIONS_OFF
396 try
397 {
398 #endif
399 // only the query to XInterface must return the same pointer:
400 Reference< XInterface > x1( _pInterface, UNO_QUERY );
401 Reference< XInterface > x2( rRef, UNO_QUERY );
402 return (x1._pInterface < x2._pInterface);
403 #if ! defined EXCEPTIONS_OFF
404 }
405 catch (RuntimeException &)
406 {
407 return sal_False;
408 }
409 #endif
410 }
411
412 //__________________________________________________________________________________________________
413 inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW(())
414 {
415 return (! operator == ( pInterface ));
416 }
417 //__________________________________________________________________________________________________
418 inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW(())
419 {
420 return operator == ( rRef._pInterface );
421 }
422 //__________________________________________________________________________________________________
423 inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW(())
424 {
425 return (! operator == ( rRef._pInterface ));
426 }
427
428 }
429 }
430 }
431 }
432
433 #endif
434
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::BaseReference
This base class serves as a base class for all template reference classes and has been introduced due...
Definition: Reference.h:54
com::sun::star::uno::Reference::Reference
Reference()
Default Constructor: Sets null reference.
Definition: Reference.hxx:112
com::sun::star::uno::Reference::get
interface_type * get() const
Gets interface pointer.
Definition: Reference.h:419
com::sun::star::uno::UNO_QUERY
This enum value can be used for implicit interface query.
Definition: Reference.h:140
com::sun::star::uno::UnoReference_NoAcquire
UnoReference_NoAcquire
Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface.
Definition: Reference.h:43
com::sun::star::uno::Reference
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:32
com::sun::star::uno::Reference::~Reference
~Reference()
Destructor: Releases interface if set.
Definition: Reference.hxx:105
SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:374
com::sun::star::uno::BaseReference::iquery
static XInterface * iquery(XInterface *pInterface, const Type &rType)
Queries given interface for type rType.
Definition: Reference.hxx:37
genfunc.hxx
com::sun::star::uno::BaseReference::iquery_throw
static XInterface * iquery_throw(XInterface *pInterface, const Type &rType)
Queries given interface for type rType.
Definition: Reference.hxx:68
com::sun::star::uno::operator==
sal_Bool operator==(const Any &rAny, const C &value)
Template equality operator: compares set value of left side any to right side value.
Definition: Any.hxx:547
com::sun::star::uno::BaseReference::_pInterface
XInterface * _pInterface
the interface pointer
Definition: Reference.h:59
com::sun::star::uno::Reference::set
sal_Bool set(const Reference< interface_type > &rRef)
Sets the given interface.
Definition: Reference.hxx:254
com::sun::star::uno::cppu_unsatisfied_iset_msg
rtl_uString * cppu_unsatisfied_iset_msg(typelib_TypeDescriptionReference *pType) SAL_THROW_EXTERN_C()
com::sun::star::uno::Reference::query
static Reference< interface_type > query(const BaseReference &rRef)
Queries given interface reference for type interface_type.
Definition: Reference.hxx:350
com::sun::star::uno::UnoReference_Query
UnoReference_Query
Enum defining UNO_QUERY for implicit interface query.
Definition: Reference.h:136
typelib_TypeClass_INTERFACE
type class of interface
Definition: typeclass.h:73
com::sun::star::uno::UnoReference_SetThrow
UnoReference_SetThrow
Enum defining UNO_SET_THROW for throwing if attempts are made to assign a null interface.
Definition: Reference.h:157
_uno_Any::pReserved
void * pReserved
reserved space for storing value
Definition: any2.h:52
sal_Bool
unsigned char sal_Bool
Definition: types.h:37
sal_False
#define sal_False
Definition: types.h:38
_uno_Any::pType
struct _typelib_TypeDescriptionReference * pType
type of value
Definition: any2.h:44
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:370
com::sun::star::uno::Reference::clear
void clear()
Clears reference, i.e.
Definition: Reference.hxx:211
com::sun::star::uno::BaseReference::operator!=
sal_Bool operator!=(XInterface *pInterface) const
Unequality operator: compares two interfaces Checks if both references are null or refer to the same ...
Definition: Reference.hxx:413
com::sun::star::uno::BaseReference::operator<
sal_Bool operator<(const BaseReference &rRef) const
Needed by some STL containers.
Definition: Reference.hxx:390
com::sun::star::uno::BaseReference::operator==
sal_Bool operator==(XInterface *pInterface) const
Equality operator: compares two interfaces Checks if both references are null or refer to the same ob...
Definition: Reference.hxx:368
_typelib_TypeDescriptionReference::eTypeClass
typelib_TypeClass eTypeClass
type class of type
Definition: typedescription.h:52
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:87
com::sun::star::uno::cppu_unsatisfied_iquery_msg
rtl_uString * cppu_unsatisfied_iquery_msg(typelib_TypeDescriptionReference *pType) SAL_THROW_EXTERN_C()
SAL_THROW_EXTERN_C
CPPU_DLLPUBLIC void SAL_THROW_EXTERN_C()
This method is called to wait for a reply of a previously sent request.
com::sun::star::uno::BaseReference::get
XInterface * get() const
Gets interface pointer.
Definition: Reference.h:86
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition: Any.h:46
_typelib_TypeDescriptionReference
Holds a weak reference to a type description.
Definition: typedescription.h:40
com::sun::star::uno::Reference::operator=
Reference< interface_type > & operator=(interface_type *pInterface)
Assignment operator: Acquires given interface pointer and sets reference.
Definition: Reference.hxx:333
SAL_THROW
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:356
com::sun::star::uno::Type
C++ class representing an IDL meta type.
Definition: Type.h:55
com::sun::star::uno::UnoReference_QueryThrow
UnoReference_QueryThrow
Enum defining UNO_QUERY_THROW for implicit interface query.
Definition: Reference.h:146
sal_True
#define sal_True
Definition: types.h:39
Reference.h
com::sun::star::uno::UNO_SET_THROW
Definition: Reference.h:159