]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/cppbind/NasalHash.cxx
First working version of DOM like Canvas event handling
[simgear.git] / simgear / nasal / cppbind / NasalHash.cxx
1 // Wrapper class for Nasal hashes
2 //
3 // Copyright (C) 2012  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 "NasalHash.hxx"
20 #include "to_nasal.hxx"
21
22 #include <cassert>
23
24 namespace nasal
25 {
26
27   //----------------------------------------------------------------------------
28   Hash::Hash(naContext c):
29     _hash( naNewHash(c) ),
30     _context(c)
31   {
32
33   }
34
35   //----------------------------------------------------------------------------
36   Hash::Hash(naRef hash, naContext c):
37     _hash(hash),
38     _context(c)
39   {
40     assert( naIsHash(_hash) );
41   }
42
43   //----------------------------------------------------------------------------
44   void Hash::set(const std::string& name, naRef ref)
45   {
46     naHash_set(_hash, to_nasal(_context, name), ref);
47   }
48
49   //----------------------------------------------------------------------------
50   naRef Hash::get(const std::string& name)
51   {
52     naRef result;
53     return naHash_get(_hash, to_nasal(_context, name), &result) ? result
54                                                                 : naNil();
55   }
56
57   //----------------------------------------------------------------------------
58   Hash Hash::createHash(const std::string& name)
59   {
60     Hash hash(_context);
61     set(name, hash);
62     return hash;
63   }
64
65   //----------------------------------------------------------------------------
66   void Hash::setContext(naContext context)
67   {
68     _context = context;
69   }
70
71   //----------------------------------------------------------------------------
72   const naRef Hash::get_naRef() const
73   {
74     return _hash;
75   }
76
77 } // namespace nasal