commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r786431 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ test/org/apache/commons/runtime/
Date Fri, 19 Jun 2009 09:39:55 GMT
Author: mturk
Date: Fri Jun 19 09:39:54 2009
New Revision: 786431

URL: http://svn.apache.org/viewvc?rev=786431&view=rev
Log:
Add Structure sizeof method

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java?rev=786431&r1=786430&r2=786431&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java
Fri Jun 19 09:39:54 2009
@@ -46,6 +46,13 @@
     }
 
     /**
+     * Get a size of this {@code structure}.
+     *
+     * @return {@code int} representing the size.
+     */
+    public abstract int sizeof();
+
+    /**
      * Get a {@code byte} value this {@code structure} contains at the
      * {@code index}.
      *

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java?rev=786431&r1=786430&r2=786431&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java
Fri Jun 19 09:39:54 2009
@@ -45,6 +45,11 @@
     private static native void   poke4(int addr, float  v);
     private static native void   poke5(int addr, double v);
 
+    public int sizeof()
+    {
+        return POINTER.PLENGTH;
+    }
+
     public boolean equals(Object other)
     {
         if (other == null)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java?rev=786431&r1=786430&r2=786431&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java
Fri Jun 19 09:39:54 2009
@@ -45,6 +45,11 @@
     private static native void   poke4(long addr, float  v);
     private static native void   poke5(long addr, double v);
 
+    public int sizeof()
+    {
+        return (int)POINTER.PLENGTH;
+    }
+
     public boolean equals(Object other)
     {
         if (other == null)

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=786431&r1=786430&r2=786431&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java Fri
Jun 19 09:39:54 2009
@@ -283,6 +283,17 @@
         p.free();
     }
 
+    public void testStructSize()
+        throws Throwable
+    {
+        Pointer p = Memory.calloc(1000);
+        assertNotNull("Pointer", p);
+        Structure s = p.asStructure();
+        assertEquals("Size", 1000, s.sizeof());
+
+        p.free();
+    }
+
     public void testPoke()
         throws Throwable
     {



Mime
View raw message