001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Rustem Rafikov
019: * @version $Revision$
020: */package org.apache.harmony.awt.nativebridge;
021:
022: public class FloatPointer extends VoidPointer {
023:
024: private static final int FLOAT_SIZE_FACTOR = 4;
025:
026: FloatPointer(int size, boolean direct) {
027: super (size * FLOAT_SIZE_FACTOR, direct);
028: }
029:
030: FloatPointer(VoidPointer p) {
031: super (p);
032: }
033:
034: FloatPointer(long addr) {
035: super (addr);
036: }
037:
038: FloatPointer(ByteBase base) {
039: super (base);
040: }
041:
042: /**
043: * Returns the element at the specified position.
044: * @param index
045: */
046: public float get(int index) {
047: return byteBase.getFloat(index * FLOAT_SIZE_FACTOR);
048: }
049:
050: /**
051: * Sets the element at the specified position.
052: * @param index
053: * @param value
054: */
055: public void set(int index, float value) {
056: byteBase.setFloat(index * FLOAT_SIZE_FACTOR, value);
057: }
058:
059: /**
060: * This method transfers int values into the given destination array.
061: *
062: * @param dst - The array into which values are to be written
063: * @param offset - The offset within the array of the first element to be written;
064: * must be non-negative and no larger than dst.length
065: * @param length - The maximum number of elements to be written to the given array;
066: * must be non-negative and no larger than dst.length - offset
067: */
068: public void get(float[] dst, int offset, int length) {
069: byteBase.getFloat(dst, offset, length);
070: }
071:
072: /**
073: * This method transfers short values from the given destination array.
074: *
075: * @param src - The array from which values are to be read
076: * @param offset - The offset within the array of the first element to be read;
077: * must be non-negative and no larger than dst.length
078: * @param length - The maximum number of elements to be read from the given array;
079: * must be non-negative and no larger than dst.length - offset
080: */
081: public void set(float[] src, int offset, int length) {
082: byteBase.setFloat(src, offset, length);
083: }
084:
085: /**
086: * returns class that represents the pointer to specified index.
087: */
088: public FloatPointer getElementPointer(int index) {
089: return new FloatPointer(byteBase.getBytesBaseElementPointer(
090: index * FLOAT_SIZE_FACTOR, FLOAT_SIZE_FACTOR));
091: }
092:
093: @Override
094: public int size() {
095: return byteBase.size() / FLOAT_SIZE_FACTOR;
096: }
097:
098: public void fill(float value, int size) {
099: int this Size = size();
100: for (int i = 0; i < size && i < thisSize; i++) {
101: byteBase.setFloat(i * FLOAT_SIZE_FACTOR, value);
102: }
103: }
104:
105: }
|