MCPcopy Index your code
hub / github.com/java-native-access/jna / getValue

Method getValue

src/com/sun/jna/Pointer.java:361–455  ·  view source on GitHub ↗
(long offset, Class<?> type, Object currentValue)

Source from the content-addressed store, hash-verified

359 //////////////////////////////////////////////////////////////////////////
360
361 Object getValue(long offset, Class<?> type, Object currentValue) {
362
363 Object result = null;
364 if (Structure.class.isAssignableFrom(type)) {
365 Structure s = (Structure)currentValue;
366 if (Structure.ByReference.class.isAssignableFrom(type)) {
367 s = Structure.updateStructureByReference((Class<Structure>) type, s, getPointer(offset));
368 } else {
369 s.useMemory(this, (int)offset, true);
370 s.read();
371 }
372 result = s;
373 } else if (type == boolean.class || type == Boolean.class) {
374 result = Function.valueOf(getInt(offset) != 0);
375 } else if (type == byte.class || type == Byte.class) {
376 result = Byte.valueOf(getByte(offset));
377 } else if (type == short.class || type == Short.class) {
378 result = Short.valueOf(getShort(offset));
379 } else if (type == char.class || type == Character.class) {
380 result = Character.valueOf(getChar(offset));
381 } else if (type == int.class || type == Integer.class) {
382 result = Integer.valueOf(getInt(offset));
383 } else if (type == long.class || type == Long.class) {
384 result = Long.valueOf(getLong(offset));
385 } else if (type == float.class || type == Float.class) {
386 result = Float.valueOf(getFloat(offset));
387 } else if (type == double.class || type == Double.class) {
388 result = Double.valueOf(getDouble(offset));
389 } else if (Pointer.class.isAssignableFrom(type)) {
390 Pointer p = getPointer(offset);
391 if (p != null) {
392 Pointer oldp = currentValue instanceof Pointer
393 ? (Pointer)currentValue : null;
394 if (oldp == null || p.peer != oldp.peer) {
395 result = p;
396 } else {
397 result = oldp;
398 }
399 }
400 } else if (type == String.class) {
401 Pointer p = getPointer(offset);
402 result = p != null ? p.getString(0) : null;
403 } else if (type == WString.class) {
404 Pointer p = getPointer(offset);
405 result = p != null ? new WString(p.getWideString(0)) : null;
406 } else if (Callback.class.isAssignableFrom(type)) {
407 // Overwrite the Java memory if the native pointer is a different
408 // function pointer.
409 Pointer fp = getPointer(offset);
410 if (fp == null) {
411 result = null;
412 } else {
413 Callback cb = (Callback)currentValue;
414 Pointer oldfp = CallbackReference.getFunctionPointer(cb);
415 if (!fp.equals(oldfp)) {
416 cb = CallbackReference.getCallback(type, fp);
417 }
418 result = cb;

Callers 1

readArrayMethod · 0.95

Calls 15

getPointerMethod · 0.95
useMemoryMethod · 0.95
readMethod · 0.95
valueOfMethod · 0.95
getIntMethod · 0.95
getByteMethod · 0.95
getShortMethod · 0.95
getCharMethod · 0.95
getLongMethod · 0.95
getFloatMethod · 0.95
getDoubleMethod · 0.95

Tested by

no test coverage detected