1 ///@file Conversion functions to convert C++ types to Nasal types
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_TO_NASAL_HXX_
20 #define SG_TO_NASAL_HXX_
22 #include <simgear/nasal/nasal.h>
24 #include <boost/utility/enable_if.hpp>
25 #include <boost/type_traits.hpp>
35 * Convert std::string to Nasal string
37 naRef to_nasal(naContext c, const std::string& str);
40 * Convert function pointer to Nasal function
42 naRef to_nasal(naContext c, naCFunction func);
45 * Convert a nasal::Hash to a Nasal hash
47 naRef to_nasal(naContext c, const Hash& hash);
50 * Simple pass-through of naRef types to allow generic usage of to_nasal
52 naRef to_nasal(naContext c, naRef ref);
55 * Convert a numeric type to Nasal number
58 typename boost::enable_if< boost::is_arithmetic<T>, naRef >::type
59 to_nasal(naContext c, T num)
65 * Convert std::vector to Nasal vector
67 template< template<class T, class Alloc> class Vector,
71 typename boost::enable_if< boost::is_same< Vector<T,Alloc>,
76 to_nasal(naContext c, const Vector<T, Alloc>& vec)
78 naRef ret = naNewVector(c);
79 naVec_setsize(c, ret, vec.size());
80 for(size_t i = 0; i < vec.size(); ++i)
81 naVec_set(ret, i, to_nasal(c, vec[i]));
87 #endif /* SG_TO_NASAL_HXX_ */