001 /* Copyright (c) 2007 Timothy Wall, All Rights Reserved
002 *
003 * This library is free software; you can redistribute it and/or
004 * modify it under the terms of the GNU Lesser General Public
005 * License as published by the Free Software Foundation; either
006 * version 2.1 of the License, or (at your option) any later version.
007 * <p/>
008 * This library is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011 * Lesser General Public License for more details.
012 */
013 package com.ochafik.lang.jnaerator.runtime;
014
015 import org.rococoa.cocoa.CGFloat;
016
017 import com.sun.jna.ptr.ByReference;
018
019 public class CGFloatByReference extends ByReference {
020 public CGFloatByReference() {
021 this(0d);
022 }
023
024 public CGFloatByReference(float value) {
025 super(CGFloat.SIZE);
026 set(value);
027 }
028 public void set(float value) {
029 set(new CGFloat(value));
030 }
031
032 public CGFloatByReference(double value) {
033 super(CGFloat.SIZE);
034 set(value);
035 }
036 public void set(double value) {
037
038 set(new CGFloat(value));
039 }
040
041 public void set(CGFloat value) {
042 switch (CGFloat.SIZE) {
043 case 4:
044 getPointer().setFloat(0, value.floatValue());
045 break;
046 case 8:
047 getPointer().setDouble(0, value.doubleValue());
048 break;
049 default:
050 throw new UnsupportedOperationException("Unhandled CGFloat size : " + CGFloat.SIZE);
051 }
052 }
053 public CGFloat get() {
054 switch (CGFloat.SIZE) {
055 case 4:
056 return new CGFloat(getPointer().getFloat(0));
057 case 8:
058 return new CGFloat(getPointer().getDouble(0));
059 default:
060 throw new UnsupportedOperationException("Unhandled CGFloat size : " + CGFloat.SIZE);
061 }
062 }
063
064 public CGFloatByReference(CGFloat value) {
065 super(CGFloat.SIZE);
066 set(value);
067 }
068 }