1 package com4j; 2 3 import java.nio.ByteBuffer ; 4 import java.nio.ByteOrder ; 5 6 7 28 public final class Variant extends Number { 29 32 final ByteBuffer image = ByteBuffer.allocateDirect(16); 33 34 39 public static enum Type implements ComEnum { 40 VT_EMPTY(0), 41 VT_NULL(1), 42 VT_I2(2), 43 VT_I4(3), 44 VT_R4(4), 45 VT_R8(5), 46 VT_CY(6), 47 VT_DATE(7), 48 VT_BSTR(8), 49 VT_DISPATCH(9), 50 VT_ERROR(10), 51 VT_BOOL(11), 52 VT_VARIANT(12), 53 VT_UNKNOWN(13), 54 VT_DECIMAL(14), 55 VT_RECORD(36), 56 VT_I1(16), 57 VT_UI1(17), 58 VT_UI2(18), 59 VT_UI4(19), 60 VT_INT(22), 61 VT_UINT(23), 62 ; 65 66 private final int value; 67 68 private Type( int value ) { 69 this.value = value; 70 } 71 72 public int comEnumValue() { 73 return value; 74 } 75 } 76 77 80 public Variant() { 81 image.order(ByteOrder.LITTLE_ENDIAN); 82 } 83 84 93 public void clear() { 94 clear0(image); 95 } 96 97 100 public void finalize() { 101 clear(); 102 } 103 104 107 private static native void clear0( ByteBuffer image ); 108 109 112 public void setType( Type t ) { 113 image.putLong(0,t.comEnumValue()); 114 } 115 116 119 public Type getType() { 120 return EnumDictionary.get(Type.class).constant((int)image.getLong(0)); 121 } 122 123 124 private static native void changeType0( int type, ByteBuffer image ); 125 126 129 private void changeType( Type t ) { 130 changeType0( t.comEnumValue(), image ); 131 } 132 133 public int intValue() { 134 changeType(Type.VT_I4); 135 return image.getInt(8); 136 } 137 138 public long longValue() { 139 return intValue(); 141 } 142 143 public float floatValue() { 144 changeType(Type.VT_R4); 145 return image.getFloat(8); 146 } 147 148 public double doubleValue() { 149 changeType(Type.VT_R8); 150 return image.getDouble(8); 151 } 152 153 public <T extends Com4jObject> T object( Class <T> type ) { 154 changeType(Type.VT_UNKNOWN); 155 int ptr = image.getInt(8); 156 if(ptr==0) return null; 157 Native.addRef(ptr); 158 return Wrapper.create(type,ptr); 159 } 160 } 161 | Popular Tags |