Debian Codegraph @

native/common/jp_buffertype.cpp

raw symbols SCIP
1 /*****************************************************************************
2 Licensed under the Apache License, Version 2.0 (the "License");
3 you may not use this file except in compliance with the License.
4 You may obtain a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13
14 See NOTICE file for details.
15 *****************************************************************************/
16 #include "jpype.h"
17 #include "pyjp.h"
18 #include "jp_context.h"
19 #include "jp_buffertype.h"
20
21 JPBufferType::JPBufferType(JPJavaFrame& frame,
22 jclass cls,
23 const string& name,
24 JPClass* superClass,
25 const JPClassList& interfaces,
26 jint modifiers)
27 : JPClass(frame, cls, name, superClass, interfaces, modifiers)
28 {
29 // Use name to get the type
30 if (name == "java.nio.Buffer")
31 {
32 m_Type = "b";
33 m_Size = 1;
34 } else if (name == "java.nio.ByteBuffer")
35 {
36 m_Type = "b";
37 m_Size = 1;
38 } else if (name == "java.nio.CharBuffer")
39 {
40 m_Type = "H";
41 m_Size = 2;
42 } else if (name == "java.nio.ShortBuffer")
43 {
44 m_Type = "h";
45 m_Size = 2;
46 } else if (name == "java.nio.IntBuffer")
47 {
48 m_Type = "i";
49 m_Size = 4;
50 } else if (name == "java.nio.LongBuffer")
51 {
52 m_Type = "q";
53 m_Size = 8;
54 } else if (name == "java.nio.FloatBuffer")
55 {
56 m_Type = "f";
57 m_Size = 4;
58 } else if (name == "java.nio.DoubleBuffer")
59 {
60 m_Type = "d";
61 m_Size = 8;
62 } else
63 {
64 auto* super = dynamic_cast<JPBufferType*> (m_SuperClass);
65 if (super == nullptr)
66 JP_RAISE(PyExc_TypeError, "Unsupported buffer type"); // GCOVR_EXCL_LINE
67 m_Type = super->m_Type;
68 m_Size = super->m_Size;
69 }
70 }
71
72 JPBufferType::~JPBufferType()
73 = default;
74
75 JPPyObject JPBufferType::convertToPythonObject(JPJavaFrame& frame, jvalue value, bool cast)
76 {
77 JP_TRACE_IN("JPBufferClass::convertToPythonObject");
78 if (!cast && value.l == nullptr)
79 return JPPyObject::getNone(); // GCOVR_EXCL_LINE
80 JPPyObject wrapper = PyJPClass_create(frame, this);
81 JPPyObject obj = PyJPBuffer_create(frame, (PyTypeObject*) wrapper.get(), JPValue(this, value));
82 return obj;
83 JP_TRACE_OUT; // GCOVR_EXCL_LINE
84 }