KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > core > model > MemoryByte


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.core.model;
12
13
14 /**
15  * A byte of memory in a memory block. Each byte of memory has a value and
16  * attributes indicating if the byte is read-only, valid, or if its value has
17  * changed.
18  * <p>
19  * Clients may instantiate this class. Clients may subclass this class to
20  * add other attributes to a memory byte, as required.
21  * </p>
22  * @since 3.1
23  * @see org.eclipse.debug.core.model.IMemoryBlockExtension
24  */

25 public class MemoryByte {
26     
27     /**
28      * Bit mask used to indicate a byte is writable.
29      */

30     public static final byte WRITABLE = 0x01;
31     
32     /**
33      * Bit mask used to indicate a byte is readable.
34      * A memory byte is readable when its value and attributes are retrievable.
35      * Otherwise, a byte is considered non-readable.
36      */

37     public static final byte READABLE = 0x02;
38     
39     /**
40      * Bit mask used to indicate a byte has changed since the last
41      * suspend event.
42      *
43      * @see org.eclipse.debug.core.DebugEvent#SUSPEND
44      */

45     public static final byte CHANGED = 0x04;
46     
47     /**
48      * Bit mask used to indicate a memory byte has history to
49      * determine if its value has changed. When a memory byte's
50      * history is unknown, the change state has no meaning.
51      */

52     public static final byte HISTORY_KNOWN = 0x08;
53     
54     /**
55      * Bit mask used to indicate a this byte of memory
56      * is big endian. If this byte of memory is little endian,
57      * turn this bit mask to off.
58      */

59     public static final byte BIG_ENDIAN = 0x10;
60     
61     /**
62      * Bit mask used to indicate that the endianess of this byte
63      * of memory is known. When a memory byte's endianess is
64      * unknown, the endianess of this byte has no meaning.
65      */

66     public static final byte ENDIANESS_KNOWN = 0x20;
67     
68     /**
69      * Value of this byte.
70      */

71     protected byte value;
72     
73     /**
74      * Attribute flags.
75      * <p>
76      * To specify READABLE: flags |= MemoryByte.READABLE;
77      * To specify WRITABLE: flags |= MemoryByte.WRITABLE;
78      * </p>
79      */

80     protected byte flags;
81     
82     /**
83      * Constructs a readable, writable memory byte without a change history,
84      * and a value of 0. The byte's endianess is known and is little endian
85      * by default.
86      */

87     public MemoryByte() {
88         this((byte)0, (byte)(WRITABLE | READABLE | ENDIANESS_KNOWN));
89     }
90     
91     /**
92      * Constructs a readable, writable memory byte without a change history,
93      * with the given value. The byte's endianess is known and is little endian
94      * by default.
95      *
96      * @param byteValue value of this memory byte
97      *
98      */

99     public MemoryByte(byte byteValue) {
100         this(byteValue, (byte)(WRITABLE | READABLE | ENDIANESS_KNOWN));
101     }
102     
103     /**
104      * Constructs a memory byte with the given value and attributes.
105      *
106      * @param byteValue value of this memory byte
107      * @param byteFlags attributes of the byte specified as a bit mask
108      */

109     public MemoryByte(byte byteValue, byte byteFlags) {
110         value = byteValue;
111         flags = byteFlags;
112     }
113
114     /**
115      * Returns this memory byte's attribute as a bit mask.
116      *
117      * @return this memory byte's attribute as a bit mask
118      */

119     public byte getFlags() {
120         return flags;
121     }
122     /**
123      * Sets this memory byte's attributes based on the given bit mask.
124      *
125      * @param flags bit mask of attributes
126      */

127     public void setFlags(byte flags) {
128         this.flags = flags;
129     }
130
131     /**
132      * Returns the value of this memory byte.
133      *
134      * @return the value of this memory byte
135      */

136     public byte getValue() {
137         return value;
138     }
139     
140     /**
141      * Sets the value of this memory byte.
142      *
143      * @param value the new value of this memory byte
144      */

145     public void setValue(byte value) {
146         this.value = value;
147     }
148     
149     /**
150      * Sets whether this memory byte is readable. A memory byte
151      * is considered readable when its value and attributes are
152      * retrievable.
153      *
154      * @param readable whether this memory byte is readable
155      */

156     public void setReadable(boolean readable) {
157         flags |= MemoryByte.READABLE;
158         if (!readable)
159             flags ^= MemoryByte.READABLE;
160     }
161     
162     /**
163      * Returns whether this memory byte is readable. A memory byte
164      * is considered readable when its value and attributes are
165      * retrievable.
166      *
167      * @return whether this memory byte is readable
168      */

169     public boolean isReadable() {
170         return ((flags & MemoryByte.READABLE) == MemoryByte.READABLE);
171     }
172     
173     /**
174      * Sets whether this memory byte is writable.
175      *
176      * @param writable whether this memory byte is writable.
177      */

178     public void setWritable(boolean writable) {
179         flags |= MemoryByte.WRITABLE;
180         if (!writable)
181             flags ^= MemoryByte.WRITABLE;
182     }
183     
184     /**
185      * Returns whether this memory byte is writable.
186      *
187      * @return whether this memory byte is writable
188      */

189     public boolean isWritable() {
190         return ((flags & MemoryByte.WRITABLE) == MemoryByte.WRITABLE);
191     }
192     
193     /**
194      * Sets whether this memory byte has changed.
195      *
196      * @param changed whether this memory byte has changed
197      */

198     public void setChanged(boolean changed) {
199         flags |= MemoryByte.CHANGED;
200         if (!changed)
201             flags ^= MemoryByte.CHANGED;
202     }
203     
204     /**
205      * Returns whether this memory byte has changed.
206      *
207      * @return whether this memory byte has changed
208      */

209     public boolean isChanged() {
210         return ((flags & MemoryByte.CHANGED) == MemoryByte.CHANGED);
211     }
212     
213     /**
214      * Sets whether the history of this byte is known. When history
215      * is unknown, the change state of a memory byte has no meaning.
216      *
217      * @param known whether the change state of this byte is known
218      */

219     public void setHistoryKnown(boolean known) {
220         flags |= MemoryByte.HISTORY_KNOWN;
221         if (!known)
222             flags ^= MemoryByte.HISTORY_KNOWN;
223     }
224     
225     /**
226      * Returns whether the history of this byte is known. When history
227      * is unknown, the change state of a memory byte has no meaning.
228      *
229      * @return whether the change state of this byte is known
230      */

231     public boolean isHistoryKnown() {
232         return ((flags & MemoryByte.HISTORY_KNOWN) == MemoryByte.HISTORY_KNOWN);
233     }
234     
235     /**
236      * Sets whether this byte of memory is big endian.
237      *
238      * @param isBigEndian whether the byte of memory is big endian.
239      */

240     public void setBigEndian(boolean isBigEndian)
241     {
242         flags |= MemoryByte.BIG_ENDIAN;
243         if (!isBigEndian)
244             flags ^= MemoryByte.BIG_ENDIAN;
245     }
246     
247     /**
248      * Returns whether this byte of memory is big endian.
249      *
250      * @return whether the byte of memory is big endian.
251      */

252     public boolean isBigEndian()
253     {
254         return ((flags & MemoryByte.BIG_ENDIAN) == MemoryByte.BIG_ENDIAN);
255     }
256     
257     /**
258      * Sets whether the endianess of this byte of memory is known.
259      * If the endianess is unknown, the endianess of this byte
260      * has no meaning.
261      *
262      * @param isEndianessKnown whether the endianess of this byte is known.
263      */

264     public void setEndianessKnown(boolean isEndianessKnown)
265     {
266         flags |= MemoryByte.ENDIANESS_KNOWN;
267         if (!isEndianessKnown)
268             flags ^= MemoryByte.ENDIANESS_KNOWN;
269     }
270     
271     /**
272      * Returns whether the endianess of this byte of memory is known.
273      * If the endianess is unknown, the endianess of this byte
274      * has no meaning.
275      *
276      * @return whether the endianess of this byte of memory is known.
277      */

278     public boolean isEndianessKnown()
279     {
280         return ((flags & MemoryByte.ENDIANESS_KNOWN) == MemoryByte.ENDIANESS_KNOWN);
281     }
282     
283 }
284
Popular Tags