1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX
23 #include <java/LocalRef.hxx>
24 #include <java/lang/Object.hxx>
27 namespace connectivity::jdbc
29 /** helper class to hold a local ref to a JNI object
31 template< typename T
>
40 GlobalRef( const GlobalRef
& _source
)
46 GlobalRef
& operator=( const GlobalRef
& _source
)
48 if ( &_source
== this )
52 set( t
.env(), _source
.get() );
56 ~GlobalRef() COVERITY_NOEXCEPT_FALSE
63 if ( m_object
!= nullptr )
66 t
.env().DeleteGlobalRef( m_object
);
71 void set( JNIEnv
& _environment
, T _object
)
73 if ( m_object
!= nullptr )
74 _environment
.DeleteGlobalRef( m_object
);
77 m_object
= static_cast< T
>( _environment
.NewGlobalRef( m_object
) );
80 void set( LocalRef
< T
>& _object
)
82 set( _object
.env(), _object
.release() );
92 return m_object
!= nullptr;
100 } // namespace connectivity::jdbc
103 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */