bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / inc / java / GlobalRef.hxx
blob760e01886c9958af3926d8920fbb1f6e5944aa7f
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"
26 #include <jvmaccess/virtualmachine.hxx>
29 namespace connectivity { namespace jdbc
31 /** helper class to hold a local ref to a JNI object
33 template< typename T >
34 class GlobalRef
36 public:
37 GlobalRef()
38 :m_object( NULL )
42 GlobalRef( const GlobalRef& _source )
43 :m_object( NULL )
45 *this = _source;
48 GlobalRef& operator=( const GlobalRef& _source )
50 if ( &_source == this )
51 return *this;
53 SDBThreadAttach t;
54 set( t.env(), _source.get() );
55 return *this;
58 ~GlobalRef()
60 reset();
63 void reset()
65 if ( m_object != NULL )
67 SDBThreadAttach t;
68 t.env().DeleteGlobalRef( m_object );
69 m_object = NULL;
73 void set( JNIEnv& _environment, T _object )
75 if ( m_object != NULL )
76 _environment.DeleteGlobalRef( m_object );
77 m_object = _object;
78 if ( m_object )
79 m_object = static_cast< T >( _environment.NewGlobalRef( m_object ) );
82 void set( LocalRef< T >& _object )
84 set( _object.env(), _object.release() );
87 T get() const
89 return m_object;
92 bool is() const
94 return m_object != NULL;
97 private:
98 T m_object;
103 } } // namespace connectivity::jdbc
106 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */