]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/cppbind/to_nasal.hxx
Silence MSVC
[simgear.git] / simgear / nasal / cppbind / to_nasal.hxx
1 ///@file
2 /// Conversion functions to convert C++ types to Nasal types
3 ///
4 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Library General Public License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
19
20 #ifndef SG_TO_NASAL_HXX_
21 #define SG_TO_NASAL_HXX_
22
23 #include <simgear/nasal/cppbind/detail/to_nasal_helper.hxx>
24
25 namespace nasal
26 {
27   /**
28    * Convert any supported C++ type to Nasal.
29    *
30    * @param c   Active Nasal context
31    * @param arg C++ Object to be converted
32    * @tparam T  Type of converted object
33    *
34    * @throws bad_nasal_cast if conversion is not possible
35    *
36    * @note  Every type which should be supported needs a function with the
37    *        following signature declared (Type needs to be a const reference
38    *        for non-integral types):
39    *
40    *        naRef to_nasal_helper(naContext, Type)
41    */
42   template<class T>
43   naRef to_nasal(naContext c, T arg)
44   {
45     return to_nasal_helper(c, arg);
46   }
47
48   template<class T, size_t N>
49   naRef to_nasal(naContext c, const T(&array)[N])
50   {
51     return to_nasal_helper(c, array);
52   }
53
54   /**
55    * Wrapper to get pointer to specific version of to_nasal applicable to given
56    * type.
57    */
58   template<class Var>
59   struct to_nasal_ptr
60   {
61     typedef typename boost::call_traits<Var>::param_type param_type;
62     typedef naRef(*type)(naContext, param_type);
63
64     static type get()
65     {
66       return &to_nasal<param_type>;
67     }
68   };
69 } // namespace nasal
70
71 #endif /* SG_TO_NASAL_HXX_ */