nss: upgrade to release 3.73
[LibreOffice.git] / connectivity / source / inc / java / GlobalRef.hxx
blob80888cb488103f1f6d1025c2252f5a031085097f
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 .
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 >
32 class GlobalRef
34 public:
35 GlobalRef()
36 :m_object( nullptr )
40 GlobalRef( const GlobalRef& _source )
41 :m_object( nullptr )
43 *this = _source;
46 GlobalRef& operator=( const GlobalRef& _source )
48 if ( &_source == this )
49 return *this;
51 SDBThreadAttach t;
52 set( t.env(), _source.get() );
53 return *this;
56 ~GlobalRef() COVERITY_NOEXCEPT_FALSE
58 reset();
61 void reset()
63 if ( m_object != nullptr )
65 SDBThreadAttach t;
66 t.env().DeleteGlobalRef( m_object );
67 m_object = nullptr;
71 void set( JNIEnv& _environment, T _object )
73 if ( m_object != nullptr )
74 _environment.DeleteGlobalRef( m_object );
75 m_object = _object;
76 if ( m_object )
77 m_object = static_cast< T >( _environment.NewGlobalRef( m_object ) );
80 void set( LocalRef< T >& _object )
82 set( _object.env(), _object.release() );
85 T get() const
87 return m_object;
90 bool is() const
92 return m_object != nullptr;
95 private:
96 T m_object;
100 } // namespace connectivity::jdbc
103 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */