1 ///@file Wrapper class for Nasal hashes
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
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.
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.
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
19 #ifndef SG_NASAL_HASH_HXX_
20 #define SG_NASAL_HASH_HXX_
22 #include "from_nasal.hxx"
23 #include "to_nasal.hxx"
36 * Create a new Nasal Hash
38 * @param c Nasal context for creating the hash
43 * Initialize from an existing Nasal Hash
45 * @param hash Existing Nasal Hash
46 * @param c Nasal context for creating new Nasal objects
48 Hash(naRef hash, naContext c);
53 * @param name Member name
54 * @param ref Reference to Nasal object (naRef)
56 void set(const std::string& name, naRef ref);
59 * Set member to anything convertible using to_nasal
61 * @param name Member name
62 * @param val Value (has to be convertible with to_nasal)
65 void set(const std::string& name, const T& val)
67 set(name, to_nasal(_context, val));
73 * @param name Member name
75 naRef get(const std::string& name);
78 * Get member converted to given type
80 * @tparam T Type to convert to (using from_nasal)
81 * @param name Member name
84 T get(const std::string& name)
86 return from_nasal<T>(_context, get(name));
90 * Create a new child hash (module)
92 * @param name Name of the new hash inside this hash
94 Hash createHash(const std::string& name);
97 * Set a new Nasal context. Eg. in FlightGear the context changes every
98 * frame, so if using the same Hash instance for multiple frames you have
99 * to update the context before using the Hash object.
101 void setContext(naContext context);
104 * Get Nasal representation of Hash
106 const naRef get_naRef() const;
117 #endif /* SG_NASAL_HASH_HXX_ */