MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
jtie_tconv_enum_impl.hpp
1 /*
2  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 /*
18  * jtie_tconv_enum_impl.hpp
19  */
20 
21 #ifndef jtie_tconv_enum_impl_hpp
22 #define jtie_tconv_enum_impl_hpp
23 
24 #include <assert.h> // not using namespaces yet
25 #include <jni.h>
26 
27 #include "jtie_tconv_enum.hpp"
28 #include "jtie_tconv_impl.hpp"
29 #include "helpers.hpp"
30 
31 // ---------------------------------------------------------------------------
32 // Java value <-> C enum conversions
33 // ---------------------------------------------------------------------------
34 
35 // currently, only Java int <-> C enum mappings are supported
36 
37 // Implements enum parameter conversions.
38 template< typename J, typename C >
39 struct ParamEnumT {
40  // ok to pass J by value
41  static C
42  convert(cstatus & s, J j, JNIEnv * env) {
43  TRACE("C ParamEnumT.convert(cstatus &, J, JNIEnv *)");
44  (void)env;
45  s = 0;
46  return static_cast< C >(j.value);
47  }
48 
49  static void
50  release(C c, J j, JNIEnv * env) {
51  TRACE("void ParamEnumT.release(C, J, JNIEnv *)");
52  (void)c; (void)j; (void)env;
53  }
54 
55 private:
56  // prohibit instantiation
57  ParamEnumT() {
58  // prohibit unsupported template specializations
59  /* is_valid_enum_type_mapping< J, C >(); */
60  }
61 };
62 
63 // Implements enum type result conversions.
64 template< typename J, typename C >
65 struct ResultEnumT {
66  // ok to return J by value
67  static J
68  convert(C c, JNIEnv * env) {
69  TRACE("J ResultEnumT.convert(C, JNIEnv *)");
70  (void)env;
71  return static_cast< J >(c);
72  }
73 
74 private:
75  // prohibit instantiation
76  ResultEnumT() {
77  // prohibit unsupported template specializations
78  /* is_valid_enum_type_mapping< J, C >(); */
79  }
80 };
81 
82 // ---------------------------------------------------------------------------
83 // Specializations for integral <-> enum type conversions
84 // ---------------------------------------------------------------------------
85 
86 // Avoid mapping types by broad, generic rules, which easily results in
87 // template instantiation ambiguities for non-enum types. Therefore,
88 // we enumerate all specicializations for enum types.
89 
90 /*
91 // define set of valid enum type mappings
92 template < typename C >
93 struct is_valid_enum_type_mapping< _jtie_jint_Enum, C > {};
94 
95 // extend for const enum specializations
96 template < typename J, typename C >
97 struct is_valid_enum_type_mapping< const J, C > {};
98 template < typename J, typename C >
99 struct is_valid_enum_type_mapping< J, const C > {};
100 template < typename J, typename C >
101 struct is_valid_enum_type_mapping< const J, const C > {};
102 */
103 
104 // non-const enum value parameter types
105 template< typename C >
106 struct Param< _jtie_jint_Enum, C >
107  : ParamEnumT< _jtie_jint_Enum, C > {};
108 
109 // non-const enum value result types
110 template< typename C >
112  : ResultEnumT< _jtie_jint_Enum, C > {};
113 
114 // ---------------------------------------------------------------------------
115 
116 #endif // jtie_tconv_enum_impl_hpp