1 /*
2  Copyright (c) 2010, 2021, Oracle and/or its affiliates.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License, version 2.0,
7  as published by the Free Software Foundation.
8 
9  This program is also distributed with certain software (including
10  but not limited to OpenSSL) that is licensed under separate terms,
11  as designated in a particular file or component or in included license
12  documentation.  The authors of MySQL hereby grant you an additional
13  permission to link the program and your derivative works with the
14  separately licensed software that they have included with MySQL.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  GNU General Public License, version 2.0, for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 */
25 /*
26  * jtie_tconv_enum.hpp
27  */
28 
29 #ifndef jtie_tconv_enum_hpp
30 #define jtie_tconv_enum_hpp
31 
32 #include <jni.h>
33 
34 // ---------------------------------------------------------------------------
35 // Java value <-> C enum conversions
36 // ---------------------------------------------------------------------------
37 
38 // currently, only Java int <-> C enum mappings are supported
39 
40 /**
41  * A root type for enum value argument/result mappings.
42  * Unlike the root class definitions for object (array etc) mappings,
43  * this class does not derive from a JNI type.  Therefore, a conversion
44  * constructor/operator is used to facilitate the static type conversion
45  * between the Java formal and actual type in this mapping.
46  * While this approach (conceptually) involves creating instances of this
47  * root class at runtime, which hold the the enum value, this should be
48  * detectable to the compiler as purely type-changing copy operations.
49  */
50 struct _jtie_jint_Enum {
51     // the enum value (cannot be const to enable assignment)
52     jint value;
53 
54     // conversion constructor
_jtie_jint_Enum_jtie_jint_Enum55     _jtie_jint_Enum(jint v) : value(v) {}
56 
57     // conversion operator
operator jint_jtie_jint_Enum58     operator jint() { return value; }
59 };
60 
61 /**
62  * Defines the trait type aliases for the mapping of
63  * an integral Java type to a C++ enum type.
64  *
65  * The macro takes these arguments:
66  *   C: A C++ enum type name.
67  *   T: A name tag for this mapping.
68  *
69  * Naming convention:
70  *   type alias:                specifies a mapping:
71  *   ttrait_<T>_i               jint <->       C
72  *   ttrait_<T>_c_iv            jint <-> const C
73  */
74 #define JTIE_DEFINE_JINT_ENUM_TYPE_MAPPING( C, T )              \
75     typedef ttrait< jint, C, _jtie_jint_Enum                    \
76                     > ttrait_##T##_iv;                          \
77     typedef ttrait< jint, C const, _jtie_jint_Enum              \
78                     > ttrait_##T##_c_iv;
79 
80 /**
81  * A helper class template that predicates the supported type conversions
82  * by presence of specialization.
83  */
84 /*
85 template < typename J, typename C >
86 struct is_valid_enum_type_mapping;
87 */
88 
89 // XXX to document
90 #define JTIE_INSTANTIATE_JINT_ENUM_TYPE_MAPPING( C )
91 //    template struct is_valid_enum_type_mapping< jint, C >;
92 
93 // ---------------------------------------------------------------------------
94 
95 #endif // jtie_tconv_enum_hpp
96