OSDN Git Service

* java/nio/CharViewBufferImpl.java: New convenience constructor.
[pf3gnuchains/gcc-fork.git] / libjava / java / nio / FloatViewBufferImpl.java
1 /* FloatViewBufferImpl.java -- 
2    Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package java.nio;
40
41 class FloatViewBufferImpl extends FloatBuffer
42 {
43   /** Position in bb (i.e. a byte offset) where this buffer starts. */
44   private int offset;
45   private ByteBuffer bb;
46   private boolean readOnly;
47   private ByteOrder endian;
48   
49   FloatViewBufferImpl (ByteBuffer bb, int capacity)
50   {
51     super (capacity, capacity, 0, -1);
52     this.bb = bb;
53     this.offset = bb.position();
54     this.readOnly = bb.isReadOnly();
55     this.endian = bb.order();
56   }
57   
58   public FloatViewBufferImpl (ByteBuffer bb, int offset, int capacity,
59                               int limit, int position, int mark,
60                               boolean readOnly, ByteOrder endian)
61   {
62     super (capacity, limit, position, mark);
63     this.bb = bb;
64     this.offset = offset;
65     this.readOnly = readOnly;
66     this.endian = endian;
67   }
68
69   public float get ()
70   {
71     int p = position();
72     float result = ByteBufferHelper.getFloat(bb, (p << 2) + offset, endian);
73     position(p + 1);
74     return result;
75   }
76
77   public float get (int index)
78   {
79     return ByteBufferHelper.getFloat(bb, (index << 2) + offset, endian);
80   }
81
82   public FloatBuffer put (float value)
83   {
84     int p = position();
85     ByteBufferHelper.putFloat(bb, (p << 2) + offset, value, endian);
86     position(p + 1);
87     return this;
88   }
89   
90   public FloatBuffer put (int index, float value)
91   {
92     ByteBufferHelper.putFloat(bb, (index << 2) + offset, value, endian);
93     return this;
94   }
95
96   public FloatBuffer compact ()
97   {
98     if (position () > 0)
99       {
100         int count = limit () - position ();
101         bb.shiftDown(offset, offset + 4 * position(), 4 * count);
102         position (count);
103         limit (capacity ());
104       }
105     return this;
106   }
107   
108   public FloatBuffer slice ()
109   {
110     // Create a sliced copy of this object that shares its content.
111     return new FloatViewBufferImpl (bb, (position () >> 2) + offset,
112                                     remaining(), remaining(), 0, -1,
113                                     readOnly, endian);
114   }
115   
116   FloatBuffer duplicate (boolean readOnly)
117   {
118     int pos = position();
119     reset();
120     int mark = position();
121     position(pos);
122     return new FloatViewBufferImpl (bb, offset, capacity(), limit(),
123                                     pos, mark, readOnly, endian);
124   }
125   
126   public FloatBuffer duplicate ()
127   {
128     return duplicate(readOnly);
129   }
130
131   public FloatBuffer asReadOnlyBuffer ()
132   {
133     return duplicate(true);
134   }
135
136   public boolean isReadOnly ()
137   {
138     return readOnly;
139   }
140   
141   public boolean isDirect ()
142   {
143     return bb.isDirect ();
144   }
145   
146   public ByteOrder order ()
147   {
148     return endian;
149   }
150 }