]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/cppbind/Ghost.cxx
Remove some debug output.
[simgear.git] / simgear / nasal / cppbind / Ghost.cxx
1 // Expose C++ objects to Nasal as ghosts
2 //
3 // Copyright (C) 2014 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 #include "Ghost.hxx"
20
21 namespace nasal
22 {
23   namespace internal
24   {
25     //--------------------------------------------------------------------------
26     GhostMetadata::DestroyList GhostMetadata::_destroy_list;
27
28     //--------------------------------------------------------------------------
29     void GhostMetadata::addNasalBase(const naRef& parent)
30     {
31       assert( naIsHash(parent) );
32       _parents.push_back(parent);
33     }
34
35     //--------------------------------------------------------------------------
36     bool GhostMetadata::isInstance(naGhostType* ghost_type, bool& is_weak) const
37     {
38       if( ghost_type == _ghost_type_strong_ptr )
39       {
40         is_weak = false;
41         return true;
42       }
43
44       if( ghost_type == _ghost_type_weak_ptr )
45       {
46         is_weak = true;
47         return true;
48       }
49
50       return false;
51     }
52
53     //--------------------------------------------------------------------------
54     GhostMetadata::GhostMetadata( const std::string& name,
55                                   const naGhostType* ghost_type_strong,
56                                   const naGhostType* ghost_type_weak ):
57       _name_strong(name),
58       _name_weak(name + " (weak ref)"),
59       _ghost_type_strong_ptr(ghost_type_strong),
60       _ghost_type_weak_ptr(ghost_type_weak)
61     {
62
63     }
64
65     //--------------------------------------------------------------------------
66     void GhostMetadata::addDerived(const GhostMetadata* derived)
67     {
68       assert(derived);
69     }
70
71     //--------------------------------------------------------------------------
72     naRef GhostMetadata::getParents(naContext c)
73     {
74       return nasal::to_nasal(c, _parents);
75     }
76   } // namespace internal
77
78   //----------------------------------------------------------------------------
79   void ghostProcessDestroyList()
80   {
81     using internal::GhostMetadata;
82     typedef GhostMetadata::DestroyList::const_iterator destroy_iterator;
83     for( destroy_iterator it = GhostMetadata::_destroy_list.begin();
84                           it != GhostMetadata::_destroy_list.end();
85                         ++it )
86       it->first(it->second);
87     GhostMetadata::_destroy_list.clear();
88   }
89
90 } // namespace nasal
91