⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cptr.java

📁 学习JAVA编程的示例
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * @(#)CPtr.java	1.8 98/03/22
 *
 * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
 *
 * See also the LICENSE file in this distribution.
 */

/**
 * An abstraction for a C pointer data type.  A CPtr instance represents, on
 * the Java side, a C pointer.  The C pointer could be any <em>type</em> of C
 * pointer.  Methods such as <code>copyIn</code>, <code>copyOut</code>,
 * <code>getXXX</code>, and <code>setXXX</code>, provide
 * means to indirect the underlying C pointer. 
 *
 * @author Sheng Liang
 * @see    CFunc
 */
public class CPtr {

    /**
     * The size of a C pointer on the platform this Java virtual machine is
     * running on.
     */
    public static final int SIZE;
    
    /**
     * A canonical representation of C's NULL pointer.
     */
    public static final CPtr NULL;
    
    
    /**
     * Compares this <code>CPtr</code> to the specified object.
     *
     * @param other a <code>CPtr</code>
     * @return      true if the class of this <code>CPtr</code> object and the
     *		    class of <code>other</code> are exactly equal, and the C
     *		    pointers being pointed to by these objects are also
     *		    equal. Returns false otherwise.
     */
    public boolean equals(Object other) {
        if (other == null)
	    return false;
	if (other == this)
	    return true;
	if (CPtr.class != other.getClass())
	    return false;
	return peer == ((CPtr)other).peer;
    }

    /**
     * Returns a hashcode for the C pointer represented by this
     * <code>Cptr</code> object.
     *
     * @return a hash code value for the represented C pointer.
     */
    public int hashCode() {
        return (int)((peer >>> 32) + (peer & 0xFFFFFFFF));
    }

    /**
     * Indirect the C pointer, copying <em>into</em> memory pointed to by C
     * pointer, from the specified array.
     *
     * @param bOff   byte offset from pointer into which data is copied
     * @param buf    <code>byte</code> array from which to copy
     * @param index  array index from which to start copying
     * @param length number of elements from <code>buf</code> that must be
     *               copied
     */
    public native void copyIn(int bOff, byte[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>into</em> memory pointed to by C
     * pointer, from the specified array.
     *
     * @param bOff   byte offset from pointer into which data is copied
     * @param buf    <code>short</code> array from which to copy
     * @param index  array index from which to start copying
     * @param length number of elements from <code>buf</code> that must be
     *               copied
     */
    public native void copyIn(int bOff, short[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>into</em> memory pointed to by C
     * pointer, from the specified array.
     *
     * @param bOff   byte offset from pointer into which data is copied
     * @param buf    <code>char</code> array from which to copy
     * @param index  array index from which to start copying
     * @param length number of elements from <code>buf</code> that must be
     *               copied
     */
    public native void copyIn(int bOff, char[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>into</em> memory pointed to by C
     * pointer, from the specified array.
     *
     * @param bOff   byte offset from pointer into which data is copied
     * @param buf    <code>int</code> array from which to copy
     * @param index  array index from which to start copying
     * @param length number of elements from <code>buf</code> that must be
     *               copied
     */
    public native void copyIn(int bOff, int[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>into</em> memory pointed to by C
     * pointer, from the specified array.
     *
     * @param bOff   byte offset from pointer into which data is copied
     * @param buf    <code>long</code> array from which to copy
     * @param index  array index from which to start copying
     * @param length number of elements from <code>buf</code> that must be
     *               copied
     */
    public native void copyIn(int bOff, long[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>into</em> memory pointed to by C
     * pointer, from the specified array.
     *
     * @param bOff   byte offset from pointer into which data is copied
     * @param buf    <code>float</code> array from which to copy
     * @param index  array index from which to start copying
     * @param length number of elements from <code>buf</code> that must be
     *               copied
     */
    public native void copyIn(int bOff, float[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>into</em> memory pointed to by C
     * pointer, from the specified array.
     *
     * @param bOff   byte offset from pointer into which data is copied
     * @param buf    <code>double</code> array from which to copy
     * @param index  array index from which to start copying
     * @param length number of elements from <code>buf</code> that must be
     *               copied
     */
    public native void copyIn(int bOff, double[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>from</em> memory pointed to by C
     * pointer, into the specified array.
     *
     * @param bOff   byte offset from pointer into which data is copied
     * @param buf    <code>byte</code> array into which data is copied
     * @param index  array index from which to start copying
     * @param length number of elements from C pointer that must be copied
     */
    public native void copyOut(int bOff, byte[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>from</em> memory pointed to by C
     * pointer, into the specified array.
     *
     * @param bOff   byte offset from pointer from which data is copied
     * @param buf    <code>short</code> array into which data is copied
     * @param index  array index to which data is copied
     * @param length number of elements from C pointer that must be copied
     */
    public native void copyOut(int bOff, short[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>from</em> memory pointed to by C
     * pointer, into the specified array.
     *
     * @param bOff   byte offset from pointer from which data is copied
     * @param buf    <code>char</code> array into which data is copied
     * @param index  array index to which data is copied
     * @param length number of elements from C pointer that must be copied
     */
    public native void copyOut(int bOff, char[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>from</em> memory pointed to by C
     * pointer, into the specified array.
     *
     * @param bOff   byte offset from pointer from which data is copied
     * @param buf    <code>int</code> array into which data is copied
     * @param index  array index to which data is copied
     * @param length number of elements from C pointer that must be copied
     */
    public native void copyOut(int bOff, int[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>from</em> memory pointed to by C
     * pointer, into the specified array.
     *
     * @param bOff   byte offset from pointer from which data is copied
     * @param buf    <code>long</code> array into which data is copied
     * @param index  array index to which data is copied
     * @param length number of elements from C pointer that must be copied
     */
    public native void copyOut(int bOff, long[] buf, int index, int length);

    /**
     * Indirect the C pointer, copying <em>from</em> memory pointed to by C
     * pointer, into the specified array.
     *
     * @param bOff   byte offset from pointer from which data is copied

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -