/[classpath]/classpath/gnu/java/nio/FloatBufferImpl.java
ViewVC logotype

Diff of /classpath/gnu/java/nio/FloatBufferImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by mkoch, Tue Mar 11 11:48:51 2003 UTC revision 1.15 by mkoch, Mon May 19 08:36:27 2003 UTC
# Line 1  Line 1 
1  /* FloatBufferImpl.java --  /* FloatBufferImpl.java --
2     Copyright (C) 2002 Free Software Foundation, Inc.     Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 35  this exception to your version of the li Line 35  this exception to your version of the li
35  obligated to do so.  If you do not wish to do so, delete this  obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */  exception statement from your version. */
37    
38    
39  package gnu.java.nio;  package gnu.java.nio;
40    
41  import java.nio.ByteBuffer;  import java.nio.ByteBuffer;
# Line 48  import java.nio.ReadOnlyBufferException; Line 49  import java.nio.ReadOnlyBufferException;
49  public final class FloatBufferImpl extends FloatBuffer  public final class FloatBufferImpl extends FloatBuffer
50  {  {
51    private boolean readOnly;    private boolean readOnly;
52      
53    public FloatBufferImpl(int cap, int off, int lim)    public FloatBufferImpl (int capacity)
   {  
     super (cap, lim, off, 0);  
     this.backing_buffer = new float [cap];  
     readOnly = false;  
   }  
     
   public FloatBufferImpl(float[] array, int offset, int length)  
   {  
     super (array.length, length, offset, 0);  
     this.backing_buffer = array;  
     readOnly = false;  
   }  
     
   public FloatBufferImpl(FloatBufferImpl copy)  
54    {    {
55      super (copy.capacity (), copy.limit (), copy.position (), 0);      this (new float [capacity], 0, capacity, capacity, 0, -1, false);
     backing_buffer = copy.backing_buffer;  
     readOnly = copy.isReadOnly ();  
56    }    }
57        
58    private static native float[] nio_cast (byte[] copy);    public FloatBufferImpl (float[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
     
   FloatBufferImpl (byte[] copy)  
   {  
     super (copy.length, copy.length, 0, 0);  
     this.backing_buffer = copy != null ? nio_cast  (copy) : null;  
     readOnly = false;  
   }  
   
   private static native byte nio_get_Byte (FloatBufferImpl b, int index, int limit);  
   
   private static native void nio_put_Byte (FloatBufferImpl b, int index, int limit, byte value);  
   
   public ByteBuffer asByteBuffer()  
59    {    {
60      ByteBufferImpl res = new ByteBufferImpl (backing_buffer);      super (buffer, offset, capacity, limit, position, mark);
61      res.limit ((limit () * 1) / 4);      this.readOnly = readOnly;
     return res;  
62    }    }
63        
64    public boolean isReadOnly ()    public boolean isReadOnly ()
# Line 95  public final class FloatBufferImpl exten Line 66  public final class FloatBufferImpl exten
66      return readOnly;      return readOnly;
67    }    }
68        
69    public FloatBuffer slice()    public FloatBuffer slice ()
70    {    {
71      return new FloatBufferImpl (this);      return new FloatBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
72    }    }
73        
74    public FloatBuffer duplicate()    public FloatBuffer duplicate ()
75    {    {
76      return new FloatBufferImpl(this);      return new FloatBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
77    }    }
78        
79    public FloatBuffer asReadOnlyBuffer()    public FloatBuffer asReadOnlyBuffer ()
80    {    {
81      FloatBufferImpl result = new FloatBufferImpl (this);      return new FloatBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
     result.readOnly = true;  
     return result;  
82    }    }
83        
84    public FloatBuffer compact()    public FloatBuffer compact ()
85    {    {
86        int copied = 0;
87        
88        while (remaining () > 0)
89          {
90            put (copied, get ());
91            copied++;
92          }
93    
94        position (copied);
95      return this;      return this;
96    }    }
97        
98    public boolean isDirect()    public boolean isDirect ()
99    {    {
100      return false;      return false;
101    }    }
102      
103    final public float get()    /**
104       * Relative get method. Reads the next <code>float</code> from the buffer.
105       */
106      final public float get ()
107    {    {
108      float e = backing_buffer[position()];      float result = backing_buffer [position ()];
109      position(position()+1);      position (position () + 1);
110      return e;      return result;
111    }    }
112        
113    final public FloatBuffer put(float b)    /**
114       * Relative put method. Writes <code>value</code> to the next position
115       * in the buffer.
116       *
117       * @exception ReadOnlyBufferException If this buffer is read-only.
118       */
119      final public FloatBuffer put (float value)
120    {    {
121      if (readOnly)      if (readOnly)
122        throw new ReadOnlyBufferException ();        throw new ReadOnlyBufferException ();
123                            
124      backing_buffer[position()] = b;      backing_buffer [position ()] = value;
125      position(position()+1);      position (position () + 1);
126      return this;      return this;
127    }    }
128        
129    final public float get(int index)    /**
130    {     * Absolute get method. Reads the <code>float</code> at position
131      return backing_buffer[index];     * <code>index</code>.
132    }     *
133         * @exception IndexOutOfBoundsException If index is negative or not smaller
134    final public FloatBuffer put(int index, float b)     * than the buffer's limit.
135       */
136      final public float get (int index)
137      {
138        return backing_buffer [index];
139      }
140      
141      /**
142       * Absolute put method. Writes <code>value</value> to position
143       * <code>index</code> in the buffer.
144       *
145       * @exception IndexOutOfBoundsException If index is negative or not smaller
146       * than the buffer's limit.
147       * @exception ReadOnlyBufferException If this buffer is read-only.
148       */
149      final public FloatBuffer put (int index, float value)
150    {    {
151      if (readOnly)      if (readOnly)
152        throw new ReadOnlyBufferException ();        throw new ReadOnlyBufferException ();
153                    
154      backing_buffer[index] = b;      backing_buffer [index] = value;
155      return this;      return this;
156    }    }
157        
158    final public ByteOrder order ()    final public ByteOrder order ()
159    {    {
160      return ByteOrder.BIG_ENDIAN;      return ByteOrder.nativeOrder ();
161    }    }
162  }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26