Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / uno / dispatcher.hxx
blob1732be04952e6600f3f7c7a23c6a40da7bd79506
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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.
24 #ifndef INCLUDED_UNO_DISPATCHER_HXX
25 #define INCLUDED_UNO_DISPATCHER_HXX
27 #include "sal/config.h"
29 #include <cstddef>
31 #include "uno/dispatcher.h"
33 /// @cond INTERNAL
35 namespace com
37 namespace sun
39 namespace star
41 namespace uno
44 /** C++ holder reference for binary C uno_Interface. Not for public use, may be
45 subject to changes.
47 @see uno_Interface
48 @attention
49 not for public use!
51 class UnoInterfaceReference
53 public:
54 uno_Interface * m_pUnoI;
56 bool is() const
57 { return m_pUnoI != NULL; }
59 inline ~UnoInterfaceReference();
60 inline UnoInterfaceReference();
61 inline UnoInterfaceReference( uno_Interface * pUnoI, __sal_NoAcquire );
62 inline UnoInterfaceReference( uno_Interface * pUnoI );
63 inline UnoInterfaceReference( UnoInterfaceReference const & ref );
65 #if defined LIBO_INTERNAL_ONLY
66 UnoInterfaceReference(UnoInterfaceReference && other) noexcept :
67 m_pUnoI(other.m_pUnoI)
68 { other.m_pUnoI = nullptr; }
69 #endif
71 uno_Interface * get() const
72 { return m_pUnoI; }
74 inline UnoInterfaceReference & set(
75 uno_Interface * pUnoI );
76 inline UnoInterfaceReference & set(
77 uno_Interface * pUnoI, __sal_NoAcquire );
78 inline void clear();
80 UnoInterfaceReference & operator = (
81 UnoInterfaceReference const & ref )
82 { return set( ref.m_pUnoI ); }
83 UnoInterfaceReference & operator = (
84 uno_Interface * pUnoI )
85 { return set( pUnoI ); }
87 #if defined LIBO_INTERNAL_ONLY
88 UnoInterfaceReference & operator =(UnoInterfaceReference && other) {
89 if (m_pUnoI != nullptr) {
90 (*m_pUnoI->release)(m_pUnoI);
92 m_pUnoI = other.m_pUnoI;
93 other.m_pUnoI = nullptr;
94 return *this;
96 #endif
98 inline void dispatch(
99 struct _typelib_TypeDescription const * pMemberType,
100 void * pReturn, void * pArgs [], uno_Any ** ppException ) const;
104 inline UnoInterfaceReference::~UnoInterfaceReference()
106 if (m_pUnoI != NULL)
107 (*m_pUnoI->release)( m_pUnoI );
111 inline UnoInterfaceReference::UnoInterfaceReference()
112 : m_pUnoI( NULL )
117 inline UnoInterfaceReference::UnoInterfaceReference(
118 uno_Interface * pUnoI, __sal_NoAcquire )
119 : m_pUnoI( pUnoI )
124 inline UnoInterfaceReference::UnoInterfaceReference( uno_Interface * pUnoI )
125 : m_pUnoI( pUnoI )
127 if (m_pUnoI != NULL)
128 (*m_pUnoI->acquire)( m_pUnoI );
132 inline UnoInterfaceReference::UnoInterfaceReference(
133 UnoInterfaceReference const & ref )
134 : m_pUnoI( ref.m_pUnoI )
136 if (m_pUnoI != NULL)
137 (*m_pUnoI->acquire)( m_pUnoI );
141 inline UnoInterfaceReference & UnoInterfaceReference::set(
142 uno_Interface * pUnoI )
144 if (pUnoI != NULL)
145 (*pUnoI->acquire)( pUnoI );
146 if (m_pUnoI != NULL)
147 (*m_pUnoI->release)( m_pUnoI );
148 m_pUnoI = pUnoI;
149 return *this;
153 inline UnoInterfaceReference & UnoInterfaceReference::set(
154 uno_Interface * pUnoI, __sal_NoAcquire )
156 if (m_pUnoI != NULL)
157 (*m_pUnoI->release)( m_pUnoI );
158 m_pUnoI = pUnoI;
159 return *this;
163 inline void UnoInterfaceReference::clear()
165 if (m_pUnoI != NULL)
167 (*m_pUnoI->release)( m_pUnoI );
168 m_pUnoI = NULL;
173 inline void UnoInterfaceReference::dispatch(
174 struct _typelib_TypeDescription const * pMemberType,
175 void * pReturn, void * pArgs [], uno_Any ** ppException ) const
177 (*m_pUnoI->pDispatcher)(
178 m_pUnoI, pMemberType, pReturn, pArgs, ppException );
186 /// @endcond
188 #endif
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */