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