Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9f370c1595806e2c1060ec5627661ee229ac1843 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.debug.internal.ui.views.memory.renderings;

import java.math.BigInteger;
import java.util.ArrayList;

import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.debug.core.model.MemoryByte;

public class MemorySegment extends PlatformObject {

	private BigInteger fAddress;
	private BigInteger fEndAddress;
	private MemoryByte[] fBytes;
	private int fNumAddressableUnits;

	public MemorySegment(BigInteger address, MemoryByte[] bytes, int numAddressableUnits)
	{
		fAddress = address;
		fBytes = bytes;
		fNumAddressableUnits = numAddressableUnits;
	}

	public BigInteger getAddress() {
		return fAddress;
	}

	public MemoryByte[] getBytes() {
		return fBytes;
	}

	public int getNumAddressableUnits() {
		return fNumAddressableUnits;
	}

	public boolean containsAddress(BigInteger address)
	{
		if (getAddress().compareTo(address) <= 0 && getEndAddress().compareTo(address) >= 0)
			return true;
		return false;
	}

	public BigInteger getEndAddress()
	{
		if (fEndAddress == null)
		{
			fEndAddress = fAddress.add(BigInteger.valueOf(fNumAddressableUnits).subtract(BigInteger.ONE));
		}
		return fEndAddress;
	}

	/**
	 * @param start - zero-based start offset
	 * @param length - number of bytes to get
	 * @return the bytes from start offset to the end.
	 */
	public MemoryByte[] getBytes(int start, int length)
	{
		if (start < 0)
			return new MemoryByte[0];

		if (start + length > fBytes.length)
			return new MemoryByte[0];

		ArrayList<MemoryByte> ret = new ArrayList<MemoryByte>();

		for (int i=start; i< start+length; i++)
		{
			ret.add(fBytes[i]);
		}
		return ret.toArray(new MemoryByte[ret.size()]);
	}

}

Back to the top