]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/cppbind/NasalHash.hxx
One more fix for old gcc
[simgear.git] / simgear / nasal / cppbind / NasalHash.hxx
1 ///@file 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 #ifndef SG_NASAL_HASH_HXX_
20 #define SG_NASAL_HASH_HXX_
21
22 #include "to_nasal.hxx"
23
24 namespace nasal
25 {
26
27   /**
28    * A Nasal Hash
29    */
30   class Hash
31   {
32     public:
33
34       /**
35        * Create a new Nasal Hash
36        *
37        * @param c   Nasal context for creating the hash
38        */
39       Hash(naContext c);
40
41       /**
42        * Initialize from an existing Nasal Hash
43        *
44        * @param hash  Existing Nasal Hash
45        * @param c     Nasal context for creating new Nasal objects
46        */
47       Hash(const naRef& hash, naContext c);
48
49       /**
50        * Set member
51        *
52        * @param name    Member name
53        * @param ref     Reference to Nasal object (naRef)
54        */
55       void set(const std::string& name, naRef ref);
56
57       /**
58        * Set member to anything convertible using to_nasal
59        *
60        * @param name    Member name
61        * @param val     Value (has to be convertible with to_nasal)
62        */
63       template<class T>
64       void set(const std::string& name, const T& val)
65       {
66         set(name, to_nasal(_context, val));
67       }
68
69       /**
70        * Create a new child hash (module)
71        *
72        * @param name  Name of the new hash inside this hash
73        */
74       Hash createHash(const std::string& name);
75
76       /**
77        * Set a new Nasal context. Eg. in FlightGear the context changes every
78        * frame, so if using the same Hash instance for multiple frames you have
79        * to update the context before using the Hash object.
80        */
81       void setContext(naContext context);
82
83       /**
84        * Get Nasal representation of Hash
85        */
86       const naRef get_naRef() const;
87
88     protected:
89
90       naRef _hash;
91       naContext _context;
92
93   };
94
95 } // namespace nasal
96
97 #endif /* SG_NASAL_HASH_HXX_ */