Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 159a032e9f37a96da892ab174e4b3689893551e3 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.core.model;


/**
 * A byte of memory in a meomry block. Each byte of memory has a value and
 * attributes indicating if the byte is read-only, valid, or if its value has
 * changed.
 * <p>
 * Clients may subclass this class.
 * TODO: when would a client subclass this class?
 * </p>
 * @since 3.1
 */
public abstract class MemoryByte {
	
    /**
     * Bit mask used to indicate a byte is read-only.
     */
	public static final byte	READONLY	= 0x01;
	
	/**
	 * Bit mask used to indicate a byte is valid.
	 * 
	 * TODO: specify what makes a byte valid - when is a byte invalid?
	 */
	public static final byte	VALID		= 0x02;
	
	/**
	 * Bit mask used to indicate a byte has changed.
	 * 
	 * TODO: specify CHANGE flag more clearly - changed since when? 
	 */
	public static final byte	CHANGED		= 0x04;
	
	/**
	 * Bit mask used to indicate a byte has no history to
	 * determine if the byte is changed or not. The change bit has
	 * no meaning if this bit is on.
	 */
	public static final byte 	UNKNOWN		= 0x08;
	
	/**
	 * Value of this byte.
	 */
	protected byte value;
	
	/**
	 * Attribute flags.
	 * <p>
	 * To specify VALID:  flags |= MemoryByte.VALID;
	 * To specify READONLY:  flags |= MemoryByte.READONLY;
	 * </p>
	 */
	protected byte flags;
	
	/**
	 * Constructs a read-write, invalid, unchanged memory byte with a
	 * value of 0.
	 * 
	 * TODO: should the valid flag be set for convenience?
	 */
	public MemoryByte() {
	}
	
	/**
	 * Constructs a read-write, invalid, unchanged memory byte with
	 * the given value.
	 * 
	 * @param byteValue value of this memory byte
	 * 
	 * TODO: should the valid flag be set for convenience?
	 */
	public MemoryByte(byte byteValue) {
		value = byteValue;
	}
	
	/**
	 * Constructs a memory byte with the given value and attributes.
	 * 
	 * @param byteValue value of this memory byte
	 * @param byteFlags attributes of the byte specified as a bit mask 
	 */
	public MemoryByte(byte byteValue, byte byteFlags) {
		value = byteValue;
		flags = byteFlags;
	}

	/**
	 * Returns this memory byte's attribute as a bit mask.
	 * 
	 * @return this memory byte's attribute as a bit mask
	 */
	public byte getFlags() {
		return flags;
	}
	/**
	 * Sets this memory byte's attributes based on the given bit mask.
	 * 
	 * @param flags bit mask of attributes
	 */
	public void setFlags(byte flags) {
		this.flags = flags;
	}

	/**
	 * Returns the value of this memory byte.
	 * 
	 * @return the value of this memory byte
	 */
	public byte getValue() {
		return value;
	}
	
	/**
	 * Sets the value of this memory byte.
	 * 
	 * @param value the new value of this memory byte
	 */
	public void setValue(byte value) {
		this.value = value;
	}
	
	/**
	 * Sets whether this memory byte is valid.
	 * 
	 * @param valid whether this memory byte is valid
	 */
	public void setValid(boolean valid) {
		flags |= MemoryByte.VALID;
		if (!valid)
			flags ^= MemoryByte.VALID;
	}
	
	/**
	 * Returns whether this memory byte is valid.
	 * 
	 * @return whether this memory byte is valid
	 */
	public boolean isValid() {
		return ((flags & MemoryByte.VALID) == MemoryByte.VALID);
	}
	
	/**
	 * Sets whether this memory byte is read-only.
	 * 
	 * @param readonly whether this memory byte is read-only.
	 */
	public void setReadonly(boolean readonly) {
		flags |= MemoryByte.READONLY;
		if (!readonly)
			flags ^= MemoryByte.READONLY;
	}
	
	/**
	 * Returns whether this memory byte is read-only.
	 * 
	 * @return whether this memory byte is read-only
	 */
	public boolean isReadonly() {
		return ((flags & MemoryByte.READONLY) == MemoryByte.READONLY);
	}
	
	/**
	 * Sets whether this memory byte has changed.
	 * 
	 * @param changed whether this memory byte has changed
	 */
	public void setChanged(boolean changed) {
		flags |= MemoryByte.CHANGED;
		if (!changed)
			flags ^= MemoryByte.CHANGED;
	}
	
	/**
	 * Returns whether this memory byte has changed.
	 * 
	 * @return whether this memory byte has changed
	 */
	public boolean isChanged() {
		return ((flags & MemoryByte.CHANGED) == MemoryByte.CHANGED);
	}
	
	/**
	 * Sets whether the value of this byte is unknown. When a value
	 * is unknown, the change state of a memory byte has no meaning.
	 * 
	 * TODO: this flag should be changed to the 'positive' KNOWN rather than
	 *  the 'negative' UNKNOWN. All other flags read in the positive state:
	 *  is valid, is read-only, is changed. Similarly, this flag should read
	 *  as is known.
	 * 
	 * @param unknown whether the value of this byte is unknown
	 */
	public void setUnknown(boolean unknown) {
		flags |= MemoryByte.UNKNOWN;
		if (!unknown)
			flags ^= MemoryByte.UNKNOWN;
	}
	
	/**
	 * Returns whether the value of this byte is unknown. When a value
	 * is unknown, the change state of a memory byte has no meaning.
	 * 
	 * @return whether the value of this byte is unknown
	 */
	public boolean isUnknown() {
		return ((flags & MemoryByte.UNKNOWN) == MemoryByte.UNKNOWN);
	}
	
	
}

Back to the top