LibreOffice
LibreOffice 24.2 SDK C/C++ API Reference
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 
20 /*
21  * This file is part of LibreOffice published API.
22  */
23 #ifndef INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H
24 #define INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H
25 
26 #include "sal/config.h"
27 
28 #include <cassert>
29 #include <cstddef>
30 
31 #if defined LIBO_INTERNAL_ONLY
32 #include <type_traits>
33 #endif
34 
35 #include "rtl/alloc.h"
36 
37 namespace com
38 {
39 namespace sun
40 {
41 namespace star
42 {
43 namespace uno
44 {
45 
46 class RuntimeException;
47 class XInterface;
48 class Type;
49 class Any;
50 
56 {
61 };
62 
67 {
68 protected:
71  XInterface * _pInterface;
72 
79  inline static XInterface * SAL_CALL iquery( XInterface * pInterface, const Type & rType );
87  inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType );
88 
89 public:
94  XInterface * SAL_CALL get() const
95  { return _pInterface; }
96 
101  bool SAL_CALL is() const
102  { return (NULL != _pInterface); }
103 
104 #if defined LIBO_INTERNAL_ONLY
105 
109  explicit operator bool() const
110  { return is(); }
111 #endif
112 
119  inline bool SAL_CALL operator == ( XInterface * pInterface ) const;
126  inline bool SAL_CALL operator != ( XInterface * pInterface ) const;
127 
134  inline bool SAL_CALL operator == ( const BaseReference & rRef ) const;
141  inline bool SAL_CALL operator != ( const BaseReference & rRef ) const;
142 
148  inline bool SAL_CALL operator < ( const BaseReference & rRef ) const;
149 };
150 
154 {
158 };
163 {
167 };
174 {
176 };
177 
182 template< class interface_type >
183 class SAL_DLLPUBLIC_RTTI Reference : public BaseReference
184 {
190  inline static XInterface * SAL_CALL iquery( XInterface * pInterface );
197  inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface );
203  inline static interface_type * SAL_CALL iset_throw( interface_type * pInterface );
204 
216  static interface_type * castFromXInterface(XInterface * p) {
217  return static_cast< interface_type * >(static_cast< void * >(p));
218  }
219 
231  static XInterface * castToXInterface(interface_type * p) {
232  return static_cast< XInterface * >(static_cast< void * >(p));
233  }
234 
235 public:
237  // these are here to force memory de/allocation to sal lib.
238  static void * SAL_CALL operator new ( ::size_t nSize )
239  { return ::rtl_allocateMemory( nSize ); }
240  static void SAL_CALL operator delete ( void * pMem )
241  { ::rtl_freeMemory( pMem ); }
242  static void * SAL_CALL operator new ( ::size_t, void * pMem )
243  { return pMem; }
244  static void SAL_CALL operator delete ( void *, void * )
245  {}
247 
250  inline ~Reference() COVERITY_NOEXCEPT_FALSE;
251 
254  inline Reference();
255 
260  inline Reference( const Reference< interface_type > & rRef );
261 
262 #if defined LIBO_INTERNAL_ONLY
263 
267  inline Reference( Reference< interface_type > && rRef ) noexcept;
268 
277  template< class derived_type >
278  inline Reference(
279  const Reference< derived_type > & rRef,
280  std::enable_if_t<
281  std::is_base_of_v<interface_type, derived_type>
282  && !std::is_same_v<interface_type, XInterface>, void *> = nullptr);
283 #endif
284 
289  inline Reference( interface_type * pInterface );
290 
296  inline Reference( interface_type * pInterface, __sal_NoAcquire dummy);
304  inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version") Reference( interface_type * pInterface, UnoReference_NoAcquire dummy );
305 
311  inline Reference( const BaseReference & rRef, UnoReference_Query dummy );
317  inline Reference( XInterface * pInterface, UnoReference_Query dummy);
323  inline Reference( const Any & rAny, UnoReference_Query dummy);
331  inline Reference( const BaseReference & rRef, UnoReference_QueryThrow dummy );
332 #ifdef LIBO_INTERNAL_ONLY
333 
336  Reference( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete;
337 #endif
338 
345  inline Reference( XInterface * pInterface, UnoReference_QueryThrow dummy );
353  inline Reference( const Any & rAny, UnoReference_QueryThrow dummy );
362  inline Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy );
371  inline Reference( interface_type * pInterface, UnoReference_SetThrow dummy );
372 
377  SAL_CALL operator const Reference< XInterface > & () const
378  { return * reinterpret_cast< const Reference< XInterface > * >( this ); }
379 
384  interface_type * SAL_CALL operator -> () const {
385  assert(_pInterface != NULL);
386  return castFromXInterface(_pInterface);
387  }
388 
394  interface_type & SAL_CALL operator * () const {
395  assert(_pInterface != NULL);
396  return *castFromXInterface(_pInterface);
397  }
398 
403  interface_type * SAL_CALL get() const
404  { return castFromXInterface(_pInterface); }
405 
408  inline void SAL_CALL clear();
409 
415  inline bool SAL_CALL set( const Reference< interface_type > & rRef );
421  inline bool SAL_CALL set( interface_type * pInterface );
422 
429  inline bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire dummy);
438  inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version") bool SAL_CALL set( interface_type * pInterface, UnoReference_NoAcquire dummy);
439 
447  inline bool SAL_CALL set( XInterface * pInterface, UnoReference_Query dummy );
455  inline bool SAL_CALL set( const BaseReference & rRef, UnoReference_Query dummy);
456 
468  inline bool set( Any const & rAny, UnoReference_Query dummy );
469 
478  inline void SAL_CALL set( XInterface * pInterface, UnoReference_QueryThrow dummy );
487  inline void SAL_CALL set( const BaseReference & rRef, UnoReference_QueryThrow dummy );
488 #ifdef LIBO_INTERNAL_ONLY
489 
492  void set( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete;
493 #endif
494 
504  inline void set( Any const & rAny, UnoReference_QueryThrow dummy);
514  inline void SAL_CALL set( interface_type * pInterface, UnoReference_SetThrow dummy);
524  inline void SAL_CALL set( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy);
525 
526 
533  inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface );
540  inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef );
541 #if defined LIBO_INTERNAL_ONLY
542 
548  inline Reference< interface_type > & operator = ( Reference< interface_type > && rRef ) noexcept;
549 #endif
550 
555  SAL_WARN_UNUSED_RESULT inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef );
561  SAL_WARN_UNUSED_RESULT inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface );
562 #if defined LIBO_INTERNAL_ONLY
563 
569  template< class other_type > inline Reference< other_type > query() const;
576  template< class other_type > inline Reference< other_type > queryThrow() const;
577 #endif
578 };
579 
580 }
581 }
582 }
583 }
584 
585 #endif
586 
587 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
UnoReference_NoAcquire
Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface.
Definition: Reference.h:55
This enum value can be used for creating a reference granting a given interface, i.e.
Definition: Reference.h:60
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won&#39;t throw in practice...
Definition: types.h:349
bool is() const
Checks if reference is null.
Definition: Reference.h:101
static XInterface * iquery_throw(XInterface *pInterface, const Type &rType)
Queries given interface for type rType.
Definition: Reference.hxx:77
bool operator!=(XInterface *pInterface) const
Inequality operator: compares two interfaces Checks if both references are null or refer to the same ...
Definition: Reference.hxx:452
This enum value can be used for implicit interface query.
Definition: Reference.h:157
This enum value can be used for implicit interface query.
Definition: Reference.h:166
bool operator<(const BaseReference &rRef) const
Needed by some STL containers.
Definition: Reference.hxx:433
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:415
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don&#39;t use, it&#39;s evil.") void doit(int nPara);.
Definition: types.h:474
C++ class representing an IDL any.
Definition: Any.h:57
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
UnoReference_Query
Enum defining UNO_QUERY for implicit interface query.
Definition: Reference.h:153
Definition: Reference.h:175
Definition: types.h:359
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:43
__sal_NoAcquire
Definition: types.h:352
UnoReference_QueryThrow
Enum defining UNO_QUERY_THROW for implicit interface query.
Definition: Reference.h:162
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:284
This base class serves as a base class for all template reference classes and has been introduced due...
Definition: Reference.h:66
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
static XInterface * iquery(XInterface *pInterface, const Type &rType)
Queries given interface for type rType.
Definition: Reference.hxx:54
UnoReference_SetThrow
Enum defining UNO_SET_THROW for throwing if attempts are made to assign a null interface.
Definition: Reference.h:173
C++ class representing an IDL meta type.
Definition: Type.h:58
XInterface * _pInterface
the interface pointer
Definition: Reference.h:71