1 /******************************************************************************* 2 * Copyright (c) 2015, 2016 Google, Inc and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * Stefan Xenos (Google) - Initial implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.core.nd.field; 15 16 import org.eclipse.jdt.internal.core.nd.Nd; 17 import org.eclipse.jdt.internal.core.nd.db.ModificationLog; 18 import org.eclipse.jdt.internal.core.nd.db.ModificationLog.Tag; 19 import org.eclipse.jdt.internal.core.nd.db.Database; 20 21 /** 22 * Declares a Nd field of type float. Can be used in place of {@link Field}<{@link Float}> in order to 23 * avoid extra GC overhead. 24 */ 25 public class FieldFloat extends BaseField { 26 private final Tag tag; 27 FieldFloat(String structName, int fieldNumber)28 public FieldFloat(String structName, int fieldNumber) { 29 setFieldName("field " + fieldNumber + ", a " + getClass().getSimpleName() + " in struct " + structName); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ 30 this.tag = ModificationLog.createTag("Writing " + getFieldName()); //$NON-NLS-1$ 31 } 32 get(Nd nd, long address)33 public float get(Nd nd, long address) { 34 Database db = nd.getDB(); 35 return db.getFloat(address + this.offset); 36 } 37 put(Nd nd, long address, float newValue)38 public void put(Nd nd, long address, float newValue) { 39 Database db = nd.getDB(); 40 db.getLog().start(this.tag); 41 try { 42 nd.getDB().putFloat(address + this.offset, newValue); 43 } finally { 44 db.getLog().end(this.tag); 45 } 46 } 47 48 @Override getRecordSize()49 public int getRecordSize() { 50 return Database.FLOAT_SIZE; 51 } 52 } 53