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.Database;
19 import org.eclipse.jdt.internal.core.nd.db.ModificationLog.Tag;
20 
21 /**
22  * Declares a Nd field of type double. Can be used in place of {@link Field}&lt{@link Double}&gt in order to
23  * avoid extra GC overhead.
24  */
25 public class FieldDouble extends BaseField {
26 	private final Tag tag;
27 
FieldDouble(String structName, int fieldNumber)28 	public FieldDouble(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 "); //$NON-NLS-1$
31 	}
32 
get(Nd nd, long address)33 	public double get(Nd nd, long address) {
34 		Database db = nd.getDB();
35 		return db.getDouble(address + this.offset);
36 	}
37 
put(Nd nd, long address, double newValue)38 	public void put(Nd nd, long address, double newValue) {
39 		Database db = nd.getDB();
40 		db.getLog().start(this.tag);
41 		try {
42 			nd.getDB().putDouble(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.DOUBLE_SIZE;
51 	}
52 }
53