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.h
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_H_
20 #define _COM_SUN_STAR_UNO_REFERENCE_H_
21
22 #include <rtl/alloc.h>
23
24
25 namespace com
26 {
27 namespace sun
28 {
29 namespace star
30 {
31 namespace uno
32 {
33
34 class RuntimeException;
35 class XInterface;
36 class Type;
37 class Any;
38
43 enum UnoReference_NoAcquire
44 {
48 UNO_REF_NO_ACQUIRE
49 };
50
54 class BaseReference
55 {
56 protected:
59 XInterface * _pInterface;
60
67 inline static XInterface * SAL_CALL iquery( XInterface * pInterface, const Type & rType )
68 SAL_THROW( (RuntimeException) );
69 #ifndef EXCEPTIONS_OFF
70
77 inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType )
78 SAL_THROW( (RuntimeException) );
79 #endif
80
81 public:
86 inline XInterface * SAL_CALL get() const SAL_THROW(())
87 { return _pInterface; }
88
93 inline sal_Bool SAL_CALL is() const SAL_THROW(())
94 { return (0 != _pInterface); }
95
102 inline sal_Bool SAL_CALL operator == ( XInterface * pInterface ) const SAL_THROW(());
109 inline sal_Bool SAL_CALL operator != ( XInterface * pInterface ) const SAL_THROW(());
110
117 inline sal_Bool SAL_CALL operator == ( const BaseReference & rRef ) const SAL_THROW(());
124 inline sal_Bool SAL_CALL operator != ( const BaseReference & rRef ) const SAL_THROW(());
125
131 inline sal_Bool SAL_CALL operator < ( const BaseReference & rRef ) const SAL_THROW(());
132 };
133
136 enum UnoReference_Query
137 {
140 UNO_QUERY,
141 };
142 #ifndef EXCEPTIONS_OFF
143
146 enum UnoReference_QueryThrow
147 {
150 UNO_QUERY_THROW,
151 };
157 enum UnoReference_SetThrow
158 {
159 UNO_SET_THROW
160 };
161 #endif
162
164 namespace detail {
165
166 // A mechanism to enable up-casts, used by the Reference conversion constructor,
167 // but at the same time disable up-casts to XInterface, so that the conversion
168 // operator for that special case is used in an expression like
169 // Reference< XInterface >(x); heavily borrowed from boost::is_base_and_derived
170 // (which manages to avoid compilation problems with ambiguous bases and cites
171 // comp.lang.c++.moderated mail <http://groups.google.com/groups?
172 // selm=df893da6.0301280859.522081f7%40posting.google.com> "SuperSubclass
173 // (is_base_and_derived) complete implementation!" by Rani Sharoni and cites
174 // Aleksey Gurtovoy for the workaround for MSVC), to avoid including Boost
175 // headers in URE headers (could ultimately be based on C++11 std::is_base_of):
176
177 template< typename T1, typename T2 > struct UpCast {
178 private:
179 template< bool, typename U1, typename > struct C
180 { typedef U1 t; };
181
182 template< typename U1, typename U2 > struct C< false, U1, U2 >
183 { typedef U2 t; };
184
185 struct S { char c[2]; };
186
187 #if defined _MSC_VER
188 static char f(T2 *, long);
189 static S f(T1 * const &, int);
190 #else
191 template< typename U > static char f(T2 *, U);
192 static S f(T1 *, int);
193 #endif
194
195 struct H {
196 H(); // avoid C2514 "class has no constructors" from MSVC 2008
197 #if defined _MSC_VER
198 operator T1 * const & () const;
199 #else
200 operator T1 * () const;
201 #endif
202 operator T2 * ();
203 };
204
205 public:
206 typedef typename C< sizeof (f(H(), 0)) == 1, void *, void >::t t;
207 };
208
209 template< typename T2 > struct UpCast< XInterface, T2 > {};
210
211 }
213
218 template< class interface_type >
219 class Reference : public BaseReference
220 {
226 inline static XInterface * SAL_CALL iquery( XInterface * pInterface )
227 SAL_THROW( (RuntimeException) );
228 #ifndef EXCEPTIONS_OFF
229
235 inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface )
236 SAL_THROW( (RuntimeException) );
242 inline static interface_type * SAL_CALL iset_throw( interface_type * pInterface )
243 SAL_THROW( (RuntimeException) );
244 #endif
245
257 static inline interface_type * castFromXInterface(XInterface * p) {
258 return static_cast< interface_type * >(static_cast< void * >(p));
259 }
260
272 static inline XInterface * castToXInterface(interface_type * p) {
273 return static_cast< XInterface * >(static_cast< void * >(p));
274 }
275
276 public:
278 // these are here to force memory de/allocation to sal lib.
279 inline static void * SAL_CALL operator new ( ::size_t nSize ) SAL_THROW(())
280 { return ::rtl_allocateMemory( nSize ); }
281 inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
282 { ::rtl_freeMemory( pMem ); }
283 inline static void * SAL_CALL operator new ( ::size_t, void * pMem ) SAL_THROW(())
284 { return pMem; }
285 inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
286 {}
288
291 inline ~Reference() SAL_THROW(());
292
295 inline Reference() SAL_THROW(());
296
301 inline Reference( const Reference< interface_type > & rRef ) SAL_THROW(());
302
311 template< class derived_type >
312 inline Reference(
313 const Reference< derived_type > & rRef,
314 typename detail::UpCast< interface_type, derived_type >::t = 0 )
315 SAL_THROW(());
316
321 inline Reference( interface_type * pInterface ) SAL_THROW(());
322
328 inline Reference( interface_type * pInterface, __sal_NoAcquire dummy) SAL_THROW(());
336 inline Reference( interface_type * pInterface, UnoReference_NoAcquire dummy ) SAL_THROW(());
337
343 inline Reference( const BaseReference & rRef, UnoReference_Query dummy ) SAL_THROW( (RuntimeException) );
349 inline Reference( XInterface * pInterface, UnoReference_Query dummy) SAL_THROW( (RuntimeException) );
355 inline Reference( const Any & rAny, UnoReference_Query dummy) SAL_THROW( (RuntimeException) );
356 #ifndef EXCEPTIONS_OFF
357
364 inline Reference( const BaseReference & rRef, UnoReference_QueryThrow dummy ) SAL_THROW( (RuntimeException) );
372 inline Reference( XInterface * pInterface, UnoReference_QueryThrow dummy ) SAL_THROW( (RuntimeException) );
380 inline Reference( const Any & rAny, UnoReference_QueryThrow dummy ) SAL_THROW( (RuntimeException) );
389 inline Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy ) SAL_THROW( (RuntimeException) );
398 inline Reference( interface_type * pInterface, UnoReference_SetThrow dummy ) SAL_THROW( (RuntimeException) );
399 #endif
400
405 inline SAL_CALL operator const Reference< XInterface > & () const SAL_THROW(())
406 { return * reinterpret_cast< const Reference< XInterface > * >( this ); }
407
412 inline interface_type * SAL_CALL operator -> () const SAL_THROW(())
413 { return castFromXInterface(_pInterface); }
414
419 inline interface_type * SAL_CALL get() const SAL_THROW(())
420 { return castFromXInterface(_pInterface); }
421
424 inline void SAL_CALL clear() SAL_THROW(());
425
431 inline sal_Bool SAL_CALL set( const Reference< interface_type > & rRef ) SAL_THROW(());
437 inline sal_Bool SAL_CALL set( interface_type * pInterface ) SAL_THROW(());
438
445 inline sal_Bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire dummy) SAL_THROW(());
454 inline sal_Bool SAL_CALL set( interface_type * pInterface, UnoReference_NoAcquire dummy) SAL_THROW(());
455
463 inline sal_Bool SAL_CALL set( XInterface * pInterface, UnoReference_Query dummy ) SAL_THROW( (RuntimeException) );
471 inline sal_Bool SAL_CALL set( const BaseReference & rRef, UnoReference_Query dummy) SAL_THROW( (RuntimeException) );
472
484 inline bool set( Any const & rAny, UnoReference_Query dummy );
485
486 #ifndef EXCEPTIONS_OFF
487
495 inline void SAL_CALL set( XInterface * pInterface, UnoReference_QueryThrow dummy ) SAL_THROW( (RuntimeException) );
504 inline void SAL_CALL set( const BaseReference & rRef, UnoReference_QueryThrow dummy ) SAL_THROW( (RuntimeException) );
505
515 inline void set( Any const & rAny, UnoReference_QueryThrow dummy);
525 inline void SAL_CALL set( interface_type * pInterface, UnoReference_SetThrow dummy) SAL_THROW( (RuntimeException) );
535 inline void SAL_CALL set( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy) SAL_THROW( (RuntimeException) );
536
537 #endif
538
545 inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface ) SAL_THROW(());
552 inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef ) SAL_THROW(());
553
559 inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef ) SAL_THROW( (RuntimeException) );
565 inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface ) SAL_THROW( (RuntimeException) );
566 };
567
569
571 template <typename T>
572 inline T * get_pointer( Reference<T> const& r )
573 {
574 return r.get();
575 }
577
578 }
579 }
580 }
581 }
582
583 #endif
584
585 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::Reference::Reference
Reference()
Default Constructor: Sets null reference.
Definition: Reference.hxx:112
com::sun::star::uno::Type
C++ class representing an IDL meta type.
Definition: Type.h:55
SAL_THROW
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:356
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
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::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
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::UnoReference_Query
UnoReference_Query
Enum defining UNO_QUERY for implicit interface query.
Definition: Reference.h:136
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
com::sun::star::uno::Reference::~Reference
~Reference()
Destructor: Releases interface if set.
Definition: Reference.hxx:105
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::BaseReference::operator<
sal_Bool operator<(const BaseReference &rRef) const
Needed by some STL containers.
Definition: Reference.hxx:390
com::sun::star::uno::UNO_SET_THROW
Definition: Reference.h:159
com::sun::star::uno::BaseReference::is
sal_Bool is() const
Checks if reference is null.
Definition: Reference.h:93
com::sun::star::uno::Reference
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:32
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::UNO_QUERY_THROW
This enum value can be used for implicit interface query.
Definition: Reference.h:150
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition: Any.h:46
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
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_QueryThrow
UnoReference_QueryThrow
Enum defining UNO_QUERY_THROW for implicit interface query.
Definition: Reference.h:146
com::sun::star::uno::Reference::clear
void clear()
Clears reference, i.e.
Definition: Reference.hxx:211
com::sun::star::uno::BaseReference::iquery
static XInterface * iquery(XInterface *pInterface, const Type &rType)
Queries given interface for type rType.
Definition: Reference.hxx:37
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
sal_Bool
unsigned char sal_Bool
Definition: types.h:37
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::BaseReference::_pInterface
XInterface * _pInterface
the interface pointer
Definition: Reference.h:59
com::sun::star::uno::UNO_REF_NO_ACQUIRE
This enum value can be used for creating a reference granting a given interface, i.e.
Definition: Reference.h:48
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
com::sun::star::uno::Reference::operator->
interface_type * operator->() const
Dereference operator: Used to call interface methods.
Definition: Reference.h:412
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:370
alloc.h