MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
jtie_tconv_refbybb_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_refbybb_impl.hpp
19  */
20 
21 #ifndef jtie_tconv_refbybb_impl_hpp
22 #define jtie_tconv_refbybb_impl_hpp
23 
24 #include <assert.h> // not using namespaces yet
25 #include <jni.h>
26 
27 #include "jtie_tconv_refbybb.hpp"
28 #include "jtie_tconv_impl.hpp"
29 #include "jtie_tconv_ptrbybb_impl.hpp"
30 #include "jtie_tconv_utils_impl.hpp"
31 #include "helpers.hpp"
32 
33 // ---------------------------------------------------------------------------
34 // ByteBufferRefParam, ByteBufferRefResult
35 // ---------------------------------------------------------------------------
36 
37 // XXX document, cleanup
38 
39 // implements the mapping of ByteBuffers to reference parameters
40 template< typename J, typename C > struct ByteBufferRefParam;
41 
42 // implements the mapping of ByteBuffers to reference results
43 template< typename J, typename C > struct ByteBufferRefResult;
44 
45 inline cstatus
46 ensureNonNullBuffer(jtie_j_n_ByteBuffer jbb, JNIEnv * env) {
47  // init return value to error
48  cstatus s = -1;
49 
50  if (jbb == NULL) {
51  const char * c = "java/lang/IllegalArgumentException";
52  const char * m = ("JTie: java.nio.ByteBuffer cannot be null"
53  " when mapped to an object reference type"
54  " (file: " __FILE__ ")");
55  registerException(env, c, m);
56  } else {
57  // ok
58  s = 0;
59  }
60  return s;
61 }
62 
63 template< typename J, typename C >
65 
66  static C &
67  convert(cstatus & s, jtie_j_n_ByteBuffer j, JNIEnv * env) {
68  TRACE("C & ByteBufferRefParam.convert(cstatus &, jtie_j_n_ByteBuffer, JNIEnv *)");
69 
70  // init return value and status to error
71  s = -1;
72  C * c = NULL;
73 
74  if (ensureNonNullBuffer(j, env) != 0) {
75  // exception pending
76  } else {
78  assert(s != 0 || c != NULL);
79  }
80  return *c;
81  }
82 
83  static void
84  release(C & c, jtie_j_n_ByteBuffer j, JNIEnv * env) {
85  TRACE("void ByteBufferRefParam.release(C &, jtie_j_n_ByteBuffer, JNIEnv *)");
87  }
88 };
89 
90 template< typename J, typename C >
92  static J *
93  convert(C & c, JNIEnv * env) {
94  TRACE("J * ByteBufferRefResult.convert(C &, JNIEnv *)");
95  // technically, C++ references can be null, hence, no asserts here
96  //assert(&c != NULL);
97  J * j = ByteBufferPtrResult< J, C >::convert(&c, env);
98  //assert(j != NULL);
99  return j;
100  }
101 };
102 
103 // ---------------------------------------------------------------------------
104 // Specializations for ByteBuffer type conversions
105 // ---------------------------------------------------------------------------
106 
107 // specialize ByteBuffers mapped to references:
108 // - params: require a minimum buffer capacity of the size of the base type
109 // - results: allocate buffer with a capacity of the size of the base type
110 template< typename C >
113 template< typename C >
116 
117 // ---------------------------------------------------------------------------
118 
119 #endif // jtie_tconv_refbybb_impl_hpp