]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/cppbind/NasalObjectHolder.hxx
cppbind: automatic conversion of SGReferenced derived pointers.
[simgear.git] / simgear / nasal / cppbind / NasalObjectHolder.hxx
1 ///@file Wrapper class for keeping Nasal objects save from the garbage collector
2 //
3 // Copyright (C) 2013  Thomas Geymayer <tomgey@gmail.com>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
18
19 #ifndef SG_NASAL_OBJECT_HOLDER_HXX_
20 #define SG_NASAL_OBJECT_HOLDER_HXX_
21
22 #include <simgear/nasal/naref.h>
23 #include <simgear/structure/SGSharedPtr.hxx>
24
25 namespace nasal
26 {
27
28   /**
29    * Prevent a Nasal object from being destroyed by the garbage collector during
30    * the lifetime of this object.
31    */
32   class ObjectHolder:
33     public SGReferenced
34   {
35     public:
36
37       /**
38        *
39        */
40       ~ObjectHolder();
41
42       /**
43        * Get captured Nasal object
44        */
45       naRef get_naRef() const;
46
47       /**
48        * Save the given object as long as the returned holder exists.
49        *
50        * @param obj Object to save
51        */
52       static SGSharedPtr<ObjectHolder> makeShared(naRef obj);
53
54     protected:
55       naRef _ref;
56       int _gc_key;
57
58       /**
59        * @param obj Object to save
60        */
61       ObjectHolder(naRef obj);
62   };
63
64 } // namespace nasal
65
66 #endif /* SG_NASAL_OBJECT_HOLDER_HXX_ */