author | Claus Gittinger <cg@exept.de> |
Tue, 21 Feb 2006 17:52:07 +0100 | |
changeset 9178 | f6ec6e771009 |
parent 9005 | b82aa6bdc487 |
child 9185 | 283bfee8b9ab |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
300 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
6492 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
15 |
ArrayedCollection subclass:#UninterpretedBytes |
1266 | 16 |
instanceVariableNames:'' |
3323 | 17 |
classVariableNames:'IsBigEndian' |
1266 | 18 |
poolDictionaries:'' |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
19 |
category:'Collections-Abstract' |
1 | 20 |
! |
21 |
||
3433 | 22 |
!UninterpretedBytes primitiveDefinitions! |
23 |
%{ |
|
24 |
/* |
|
25 |
* Notice: I am abstract, and my subclasses may be anything. |
|
26 |
* Therefore, the code must always handle the fallback case |
|
27 |
* where the receiver is neither an ExternalBytes nor a ByteArray. |
|
28 |
* (which are, however, the most common) |
|
29 |
* |
|
30 |
* macro to fetch my byte address and size-in-bytes; |
|
31 |
* convenient for inline-C code. |
|
32 |
* (yes, C is bad ...) |
|
33 |
*/ |
|
34 |
#define __fetchBytePointerAndSize__(o, pPtr, pSize) \ |
|
35 |
{\ |
|
36 |
if (__isNonNilObject(o)) { \ |
|
4308 | 37 |
if (__qClass(o) == ByteArray) { \ |
38 |
*(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \ |
|
3433 | 39 |
*(pSize) = __byteArraySize(o); \ |
40 |
} else if (__qClass(o) == ExternalBytes) { \ |
|
41 |
OBJ __sz__ = __externalBytesSize(o); \ |
|
42 |
if (__isSmallInteger(__sz__)) { \ |
|
43 |
*(pSize) = __intVal(__sz__); \ |
|
4308 | 44 |
*(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \ |
3433 | 45 |
} else { \ |
4308 | 46 |
*(pPtr) = (unsigned char *)0; \ |
3433 | 47 |
} \ |
48 |
} else { \ |
|
4308 | 49 |
*(pPtr) = (unsigned char *)0; \ |
3433 | 50 |
} \ |
51 |
} else { \ |
|
4308 | 52 |
*(pPtr) = (unsigned char *)0; \ |
3433 | 53 |
} \ |
54 |
} |
|
55 |
||
56 |
%} |
|
57 |
! ! |
|
58 |
||
68 | 59 |
!UninterpretedBytes class methodsFor:'documentation'! |
1 | 60 |
|
88 | 61 |
copyright |
62 |
" |
|
63 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
300 | 64 |
All Rights Reserved |
88 | 65 |
|
66 |
This software is furnished under a license and may be used |
|
67 |
only in accordance with the terms of that license and with the |
|
68 |
inclusion of the above copyright notice. This software may not |
|
69 |
be provided or otherwise made available to, or used by, any |
|
70 |
other person. No title to or ownership of the software is |
|
71 |
hereby transferred. |
|
72 |
" |
|
73 |
! |
|
74 |
||
68 | 75 |
documentation |
76 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
77 |
UninterpretedBytes provides the common protocol for byte-storage |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
78 |
containers; concrete subclasses are |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
79 |
ByteArray (which store the bytes within the |
4308 | 80 |
Smalltalk object memory) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
81 |
and |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
82 |
ExternalBytes (which store the bytes in the malloc-heap). |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
83 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
84 |
UninterpretedBytes itself is abstract, so no instances of it can be created. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
85 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
86 |
[See also:] |
4308 | 87 |
ByteArray String ExternalBytes |
1294 | 88 |
|
89 |
[author:] |
|
4308 | 90 |
Claus Gittinger |
3433 | 91 |
|
92 |
[Notice:] |
|
93 |
Notice the confusion due to multiple methods with the same |
|
4308 | 94 |
functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:'). |
95 |
The reason is that at the time this class was written, |
|
96 |
ST80 sid not offer protocol to specify the byteOrder, and |
|
97 |
ST/X provided methods ending in 'MSB:' for this. |
|
98 |
In the meanwhile, VW added protocol ending in 'bigEndian:', |
|
3433 | 99 |
which has been added here for compatibility. |
100 |
(certainly a point, where an ansi-standard will help) |
|
68 | 101 |
" |
102 |
! ! |
|
1 | 103 |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
104 |
!UninterpretedBytes class methodsFor:'instance creation'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
105 |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
106 |
from:aByteArray |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
107 |
"return new instance which is a copy of aByteArray" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
108 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
109 |
|len bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
110 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
111 |
len := aByteArray size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
112 |
bytes := self new:len. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
113 |
bytes replaceBytesFrom:1 to:len with:aByteArray startingAt:1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
114 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
115 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
116 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
117 |
String from:#[40 41 42] |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
118 |
String with:#[40 41 42 43 44 45 46 47 48 49 50] from:2 to:5 |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
119 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
120 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
121 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
122 |
fromHexString:aString |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
123 |
"Dolphin compatibility: |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
124 |
decode a byteArray from a hex string (as generated by hexPrintOn:)" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
125 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
126 |
|sz "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
127 |
chars s bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
128 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
129 |
sz := aString size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
130 |
sz == 0 ifTrue:[^ self new]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
131 |
sz odd ifTrue:[self error:'invalid hex string (odd size)'.]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
132 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
133 |
bytes := self new:(sz // 2). |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
134 |
s := aString readStream. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
135 |
1 to:sz // 2 do:[:idx | |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
136 |
chars := s next:2. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
137 |
bytes at:idx put:(Integer readFrom:chars radix:16). |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
138 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
139 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
140 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
141 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
142 |
ByteArray fromHexString:'1234FEFF' |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
143 |
ExternalBytes fromHexString:'1234FEFF' |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
144 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
145 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
146 |
|s| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
147 |
s := String streamContents:[:s | #[1 2 3] hexPrintOn:s]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
148 |
ByteArray fromHexString:s |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
149 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
150 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
151 |
"Modified: / 6.3.1997 / 15:28:52 / cg" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
152 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
153 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
154 |
fromPackedString:aString |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
155 |
"ST-80 compatibility: decode a byteArray from a packed string in which |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
156 |
6bits are encoded per character. The argument, aString must be a multiple |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
157 |
of 4 in size (since 24 is the lcm of 6 and 8). This is somewhat like |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
158 |
the radix-encoding used in good old PDP11 times ;-) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
159 |
ST-80 uses this encoding for Images ... |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
160 |
This is very similar (but not equal) to the algorithm used in RFC1421. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
161 |
PS: It took a while to figure that one out ... I dont like it ;-)" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
162 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
163 |
|index "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
164 |
dstIndex "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
165 |
stop "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
166 |
sixBits "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
167 |
n "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
168 |
sz "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
169 |
lastCharacter bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
170 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
171 |
sz := aString size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
172 |
sz == 0 ifTrue:[^ self new]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
173 |
sz := sz - (aString occurrencesOf:Character linefeed). |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
174 |
sz := sz - (aString occurrencesOf:Character return). |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
175 |
sz := sz - (aString occurrencesOf:Character tab). |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
176 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
177 |
stop := sz // 4 * 3. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
178 |
"the size modulo 3 is encoded in the last character, if its in the |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
179 |
range 97 .. otherwise, its exact." |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
180 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
181 |
lastCharacter := aString last. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
182 |
lastCharacter codePoint > 96 ifTrue:[ |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
183 |
stop := stop - 3 + lastCharacter codePoint - 96 |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
184 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
185 |
bytes := self new:stop. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
186 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
187 |
index := 1. dstIndex := 1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
188 |
[dstIndex <= stop] whileTrue:[ |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
189 |
"/ take 4 characters ... |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
190 |
"/ allow a line break before each group of 4 |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
191 |
sixBits := (aString at:index) codePoint. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
192 |
[sixBits < 32] whileTrue:[ |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
193 |
index := index + 1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
194 |
sixBits := (aString at:index) codePoint. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
195 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
196 |
sixBits := sixBits bitAnd:16r3F. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
197 |
n := sixBits. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
198 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
199 |
sixBits := (aString at:index+1) codePoint. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
200 |
sixBits := sixBits bitAnd:16r3F. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
201 |
n := (n bitShift:6) + sixBits. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
202 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
203 |
sixBits := (aString at:index+2) codePoint. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
204 |
sixBits := sixBits bitAnd:16r3F. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
205 |
n := (n bitShift:6) + sixBits. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
206 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
207 |
sixBits := (aString at:index+3) codePoint. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
208 |
sixBits := sixBits bitAnd:16r3F. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
209 |
n := (n bitShift:6) + sixBits. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
210 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
211 |
index := index + 4. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
212 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
213 |
"/ now have 24 bits in n |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
214 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
215 |
bytes at:dstIndex put:(n bitShift:-16). |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
216 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
217 |
dstIndex < stop ifTrue:[ |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
218 |
bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF). |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
219 |
dstIndex+2 <= stop ifTrue:[ |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
220 |
bytes at:dstIndex+2 put:(n bitAnd:16rFF). |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
221 |
] |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
222 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
223 |
dstIndex := dstIndex + 3. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
224 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
225 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
226 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
227 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
228 |
ByteArray fromPackedString:(#[1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
229 |
ByteArray fromPackedString:(#[1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
230 |
ByteArray fromPackedString:(#[1 1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
231 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
232 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
233 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
234 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
235 |
"Modified: / 6.3.1997 / 15:28:52 / cg" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
236 |
"Modified: / 18.12.1997 / 17:17:11 / stefan" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
237 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
238 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
239 |
with:aByteArray from:start to:stop |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
240 |
"return new instance with a copy of aByteArray |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
241 |
beginning at index start up to and including index stop" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
242 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
243 |
|len bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
244 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
245 |
len := stop-start+1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
246 |
bytes := self new:len. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
247 |
bytes replaceBytesFrom:1 to:len with:aByteArray startingAt:start. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
248 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
249 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
250 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
251 |
String with:#[40 41 42 43 44 45 46 47 48 49 50] from:2 to:5 |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
252 |
" |
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
253 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
254 |
|
1 | 255 |
!UninterpretedBytes class methodsFor:'queries'! |
256 |
||
8893 | 257 |
isAbstract |
258 |
^ self == UninterpretedBytes |
|
259 |
! |
|
260 |
||
1 | 261 |
isBigEndian |
77 | 262 |
"return true, if words/shorts store the most-significant |
263 |
byte first (MSB), false if least-sign.-first (LSB). |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
264 |
I.e. false for vax, intel; true for m68k, sun. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
265 |
|
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
266 |
Notice: UninterpretedBytes isBigEndian |
4308 | 267 |
this is inlined both by stc and the jit compiler" |
1 | 268 |
|
269 |
%{ /* NOCONTEXT */ |
|
270 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
271 |
#if defined(__MSBFIRST__) |
3936 | 272 |
RETURN (true); |
273 |
#else |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
274 |
# if defined(__LSBFIRST__) |
4275 | 275 |
RETURN (false); |
276 |
# else |
|
1 | 277 |
/* |
278 |
* I dont like ifdefs - you always forget some ... |
|
3433 | 279 |
* therefore we look into a structure at run-time. |
280 |
* (also, there are CPUs around [mips], where the byteorder |
|
281 |
* is programmable, and which come in different flavours) |
|
282 |
* |
|
283 |
* NOTICE: |
|
284 |
* both the JIT and stc may inline this to a |
|
285 |
* constant for systems where this is known. |
|
1 | 286 |
*/ |
287 |
union { |
|
4308 | 288 |
unsigned int u_l; |
289 |
char u_c[sizeof(int)]; |
|
1 | 290 |
} u; |
291 |
||
292 |
u.u_l = 0x87654321; |
|
77 | 293 |
if (u.u_c[0] == 0x21) RETURN (false); |
294 |
RETURN (true); |
|
4275 | 295 |
# endif |
3936 | 296 |
#endif |
1 | 297 |
%} |
3433 | 298 |
" |
299 |
UninterpretedBytes isBigEndian |
|
300 |
" |
|
3209 | 301 |
! |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
302 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
303 |
isBuiltInClass |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
304 |
"return true if this class is known by the run-time-system. |
3323 | 305 |
Here, true is returned, since UninterpretedBytes is the superclass of |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
306 |
some builtIn classes (ByteArray & ExternalBytes)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
307 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
308 |
^ self == UninterpretedBytes |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
309 |
|
3323 | 310 |
"Modified: / 23.4.1996 / 15:56:25 / cg" |
311 |
"Modified: / 5.3.1998 / 14:56:22 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
312 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
313 |
|
3459 | 314 |
!UninterpretedBytes methodsFor:'accessing-bytes'! |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
315 |
|
4422 | 316 |
bcdByteAt:index |
317 |
"return the bcd-value for a byte at index." |
|
318 |
||
4425 | 319 |
^ (self byteAt:index) decodeFromBCD |
4422 | 320 |
|
321 |
" |
|
322 |
#[ 16r55 ] bcdByteAt:1 |
|
323 |
#[ 16r99] bcdByteAt:1 |
|
324 |
#[ 16rAA] bcdByteAt:1 |
|
325 |
" |
|
326 |
! |
|
327 |
||
328 |
bcdByteAt:index put:aNumber |
|
329 |
"set the byte at index as bcd-value." |
|
330 |
||
331 |
(aNumber between:0 and:99) ifFalse:[ |
|
4530
793b116fef3e
error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents:
4515
diff
changeset
|
332 |
self error:'invalid value for BCD encoding' |
4422 | 333 |
]. |
4425 | 334 |
^ self byteAt:index put:aNumber encodeAsBCD |
4422 | 335 |
|
336 |
" |
|
4425 | 337 |
(((ByteArray new:1) bcdByteAt:1 put:55; yourself) at:1) hexPrintString |
338 |
(((ByteArray new:1) bcdByteAt:1 put:99; yourself) at:1) hexPrintString |
|
339 |
(((ByteArray new:1) bcdByteAt:1 put:100; yourself) at:1) hexPrintString |
|
340 |
(((ByteArray new:1) bcdByteAt:1 put:-1; yourself) at:1) hexPrintString |
|
4422 | 341 |
" |
342 |
! |
|
343 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
344 |
byteAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
345 |
"return the byte at index. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
346 |
For ByteArray, this is the same as basicAt:; |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
347 |
however, for strings or symbols, this returns a numeric byteValue |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
348 |
instead of a character." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
349 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
350 |
^ self subclassResponsibility |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
351 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
352 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
353 |
byteAt:index put:value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
354 |
"set the byte at index. For ByteArray, this is the same as basicAt:put:. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
355 |
However, for Strings, this expects a byteValue to be stored." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
356 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
357 |
^ self subclassResponsibility |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
358 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
359 |
|
3459 | 360 |
signedByteAt:index |
361 |
"return the byte at index as a signed 8 bit value. |
|
362 |
The index is a smalltalk index (i.e. 1-based). |
|
363 |
This may be worth a primitive." |
|
364 |
||
365 |
^ (self at:index) signExtendedByteValue |
|
366 |
||
367 |
" |
|
368 |
|b| |
|
369 |
b := ByteArray new:2. |
|
370 |
b at:1 put:16rFF. |
|
371 |
b at:2 put:16r7F. |
|
372 |
b signedByteAt:1 |
|
373 |
" |
|
374 |
||
375 |
"Modified: 1.7.1996 / 21:13:53 / cg" |
|
376 |
! |
|
377 |
||
378 |
signedByteAt:index put:aSignedByteValue |
|
379 |
"return the byte at index as a signed 8 bit value. |
|
380 |
The index is a smalltalk index (i.e. 1-based). |
|
381 |
Return the signedByteValue argument. |
|
382 |
This may be worth a primitive." |
|
383 |
||
384 |
|b "{ Class: SmallInteger }"| |
|
385 |
||
386 |
aSignedByteValue >= 0 ifTrue:[ |
|
387 |
b := aSignedByteValue |
|
388 |
] ifFalse:[ |
|
389 |
b := 16r100 + aSignedByteValue |
|
390 |
]. |
|
391 |
self at:index put:b. |
|
392 |
^ aSignedByteValue |
|
393 |
||
394 |
" |
|
395 |
|b| |
|
396 |
b := ByteArray new:2. |
|
397 |
b signedByteAt:1 put:-1. |
|
398 |
b at:1 |
|
399 |
" |
|
400 |
||
401 |
"Modified: 1.7.1996 / 21:12:37 / cg" |
|
402 |
! ! |
|
403 |
||
404 |
!UninterpretedBytes methodsFor:'accessing-floats & doubles'! |
|
405 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
406 |
doubleAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
407 |
"return the 8-bytes starting at index as a Float. |
3433 | 408 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
409 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
410 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
411 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
412 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
413 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
414 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
415 |
|
3433 | 416 |
%{ |
417 |
/* |
|
418 |
* handle the most common cases fast ... |
|
419 |
*/ |
|
420 |
if (__isSmallInteger(index)) { |
|
4308 | 421 |
unsigned char *cp; |
3433 | 422 |
int sz; |
4308 | 423 |
|
3433 | 424 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
4308 | 425 |
if (cp) { |
3433 | 426 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
427 |
||
3434 | 428 |
if ((idx+(sizeof(double)-1)) < sz) { |
3433 | 429 |
cp += idx; |
430 |
/* |
|
431 |
* aligned |
|
432 |
*/ |
|
3434 | 433 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
3433 | 434 |
double dVal = ((double *)cp)[0]; |
3434 | 435 |
OBJ f; |
436 |
||
437 |
__qMKFLOAT(f, dVal); |
|
4308 | 438 |
RETURN (f); |
3433 | 439 |
} |
440 |
} |
|
441 |
} |
|
442 |
} |
|
443 |
%}. |
|
444 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
445 |
newFloat := Float basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
446 |
1 to:8 do:[:destIndex| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
447 |
newFloat basicAt:destIndex put:(self at:index - 1 + destIndex) |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
448 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
449 |
^ newFloat. |
3433 | 450 |
|
451 |
" |
|
452 |
|b| |
|
453 |
||
454 |
b := ByteArray new:20. |
|
455 |
b doubleAt:1 put:(Float pi). |
|
456 |
Transcript showCR:b. |
|
457 |
Transcript showCR:(b doubleAt:1) |
|
458 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
459 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
460 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
461 |
doubleAt:index MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
462 |
"return the 8-bytes starting at index as a Float. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
463 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
464 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
465 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
466 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
467 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
468 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
469 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
470 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
471 |
msb == UninterpretedBytes isBigEndian ifTrue:[ |
4308 | 472 |
^ self doubleAt:index. |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
473 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
474 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
475 |
newFloat := Float basicNew. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
476 |
1 to:8 do:[:destIndex| |
4308 | 477 |
newFloat basicAt:(9-destIndex) put:(self at:index - 1 + destIndex) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
478 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
479 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
480 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
481 |
"Created: / 15.5.1998 / 17:21:45 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
482 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
483 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
484 |
doubleAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
485 |
"store the value of the argument, aFloat into the receiver |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
486 |
starting at index. |
3433 | 487 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
488 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
489 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
490 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
491 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
492 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
493 |
|flt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
494 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
495 |
flt := aFloat asFloat. |
3433 | 496 |
%{ |
497 |
/* |
|
498 |
* handle the most common cases fast ... |
|
499 |
*/ |
|
500 |
if (__isSmallInteger(index) && __isFloat(flt)) { |
|
4308 | 501 |
unsigned char *cp; |
502 |
int sz; |
|
3433 | 503 |
|
4308 | 504 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
505 |
if (cp) { |
|
506 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3433 | 507 |
|
4308 | 508 |
if ((idx+(sizeof(double)-1)) < sz) { |
509 |
cp += idx; |
|
510 |
/* |
|
511 |
* aligned |
|
512 |
*/ |
|
513 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
514 |
((double *)cp)[0] = __floatVal(flt); |
|
515 |
RETURN (aFloat); |
|
516 |
} |
|
517 |
} |
|
518 |
} |
|
3433 | 519 |
} |
520 |
%}. |
|
521 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
522 |
1 to:8 do:[:srcIndex| |
4308 | 523 |
self at:index - 1 + srcIndex put:(flt basicAt:srcIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
524 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
525 |
^ aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
526 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
527 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
528 |
doubleAt:index put:aFloat MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
529 |
"store the value of the argument, aFloat into the receiver |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
530 |
starting at index. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
531 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
532 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
533 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
534 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
535 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
536 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
537 |
|flt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
538 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
539 |
msb == UninterpretedBytes isBigEndian ifTrue:[ |
4308 | 540 |
^ self doubleAt:index put:aFloat. |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
541 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
542 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
543 |
flt := aFloat asFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
544 |
1 to:8 do:[:srcIndex| |
4308 | 545 |
self at:index - 1 + srcIndex put:(flt basicAt:(9-srcIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
546 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
547 |
^ aFloat |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
548 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
549 |
"Created: / 15.5.1998 / 17:22:27 / cg" |
3447 | 550 |
"Modified: / 15.5.1998 / 17:26:29 / cg" |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
551 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
552 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
553 |
floatAt:index |
3434 | 554 |
"return the 4-bytes starting at index as a ShortFloat. |
3433 | 555 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
556 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80; |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
557 |
therefore this method reads a 4-byte float from the byteArray and returns |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
558 |
a float object which keeps an 8-byte double internally. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
559 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
560 |
float representation and order - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
561 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
562 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
563 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
564 |
|
3434 | 565 |
%{ |
566 |
/* |
|
567 |
* handle the most common cases fast ... |
|
568 |
*/ |
|
569 |
if (__isSmallInteger(index)) { |
|
4308 | 570 |
unsigned char *cp; |
571 |
int sz; |
|
3434 | 572 |
|
4308 | 573 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
574 |
if (cp) { |
|
575 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 576 |
|
4308 | 577 |
if ((idx+(sizeof(float)-1)) < sz) { |
578 |
cp += idx; |
|
579 |
/* |
|
580 |
* aligned |
|
581 |
*/ |
|
582 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
583 |
float fVal = ((float *)cp)[0]; |
|
3434 | 584 |
OBJ f; |
585 |
||
586 |
__qMKSFLOAT(f, fVal); |
|
4308 | 587 |
RETURN (f); |
588 |
} |
|
589 |
} |
|
590 |
} |
|
3434 | 591 |
} |
592 |
%}. |
|
593 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
594 |
newFloat := ShortFloat basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
595 |
1 to:4 do:[:destIndex| |
4308 | 596 |
newFloat basicAt:destIndex put:(self at:index - 1 + destIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
597 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
598 |
^ newFloat. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
599 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
600 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
601 |
floatAt:index MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
602 |
"return the 4-bytes starting at index as a ShortFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
603 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
604 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80; |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
605 |
therefore this method reads a 4-byte float from the byteArray and returns |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
606 |
a float object which keeps an 8-byte double internally. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
607 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
608 |
float representation and order - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
609 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
610 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
611 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
612 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
613 |
msb == UninterpretedBytes isBigEndian ifTrue:[ |
4308 | 614 |
^ self floatAt:index |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
615 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
616 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
617 |
newFloat := ShortFloat basicNew. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
618 |
1 to:4 do:[:destIndex| |
4308 | 619 |
newFloat basicAt:(5-destIndex) put:(self at:index - 1 + destIndex) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
620 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
621 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
622 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
623 |
"Modified: / 15.5.1998 / 17:20:19 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
624 |
"Created: / 15.5.1998 / 17:20:35 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
625 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
626 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
627 |
floatAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
628 |
"store the 4 bytes of value of the argument, aFloat into the receiver |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
629 |
starting at index. |
3433 | 630 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
631 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
632 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
633 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
634 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
635 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
636 |
|sflt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
637 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
638 |
sflt := aFloat asShortFloat. |
3434 | 639 |
%{ |
640 |
/* |
|
641 |
* handle the most common cases fast ... |
|
642 |
*/ |
|
643 |
if (__isSmallInteger(index) && __isShortFloat(sflt)) { |
|
4308 | 644 |
unsigned char *cp; |
645 |
int sz; |
|
3434 | 646 |
|
4308 | 647 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
648 |
if (cp) { |
|
649 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 650 |
|
4308 | 651 |
if ((idx+(sizeof(float)-1)) < sz) { |
652 |
cp += idx; |
|
653 |
/* |
|
654 |
* aligned |
|
655 |
*/ |
|
656 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
657 |
((float *)cp)[0] = __shortFloatVal(sflt); |
|
3434 | 658 |
|
4308 | 659 |
RETURN (aFloat); |
660 |
} |
|
661 |
} |
|
662 |
} |
|
3434 | 663 |
} |
664 |
%}. |
|
665 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
666 |
1 to:4 do:[:srcIndex| |
4308 | 667 |
self at:index - 1 + srcIndex put:(sflt basicAt:srcIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
668 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
669 |
^ aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
670 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
671 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
672 |
floatAt:index put:aFloat MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
673 |
"store the 4 bytes of value of the argument, aFloat into the receiver |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
674 |
starting at index. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
675 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
676 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
677 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
678 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
679 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
680 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
681 |
|sflt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
682 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
683 |
msb == UninterpretedBytes isBigEndian ifTrue:[ |
4308 | 684 |
^ self floatAt:index put:aFloat |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
685 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
686 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
687 |
sflt := aFloat asShortFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
688 |
1 to:4 do:[:srcIndex| |
4308 | 689 |
self at:index - 1 + srcIndex put:(sflt basicAt:(5-srcIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
690 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
691 |
^ aFloat |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
692 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
693 |
"Created: / 15.5.1998 / 17:20:41 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
694 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
695 |
|
3323 | 696 |
ieeeDoubleAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
697 |
"retrieve the 8 bytes starting at index as a float. |
3433 | 698 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 699 |
The 8 bytes are assumed to be in IEEE floating point single precision |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
700 |
number format." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
701 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
702 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
703 |
currently, we assume that the machines native number format is already |
3323 | 704 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
705 |
to an IBM 370 or old VAX etc. |
3323 | 706 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
707 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
708 |
" |
3433 | 709 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
710 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
711 |
^ self doubleAt:index |
3323 | 712 |
|
713 |
"Created: / 5.3.1998 / 10:50:03 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
714 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
715 |
|
3323 | 716 |
ieeeDoubleAt:index put:aFloat |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
717 |
"store the value of the argument, aFloat into the receiver |
3433 | 718 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 719 |
starting at index. Storage is in IEEE floating point double precision format. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
720 |
(i.e. 8 bytes are stored)." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
721 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
722 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
723 |
currently, we assume that the machines native number format is already |
3323 | 724 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
725 |
to an IBM 370 or old VAX etc. |
3323 | 726 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
727 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
728 |
" |
3433 | 729 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
730 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
731 |
^ self doubleAt:index put:aFloat |
3323 | 732 |
|
733 |
"Created: / 5.3.1998 / 10:50:26 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
734 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
735 |
|
3323 | 736 |
ieeeFloatAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
737 |
"retrieve the 4 bytes starting at index as a float. |
3433 | 738 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 739 |
The 4 bytes are assumed to be in IEEE floating point single precision |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
740 |
number format." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
741 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
742 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
743 |
currently, we assume that the machines native number format is already |
3323 | 744 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
745 |
to an IBM 370 or old VAX etc. |
3323 | 746 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
747 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
748 |
" |
3433 | 749 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
750 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
751 |
^ self floatAt:index |
3323 | 752 |
|
753 |
"Created: / 5.3.1998 / 10:50:45 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
754 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
755 |
|
3323 | 756 |
ieeeFloatAt:index put:aFloat |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
757 |
"store the value of the argument, aFloat into the receiver |
3433 | 758 |
starting at index, which is a smalltalk index (i.e. 1-based). |
759 |
Storage is in IEEE floating point single precision format. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
760 |
(i.e. 4 bytes are stored). Since ST/X floats are really doubles, the low- |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
761 |
order 4 bytes of the precision is lost." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
762 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
763 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
764 |
currently, we assume that the machines native number format is already |
3323 | 765 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
766 |
to an IBM 370 or old VAX etc. |
3323 | 767 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
768 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
769 |
" |
3433 | 770 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
771 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
772 |
^ self floatAt:index put:aFloat |
3323 | 773 |
|
774 |
"Created: / 5.3.1998 / 10:51:11 / stefan" |
|
3459 | 775 |
! ! |
776 |
||
777 |
!UninterpretedBytes methodsFor:'accessing-longlongs'! |
|
778 |
||
779 |
longLongAt:index |
|
780 |
"return the 8-bytes starting at index as a signed Integer. |
|
781 |
The index is a smalltalk index (i.e. 1-based). |
|
782 |
The value is retrieved in the machines natural byte order. |
|
783 |
This may be worth a primitive." |
|
784 |
||
785 |
|w| |
|
786 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
787 |
w := self unsignedLongLongAt:index bigEndian:(UninterpretedBytes isBigEndian). |
3459 | 788 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
4308 | 789 |
^ w - (16r10000000000000000) |
3459 | 790 |
]. |
791 |
^ w |
|
792 |
||
793 |
" |
|
794 |
|b| |
|
795 |
b := ByteArray new:4. |
|
796 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
797 |
(b longLongAt:1) |
|
798 |
" |
|
799 |
||
800 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
801 |
"Created: / 5.3.1998 / 14:40:05 / stefan" |
|
802 |
"Modified: / 5.3.1998 / 14:58:32 / stefan" |
|
803 |
! |
|
804 |
||
805 |
longLongAt:index bigEndian:msb |
|
806 |
"return the 8-bytes starting at index as a signed Integer. |
|
807 |
The index is a smalltalk index (i.e. 1-based). |
|
808 |
The value is retrieved in the given byte order. |
|
809 |
This may be worth a primitive." |
|
810 |
||
811 |
|w| |
|
812 |
||
813 |
w := self unsignedLongLongAt:index bigEndian:msb. |
|
814 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
|
4308 | 815 |
^ w - (16r10000000000000000) |
3459 | 816 |
]. |
817 |
^ w |
|
818 |
||
819 |
" |
|
820 |
|b| |
|
821 |
b := ByteArray new:4. |
|
822 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
823 |
(b longLongAt:1 msb:true) |
|
824 |
" |
|
825 |
||
826 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
827 |
"Created: / 5.3.1998 / 14:40:54 / stefan" |
|
828 |
"Modified: / 9.5.1998 / 01:10:59 / cg" |
|
829 |
! |
|
830 |
||
831 |
longLongAt:byteIndex put:anInteger |
|
832 |
"store a signed longLong (64bit) integer. |
|
833 |
The index is a smalltalk index (i.e. 1-based). |
|
834 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
835 |
||
7813 | 836 |
|v| |
3459 | 837 |
|
7813 | 838 |
v := anInteger. |
839 |
anInteger < 0 ifTrue:[ |
|
840 |
v := v + 16r10000000000000000 |
|
841 |
]. |
|
842 |
^ self unsignedLongLongAt:byteIndex put:v |
|
3459 | 843 |
! |
844 |
||
845 |
longLongAt:byteIndex put:anInteger bigEndian:msb |
|
846 |
"store a signed longLong (64bit) integer. |
|
847 |
The index is a smalltalk index (i.e. 1-based). |
|
848 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
849 |
||
850 |
|v| |
|
851 |
||
852 |
v := anInteger. |
|
853 |
anInteger < 0 ifTrue:[ |
|
4308 | 854 |
v := v + 16r10000000000000000 |
3459 | 855 |
]. |
856 |
^ self unsignedLongLongAt:byteIndex put:v bigEndian:msb |
|
857 |
||
858 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
859 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
860 |
! |
|
861 |
||
862 |
quadWordAt:index MSB:msb |
|
863 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
864 |
The index is a smalltalk index (i.e. 1-based). |
|
865 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
866 |
||
867 |
|l |
|
868 |
bIdx "{ Class: SmallInteger }" |
|
869 |
delta "{ Class: SmallInteger }"| |
|
870 |
||
871 |
l := LargeInteger basicNew numberOfDigits:8. |
|
872 |
msb ifTrue:[ |
|
4308 | 873 |
bIdx := index + 7. |
874 |
delta := -1 |
|
3459 | 875 |
] ifFalse:[ |
4308 | 876 |
bIdx := index. |
877 |
delta := 1 |
|
3459 | 878 |
]. |
879 |
1 to:8 do:[:i | |
|
4308 | 880 |
l digitAt:i put:(self basicAt:bIdx). |
881 |
bIdx := bIdx + delta |
|
3459 | 882 |
]. |
883 |
^ l compressed |
|
884 |
||
885 |
" |
|
886 |
|b| |
|
887 |
||
888 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
889 |
(b quadWordAt:1 MSB:false) printStringRadix:16 |
|
890 |
" |
|
891 |
||
892 |
"Modified: 5.11.1996 / 14:06:21 / cg" |
|
893 |
! |
|
894 |
||
895 |
quadWordAt:index put:anInteger MSB:msb |
|
896 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
897 |
The index is a smalltalk index (i.e. 1-based). |
|
898 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
899 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
900 |
||
901 |
|bIdx "{ Class: SmallInteger }" |
|
902 |
delta "{ Class: SmallInteger }"| |
|
903 |
||
904 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[ |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
905 |
^ self elementBoundsError:anInteger |
3459 | 906 |
]. |
907 |
||
908 |
msb ifTrue:[ |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
909 |
bIdx := index + 7. |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
910 |
delta := -1 |
3459 | 911 |
] ifFalse:[ |
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
912 |
bIdx := index. |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
913 |
delta := 1 |
3459 | 914 |
]. |
915 |
1 to:8 do:[:i | |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
916 |
self basicAt:bIdx put:(anInteger digitAt:i). |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
917 |
bIdx := bIdx + delta. |
3459 | 918 |
]. |
919 |
^ anInteger |
|
920 |
||
921 |
" |
|
922 |
|b| |
|
923 |
b := ByteArray new:8. |
|
924 |
b quadWordAtIndex:1 put:16r0807060504030201 MSB:false. |
|
925 |
b inspect |
|
926 |
" |
|
927 |
! |
|
928 |
||
929 |
unsignedLongLongAt:index bigEndian:msb |
|
930 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
931 |
The index is a smalltalk index (i.e. 1-based). |
|
932 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
933 |
||
934 |
|l |
|
935 |
bIdx "{ Class: SmallInteger }" |
|
936 |
delta "{ Class: SmallInteger }"| |
|
937 |
||
938 |
l := LargeInteger basicNew numberOfDigits:8. |
|
939 |
msb ifTrue:[ |
|
4308 | 940 |
bIdx := index + 7. |
941 |
delta := -1 |
|
3459 | 942 |
] ifFalse:[ |
4308 | 943 |
bIdx := index. |
944 |
delta := 1 |
|
3459 | 945 |
]. |
946 |
1 to:8 do:[:i | |
|
4308 | 947 |
l digitAt:i put:(self basicAt:bIdx). |
948 |
bIdx := bIdx + delta |
|
3459 | 949 |
]. |
950 |
^ l compressed |
|
951 |
||
952 |
" |
|
953 |
|b| |
|
954 |
||
955 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
956 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
|
957 |
" |
|
958 |
||
959 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
960 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
961 |
! |
|
962 |
||
963 |
unsignedLongLongAt:index put:anInteger |
|
964 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
965 |
The index is a smalltalk index (i.e. 1-based). |
|
966 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
967 |
The value is stored in natural byte order." |
|
968 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
969 |
^ self unsignedLongLongAt:index put:anInteger bigEndian:(UninterpretedBytes isBigEndian) |
3459 | 970 |
|
971 |
"Created: / 5.3.1998 / 14:44:00 / stefan" |
|
972 |
"Modified: / 5.3.1998 / 15:02:32 / stefan" |
|
973 |
! |
|
974 |
||
975 |
unsignedLongLongAt:index put:anInteger bigEndian:msb |
|
976 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
977 |
The index is a smalltalk index (i.e. 1-based). |
|
978 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
979 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
980 |
||
981 |
|bIdx "{ Class: SmallInteger }" |
|
982 |
delta "{ Class: SmallInteger }"| |
|
983 |
||
984 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[ |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
985 |
^ self elementBoundsError:anInteger |
3459 | 986 |
]. |
987 |
||
988 |
msb ifTrue:[ |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
989 |
bIdx := index + 7. |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
990 |
delta := -1 |
3459 | 991 |
] ifFalse:[ |
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
992 |
bIdx := index. |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
993 |
delta := 1 |
3459 | 994 |
]. |
995 |
1 to:8 do:[:i | |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
996 |
self basicAt:bIdx put:(anInteger digitAt:i). |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
997 |
bIdx := bIdx + delta. |
3459 | 998 |
]. |
999 |
^ anInteger |
|
1000 |
||
1001 |
" |
|
1002 |
|b| |
|
1003 |
b := ByteArray new:8. |
|
1004 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
1005 |
b inspect |
|
1006 |
" |
|
1007 |
||
1008 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
1009 |
! ! |
|
1010 |
||
1011 |
!UninterpretedBytes methodsFor:'accessing-longs'! |
|
1012 |
||
1013 |
doubleWordAt:index |
|
1014 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1015 |
The index is a smalltalk index (i.e. 1-based). |
|
4515 | 1016 |
The value is retrieved in the machines natural byte order." |
3459 | 1017 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1018 |
^ self doubleWordAt:index MSB:(UninterpretedBytes isBigEndian) |
3459 | 1019 |
|
1020 |
" |
|
1021 |
|b| |
|
1022 |
||
1023 |
b := ByteArray withAll:#(1 2 3 4). |
|
1024 |
(b doubleWordAt:1) printStringRadix:16 |
|
1025 |
" |
|
1026 |
||
1027 |
"Modified: / 5.3.1998 / 14:57:35 / stefan" |
|
1028 |
! |
|
1029 |
||
1030 |
doubleWordAt:index MSB:msb |
|
1031 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1032 |
The index is a smalltalk index (i.e. 1-based). |
|
1033 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
4515 | 1034 |
LSB-first otherwise." |
3459 | 1035 |
|
1036 |
|val |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1037 |
ival "{ Class: SmallInteger }" |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1038 |
t "{ Class: SmallInteger }" |
3459 | 1039 |
i "{ Class: SmallInteger }" |
1040 |
b1 "{ Class: SmallInteger }" |
|
1041 |
b2 "{ Class: SmallInteger }" |
|
1042 |
b3 "{ Class: SmallInteger }" |
|
1043 |
b4 "{ Class: SmallInteger }"| |
|
1044 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1045 |
%{ |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1046 |
/* |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1047 |
* handle the most common cases fast ... |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1048 |
*/ |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1049 |
if (__isSmallInteger(index)) { |
4515 | 1050 |
unsigned char *cp; |
1051 |
int sz; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1052 |
|
4515 | 1053 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
1054 |
if (cp) { |
|
1055 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1056 |
unsigned int iVal; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1057 |
|
4515 | 1058 |
if ((idx+(sizeof(int)-1)) < sz) { |
1059 |
cp += idx; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1060 |
|
4515 | 1061 |
if (msb == true) { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1062 |
#if defined(__MSBFIRST__) |
4515 | 1063 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
1064 |
/* |
|
1065 |
* aligned |
|
1066 |
*/ |
|
1067 |
iVal = ((unsigned int *)cp)[0]; |
|
1068 |
} else |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1069 |
#endif |
4515 | 1070 |
{ |
1071 |
iVal = cp[0]; |
|
1072 |
iVal = (iVal << 8) | cp[1]; |
|
1073 |
iVal = (iVal << 8) | cp[2]; |
|
1074 |
iVal = (iVal << 8) | cp[3]; |
|
1075 |
} |
|
1076 |
} else { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1077 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
4515 | 1078 |
/* |
1079 |
* aligned or not - we dont care |
|
1080 |
* (i386 can fetch unaligned) |
|
1081 |
*/ |
|
1082 |
iVal = ((unsigned int *)cp)[0]; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1083 |
#else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1084 |
# if defined(__LSBFIRST__) |
4515 | 1085 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
1086 |
/* |
|
1087 |
* aligned |
|
1088 |
*/ |
|
1089 |
iVal = ((unsigned int *)cp)[0]; |
|
1090 |
} else |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1091 |
# endif |
4515 | 1092 |
{ |
1093 |
iVal = cp[3]; |
|
1094 |
iVal = (iVal << 8) | cp[2]; |
|
1095 |
iVal = (iVal << 8) | cp[1]; |
|
1096 |
iVal = (iVal << 8) | cp[0]; |
|
1097 |
} |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1098 |
#endif |
4515 | 1099 |
} |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1100 |
#if __POINTER_SIZE__ == 8 |
8913 | 1101 |
RETURN (__mkSmallInteger(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1102 |
#else |
4515 | 1103 |
RETURN (__MKUINT(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1104 |
#endif |
4515 | 1105 |
} |
1106 |
} |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1107 |
} |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1108 |
%}. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1109 |
|
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1110 |
"/ fallBack code - non ByteArray-like receiver |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1111 |
"/ or funny index |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1112 |
|
3459 | 1113 |
i := index. |
1114 |
b1 := self at:i. |
|
1115 |
b2 := self at:(i+1). |
|
1116 |
b3 := self at:(i+2). |
|
1117 |
b4 := self at:(i+3). |
|
1118 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1119 |
msb ifFalse:[ |
4515 | 1120 |
t := b4. b4 := b1. b1 := t. |
1121 |
t := b3. b3 := b2. b2 := t. |
|
3459 | 1122 |
]. |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1123 |
ival := b1. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1124 |
ival := (ival bitShift:8) + b2. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1125 |
ival := (ival bitShift:8) + b3. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1126 |
val := (ival bitShift:8) + b4. |
3459 | 1127 |
^ val |
1128 |
||
1129 |
" |
|
1130 |
|b| |
|
1131 |
||
1132 |
b := ByteArray withAll:#(1 2 3 4). |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1133 |
(b doubleWordAt:1 MSB:true) printStringRadix:16. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1134 |
(b doubleWordAt:1 MSB:false) printStringRadix:16 |
3459 | 1135 |
" |
1136 |
||
1137 |
! |
|
1138 |
||
1139 |
doubleWordAt:index put:value |
|
1140 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1141 |
The index is a smalltalk index (i.e. 1-based). |
|
1142 |
The value should be in the range 0 to 16rFFFFFFFF |
|
1143 |
(for negative values, the stored value is not defined). |
|
4515 | 1144 |
The value is stored in the machines natural byte order." |
3459 | 1145 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1146 |
^ self doubleWordAt:index put:value MSB:(UninterpretedBytes isBigEndian) |
3459 | 1147 |
|
1148 |
" |
|
1149 |
|b| |
|
1150 |
b := ByteArray new:4. |
|
1151 |
b doubleWordAt:1 put:16r04030201. |
|
1152 |
b inspect |
|
1153 |
" |
|
1154 |
||
1155 |
"Modified: / 5.3.1998 / 14:57:48 / stefan" |
|
1156 |
! |
|
1157 |
||
1158 |
doubleWordAt:index put:aNumber MSB:msb |
|
1159 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1160 |
The index is a smalltalk index (i.e. 1-based). |
|
1161 |
The value must be in the range 0 to 16rFFFFFFFF. |
|
4515 | 1162 |
The value is stored MSB-first if msb is true; LSB-first otherwise." |
3459 | 1163 |
|
1164 |
|i "{ Class: SmallInteger }" | |
|
1165 |
||
1166 |
((aNumber < 0) or:[aNumber > 16rFFFFFFFF]) ifTrue:[ |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
1167 |
^ self elementBoundsError:aNumber |
3459 | 1168 |
]. |
1169 |
||
1170 |
i := index. |
|
1171 |
msb ifTrue:[ |
|
4515 | 1172 |
self at:i put:(aNumber digitAt:4). |
1173 |
self at:(i+1) put:(aNumber digitAt:3). |
|
1174 |
self at:(i+2) put:(aNumber digitAt:2). |
|
1175 |
self at:(i+3) put:(aNumber digitAt:1). |
|
3459 | 1176 |
] ifFalse:[ |
4515 | 1177 |
self at:i put:(aNumber digitAt:1). |
1178 |
self at:(i+1) put:(aNumber digitAt:2). |
|
1179 |
self at:(i+2) put:(aNumber digitAt:3). |
|
1180 |
self at:(i+3) put:(aNumber digitAt:4). |
|
3459 | 1181 |
]. |
1182 |
^ aNumber |
|
1183 |
||
1184 |
" |
|
1185 |
|b| |
|
1186 |
b := ByteArray new:8. |
|
1187 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
|
1188 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
1189 |
b inspect |
|
1190 |
" |
|
1191 |
||
1192 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
1193 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
|
1194 |
! |
|
1195 |
||
1196 |
doubleWordAtDoubleWordIndex:index |
|
1197 |
"return the unsigned long at index, anInteger. |
|
1198 |
Fetching in the machines natural byte order. |
|
1199 |
Indices are 1-based and scaled as appropriate to allow |
|
1200 |
accessing the memory as an array of doubleWord entries. |
|
1201 |
(i.e. indices are 1, 2, ...)" |
|
1202 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1203 |
^ self doubleWordAtDoubleWordIndex:index MSB:(UninterpretedBytes isBigEndian) |
3459 | 1204 |
|
1205 |
"Created: / 21.1.1998 / 17:43:53 / cg" |
|
1206 |
"Modified: / 5.3.1998 / 14:58:06 / stefan" |
|
1207 |
! |
|
1208 |
||
1209 |
doubleWordAtDoubleWordIndex:index MSB:msb |
|
1210 |
"return the unsigned long at index, anInteger. |
|
1211 |
Fetching is MSB if msb is true, LSB otherwise. |
|
1212 |
Indices are 1-based and scaled as appropriate to allow |
|
1213 |
accessing the memory as an array of doubleWord entries. |
|
1214 |
(i.e. indices are 1, 2, ...)" |
|
1215 |
||
1216 |
^ self doubleWordAt:(index - 1 * 4 + 1) MSB:msb |
|
1217 |
||
1218 |
"Created: / 21.1.1998 / 17:44:07 / cg" |
|
1219 |
! |
|
1220 |
||
1221 |
doubleWordAtDoubleWordIndex:index put:value |
|
1222 |
"set the long at index, anInteger. |
|
1223 |
Storing in the machines natural byte order. |
|
1224 |
Indices are 1-based and scaled as appropriate to allow |
|
1225 |
accessing the memory as an array of doubleWord entries. |
|
1226 |
(i.e. indices are 1, 2, ...)" |
|
1227 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1228 |
^ self doubleWordAtDoubleWordIndex:index put:value MSB:(UninterpretedBytes isBigEndian) |
3459 | 1229 |
|
1230 |
"Created: / 21.1.1998 / 17:44:13 / cg" |
|
1231 |
"Modified: / 5.3.1998 / 14:58:19 / stefan" |
|
1232 |
! |
|
1233 |
||
1234 |
doubleWordAtDoubleWordIndex:index put:value MSB:msb |
|
1235 |
"set the long at index, anInteger. |
|
1236 |
Storing is MSB if msb is true, LSB otherwise. |
|
1237 |
Indices are 1-based and scaled as appropriate to allow |
|
1238 |
accessing the memory as an array of doubleWord entries. |
|
1239 |
(i.e. indices are 1, 2, ...)" |
|
1240 |
||
1241 |
^ self doubleWordAt:(index - 1 * 4 + 1) put:value MSB:msb |
|
1242 |
||
1243 |
"Created: / 21.1.1998 / 17:44:19 / cg" |
|
3323 | 1244 |
! |
1245 |
||
1246 |
longAt:index |
|
1247 |
"return the 4-bytes starting at index as a signed Integer. |
|
3433 | 1248 |
The index is a smalltalk index (i.e. 1-based). |
4308 | 1249 |
The value is retrieved in the machines natural byte order, |
1250 |
therefore, this should only be used for byte-data which is |
|
1251 |
only used inside this machine. |
|
1252 |
To setup data packets which are to be sent to other machines, |
|
1253 |
or stored into a file, always use longAt:MSB: and specify |
|
1254 |
a definite byteOrder." |
|
3323 | 1255 |
|
1256 |
|w| |
|
1257 |
||
3434 | 1258 |
%{ |
1259 |
/* |
|
1260 |
* handle the most common cases fast ... |
|
1261 |
*/ |
|
1262 |
if (__isSmallInteger(index)) { |
|
4308 | 1263 |
unsigned char *cp; |
1264 |
int sz; |
|
3434 | 1265 |
|
4308 | 1266 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
1267 |
if (cp) { |
|
1268 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 1269 |
|
4308 | 1270 |
if ((idx+(sizeof(int)-1)) < sz) { |
1271 |
cp += idx; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1272 |
#if defined(__i386__) |
4308 | 1273 |
/* |
1274 |
* aligned or not, we dont care (i386 can do both) |
|
1275 |
*/ |
|
1276 |
{ |
|
1277 |
int iVal = ((int *)cp)[0]; |
|
3434 | 1278 |
|
4308 | 1279 |
RETURN (__MKINT(iVal)); |
1280 |
} |
|
1281 |
#else |
|
1282 |
/* |
|
1283 |
* aligned |
|
1284 |
*/ |
|
1285 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1286 |
int iVal = ((int *)cp)[0]; |
4308 | 1287 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1288 |
# if __POINTER_SIZE__ == 8 |
8913 | 1289 |
RETURN (__mkSmallInteger(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1290 |
# else |
4308 | 1291 |
RETURN (__MKINT(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1292 |
# endif |
4308 | 1293 |
} |
1294 |
#endif |
|
1295 |
} |
|
1296 |
} |
|
3434 | 1297 |
} |
1298 |
%}. |
|
1299 |
||
3323 | 1300 |
w := self unsignedLongAt:index. |
1301 |
(w > (16r7FFFFFFF)) ifTrue:[ |
|
4308 | 1302 |
^ w - (16r100000000) |
3323 | 1303 |
]. |
1304 |
^ w |
|
1305 |
||
1306 |
" |
|
1307 |
|b| |
|
1308 |
b := ByteArray new:4. |
|
1309 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
1310 |
(b longAt:1) |
|
1311 |
" |
|
1312 |
||
1313 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
1314 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
1315 |
! |
|
1316 |
||
1317 |
longAt:index bigEndian:msb |
|
1318 |
"return the 4-bytes starting at index as a signed Integer. |
|
3433 | 1319 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1320 |
Depending on msb, the value is retrieved MSB-first or LSB-first. |
1321 |
This may be worth a primitive." |
|
1322 |
||
1323 |
|w| |
|
1324 |
||
1325 |
w := self unsignedLongAt:index bigEndian:msb. |
|
1326 |
(w > (16r7FFFFFFF)) ifTrue:[ |
|
4308 | 1327 |
^ w - (16r100000000) |
3323 | 1328 |
]. |
1329 |
^ w |
|
1330 |
||
1331 |
" |
|
1332 |
|b| |
|
1333 |
b := ByteArray new:4. |
|
1334 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
1335 |
(b longAt:1) |
|
1336 |
" |
|
1337 |
||
1338 |
"Modified: / 1.7.1996 / 21:11:33 / cg" |
|
1339 |
"Created: / 5.3.1998 / 14:02:03 / stefan" |
|
1340 |
! |
|
1341 |
||
1342 |
longAt:index put:value |
|
1343 |
"set the 4-bytes starting at index from the signed Integer value. |
|
3433 | 1344 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1345 |
The value is stored in the machines natural byte order. |
1346 |
This may be worth a primitive. |
|
1347 |
||
1348 |
This is the ST80 version of #signedDoubleWordAt:put:" |
|
1349 |
||
1350 |
|v| |
|
1351 |
||
3434 | 1352 |
%{ |
1353 |
/* |
|
1354 |
* handle the most common cases fast ... |
|
1355 |
*/ |
|
1356 |
if (__isSmallInteger(index)) { |
|
4308 | 1357 |
unsigned char *cp; |
1358 |
int sz; |
|
3434 | 1359 |
|
4308 | 1360 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
1361 |
if (cp) { |
|
1362 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 1363 |
|
4308 | 1364 |
if ((idx+(sizeof(int)-1)) < sz) { |
1365 |
cp += idx; |
|
1366 |
/* |
|
1367 |
* aligned |
|
1368 |
*/ |
|
1369 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
3434 | 1370 |
int __v; |
1371 |
||
4308 | 1372 |
if (__isSmallInteger(value)) { |
1373 |
((int *)cp)[0] = __intVal(value); |
|
1374 |
RETURN (value); |
|
3434 | 1375 |
} |
1376 |
if (__v = __signedLongIntVal(value)) { |
|
1377 |
((int *)cp)[0] = __v; |
|
1378 |
RETURN (value); |
|
1379 |
} |
|
4308 | 1380 |
} |
1381 |
} |
|
1382 |
} |
|
3434 | 1383 |
} |
1384 |
%}. |
|
1385 |
||
3323 | 1386 |
value >= 0 ifTrue:[ |
4308 | 1387 |
v := value |
3323 | 1388 |
] ifFalse:[ |
4308 | 1389 |
v := value + 16r100000000 |
3323 | 1390 |
]. |
1391 |
self unsignedLongAt:index put:v. |
|
1392 |
^ value |
|
1393 |
||
1394 |
" |
|
1395 |
|b| |
|
1396 |
b := ByteArray new:4. |
|
1397 |
b longAt:1 put:-1. |
|
1398 |
(b unsignedLongAt:1) printStringRadix:16 |
|
1399 |
" |
|
1400 |
||
1401 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
|
1402 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
1403 |
! |
|
1404 |
||
3444 | 1405 |
longAt:byteIndex put:anInteger bigEndian:msb |
1406 |
"store a signed long (32bit) integer. |
|
1407 |
The index is a smalltalk index (i.e. 1-based). |
|
1408 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
1409 |
||
1410 |
|v| |
|
1411 |
||
1412 |
v := anInteger. |
|
1413 |
anInteger < 0 ifTrue:[ |
|
4308 | 1414 |
v := v + 16r100000000 |
3444 | 1415 |
]. |
1416 |
^ self unsignedLongAt:byteIndex put:v bigEndian:msb |
|
1417 |
||
1418 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
1419 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
1420 |
! |
|
1421 |
||
6492 | 1422 |
pointerAt:index put:value |
1423 |
"set the pointer starting at index from the signed Integer value. |
|
1424 |
The index is a smalltalk index (i.e. 1-based). |
|
1425 |
Only aligned accesses are allowed. |
|
1426 |
The value is either an ExternalAddress or ExternalBytes" |
|
1427 |
||
1428 |
%{ |
|
1429 |
OBJ *pointer; |
|
1430 |
||
7814
c649ba9fd538
#pointerAt:put: now works for ExternalAddressLike objects
Stefan Vogel <sv@exept.de>
parents:
7813
diff
changeset
|
1431 |
if (__isExternalAddressLike(value)) { |
6492 | 1432 |
pointer = __externalAddressVal(value); |
7197
a68adb223592
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7193
diff
changeset
|
1433 |
} else if (__isExternalBytesLike(value)) { |
6492 | 1434 |
pointer = __externalBytesVal(value); |
6885 | 1435 |
if (pointer == (OBJ *)0) |
6492 | 1436 |
pointer = 0; |
1437 |
} else goto bad; |
|
1438 |
||
1439 |
if (__isSmallInteger(index)) { |
|
1440 |
unsigned char *cp; |
|
1441 |
int sz; |
|
1442 |
||
1443 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1444 |
if (cp) { |
|
1445 |
unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1; |
|
1446 |
||
1447 |
if ((idx+(sizeof(pointer)-1)) < sz) { |
|
1448 |
cp += idx; |
|
1449 |
/* |
|
1450 |
* aligned |
|
1451 |
*/ |
|
1452 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
1453 |
((char **)cp)[0] = (char *) pointer; |
|
1454 |
RETURN (value); |
|
1455 |
} |
|
1456 |
} |
|
1457 |
} |
|
1458 |
} |
|
1459 |
bad:; |
|
1460 |
%}. |
|
1461 |
||
1462 |
self primitiveFailed. |
|
1463 |
||
1464 |
" |
|
1465 |
|b| |
|
1466 |
b := ByteArray new:ExternalAddress pointerSize. |
|
1467 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
1468 |
(b unsignedLongAt:1) printStringRadix:16 |
|
1469 |
" |
|
1470 |
||
1471 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
|
1472 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
1473 |
! |
|
1474 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1475 |
signedDoubleWordAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1476 |
"return the 4-bytes starting at index as a signed Integer. |
3433 | 1477 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1478 |
The value is retrieved in the machines natural byte order. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1479 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1480 |
|
4515 | 1481 |
^ self signedDoubleWordAt:index MSB:(UninterpretedBytes isBigEndian) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1482 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1483 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1484 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1485 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1486 |
b doubleWordAt:1 put:16rFFFFFFFF. |
4515 | 1487 |
(b signedDoubleWordAt:1) |
1488 |
" |
|
1489 |
" |
|
1490 |
|b| |
|
1491 |
b := ByteArray new:4. |
|
1492 |
b signedDoubleWordAt:1 put:-1. |
|
1493 |
(b doubleWordAt:1) |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1494 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1495 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1496 |
"Modified: 1.7.1996 / 21:11:28 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1497 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1498 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1499 |
signedDoubleWordAt:index MSB:msb |
4515 | 1500 |
"return the 4-bytes starting at index as a (signed) Integer. |
3433 | 1501 |
The index is a smalltalk index (i.e. 1-based). |
4515 | 1502 |
The value is retrieved MSB-first, if the msb-arg is true; |
1503 |
LSB-first otherwise." |
|
1504 |
||
1505 |
|val |
|
1506 |
ival "{ Class: SmallInteger }" |
|
1507 |
t "{ Class: SmallInteger }" |
|
1508 |
i "{ Class: SmallInteger }" |
|
1509 |
b1 "{ Class: SmallInteger }" |
|
1510 |
b2 "{ Class: SmallInteger }" |
|
1511 |
b3 "{ Class: SmallInteger }" |
|
1512 |
b4 "{ Class: SmallInteger }"| |
|
1513 |
||
1514 |
%{ |
|
1515 |
/* |
|
1516 |
* handle the most common cases fast ... |
|
1517 |
*/ |
|
1518 |
if (__isSmallInteger(index)) { |
|
1519 |
unsigned char *cp; |
|
1520 |
int sz; |
|
1521 |
||
1522 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1523 |
if (cp) { |
|
1524 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1525 |
int iVal; |
|
1526 |
||
1527 |
if ((idx+(sizeof(int)-1)) < sz) { |
|
1528 |
cp += idx; |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1529 |
|
4515 | 1530 |
if (msb == true) { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1531 |
#if defined(__MSBFIRST__) |
4515 | 1532 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
1533 |
/* |
|
1534 |
* aligned |
|
1535 |
*/ |
|
1536 |
iVal = ((int *)cp)[0]; |
|
1537 |
} else |
|
1538 |
#endif |
|
1539 |
{ |
|
1540 |
iVal = cp[0]; |
|
1541 |
iVal = (iVal << 8) | cp[1]; |
|
1542 |
iVal = (iVal << 8) | cp[2]; |
|
1543 |
iVal = (iVal << 8) | cp[3]; |
|
1544 |
} |
|
1545 |
} else { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1546 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
4515 | 1547 |
/* |
1548 |
* aligned or not - we dont care |
|
1549 |
* (i386 can fetch unaligned) |
|
1550 |
*/ |
|
1551 |
iVal = ((int *)cp)[0]; |
|
1552 |
#else |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1553 |
# if defined(__LSBFIRST__) |
4515 | 1554 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
1555 |
/* |
|
1556 |
* aligned |
|
1557 |
*/ |
|
1558 |
iVal = ((int *)cp)[0]; |
|
1559 |
} else |
|
1560 |
# endif |
|
1561 |
{ |
|
1562 |
iVal = cp[3]; |
|
1563 |
iVal = (iVal << 8) | cp[2]; |
|
1564 |
iVal = (iVal << 8) | cp[1]; |
|
1565 |
iVal = (iVal << 8) | cp[0]; |
|
1566 |
} |
|
1567 |
#endif |
|
1568 |
} |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1569 |
#if __POINTER_SIZE__ == 8 |
8913 | 1570 |
RETURN (__mkSmallInteger(iVal)); |
4515 | 1571 |
#else |
1572 |
RETURN (__MKINT(iVal)); |
|
1573 |
#endif |
|
1574 |
} |
|
1575 |
} |
|
1576 |
} |
|
1577 |
%}. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1578 |
|
4515 | 1579 |
"/ fallBack code - non ByteArray-like receiver |
1580 |
"/ or funny index |
|
1581 |
||
1582 |
i := index. |
|
1583 |
b1 := self at:i. |
|
1584 |
b2 := self at:(i+1). |
|
1585 |
b3 := self at:(i+2). |
|
1586 |
b4 := self at:(i+3). |
|
1587 |
||
1588 |
msb ifFalse:[ |
|
1589 |
t := b4. b4 := b1. b1 := t. |
|
1590 |
t := b3. b3 := b2. b2 := t. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1591 |
]. |
4515 | 1592 |
ival := b1. |
1593 |
ival := (ival bitShift:8) + b2. |
|
1594 |
ival := (ival bitShift:8) + b3. |
|
1595 |
val := (ival bitShift:8) + b4. |
|
1596 |
||
1597 |
(val > (16r7FFFFFFF)) ifTrue:[ |
|
1598 |
^ val - (16r100000000) |
|
1599 |
]. |
|
1600 |
^ val |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1601 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1602 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1603 |
|b| |
4515 | 1604 |
|
1605 |
b := ByteArray withAll:#(1 2 3 4). |
|
1606 |
(b signedDoubleWordAt:1 MSB:true) printStringRadix:16. |
|
1607 |
(b signedDoubleWordAt:1 MSB:false) printStringRadix:16 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1608 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1609 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1610 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1611 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1612 |
signedDoubleWordAt:index put:value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1613 |
"set the 4-bytes starting at index from the signed Integer value. |
3433 | 1614 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1615 |
The value is stored in the machines natural byte order. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1616 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1617 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1618 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1619 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1620 |
value >= 0 ifTrue:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1621 |
v := value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1622 |
] ifFalse:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1623 |
v := value + 16r100000000 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1624 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1625 |
self doubleWordAt:index put:v. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1626 |
^ value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1627 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1628 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1629 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1630 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1631 |
b signedDoubleWordAt:1 put:-1. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1632 |
(b doubleWordAt:1) printStringRadix:16 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1633 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1634 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1635 |
"Modified: 1.7.1996 / 21:11:39 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1636 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1637 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1638 |
signedDoubleWordAt:index put:value MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1639 |
"set the 4-bytes starting at index from the signed Integer value. |
3433 | 1640 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1641 |
Depending on msb, the value is stored MSB-first or LSB-first. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1642 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1643 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1644 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1645 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1646 |
value >= 0 ifTrue:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1647 |
v := value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1648 |
] ifFalse:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1649 |
v := value + 16r100000000 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1650 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1651 |
self doubleWordAt:index put:v MSB:msb. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1652 |
^ value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1653 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1654 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1655 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1656 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1657 |
b signedDoubleWordAt:1 put:-1. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1658 |
(b doubleWordAt:1) printStringRadix:16 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1659 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1660 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1661 |
"Modified: 1.7.1996 / 21:11:46 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1662 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1663 |
|
3323 | 1664 |
unsignedLongAt:index |
1665 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 1666 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1667 |
The value is retrieved in the machines natural byte order. |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1668 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1669 |
Same as doubleWordAt: for protocol completeness" |
3323 | 1670 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1671 |
^ self doubleWordAt:index |
3323 | 1672 |
|
1673 |
" |
|
1674 |
|b| |
|
1675 |
||
1676 |
b := ByteArray withAll:#(1 2 3 4). |
|
1677 |
(b unsignedLongAt:1) printStringRadix:16 |
|
1678 |
" |
|
1679 |
||
1680 |
"Created: / 5.3.1998 / 11:56:53 / stefan" |
|
1681 |
"Modified: / 5.3.1998 / 14:58:48 / stefan" |
|
1682 |
! |
|
1683 |
||
1684 |
unsignedLongAt:index bigEndian:msb |
|
1685 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 1686 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1687 |
The value is retrieved MSB-first, if the msb-arg is true; |
1688 |
LSB-first otherwise. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1689 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1690 |
Same as doubleWordAt:MSB: for protocol completeness" |
3323 | 1691 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1692 |
^ self doubleWordAt:index MSB:msb |
3323 | 1693 |
|
1694 |
" |
|
1695 |
|b| |
|
1696 |
||
1697 |
b := ByteArray withAll:#(1 2 3 4). |
|
1698 |
(b unsignedLongAt:1 bigEndian:true) printStringRadix:16. |
|
1699 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1700 |
" |
|
1701 |
||
1702 |
"Modified: / 21.1.1998 / 17:42:30 / cg" |
|
1703 |
"Created: / 5.3.1998 / 11:46:05 / stefan" |
|
1704 |
! |
|
1705 |
||
1706 |
unsignedLongAt:index put:value |
|
1707 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 1708 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1709 |
The value should be in the range 0 to 16rFFFFFFFF |
1710 |
(for negative values, the stored value is not defined). |
|
1711 |
The value is stored in the machines natural byte order. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1712 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1713 |
Same as doubleWordAt:put: for protocol completeness" |
3323 | 1714 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1715 |
^ self doubleWordAt:index put:value |
3323 | 1716 |
|
1717 |
" |
|
1718 |
|b| |
|
1719 |
b := ByteArray new:4. |
|
1720 |
b unsignedLongAt:1 put:16r04030201. |
|
1721 |
b inspect |
|
1722 |
" |
|
1723 |
||
1724 |
"Created: / 5.3.1998 / 11:57:44 / stefan" |
|
1725 |
"Modified: / 5.3.1998 / 14:58:59 / stefan" |
|
1726 |
! |
|
1727 |
||
1728 |
unsignedLongAt:index put:aNumber bigEndian:msb |
|
1729 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 1730 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1731 |
The value must be in the range 0 to 16rFFFFFFFF. |
1732 |
The value is stored MSB-first if msb is true; LSB-first otherwise. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1733 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1734 |
Same as doubleWordAt:put:MSB: for protocol completeness" |
3323 | 1735 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1736 |
^ self doubleWordAt:index put:aNumber MSB:msb |
3323 | 1737 |
|
1738 |
" |
|
1739 |
|b| |
|
1740 |
b := ByteArray new:8. |
|
1741 |
b unsignedLongAt:1 put:16r04030201 bigEndian:true. |
|
1742 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1743 |
" |
|
1744 |
||
1745 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
1746 |
"Created: / 5.3.1998 / 11:43:53 / stefan" |
|
1747 |
"Modified: / 5.3.1998 / 11:47:30 / stefan" |
|
3459 | 1748 |
! ! |
1749 |
||
1750 |
!UninterpretedBytes methodsFor:'accessing-shorts'! |
|
1751 |
||
1752 |
shortAt:index |
|
1753 |
"return the 2-bytes starting at index as a signed Integer. |
|
1754 |
The index is a smalltalk index (i.e. 1-based). |
|
1755 |
The value is retrieved in the machines natural byte order. |
|
1756 |
This may be worth a primitive. |
|
1757 |
This is the ST80 equivalent of #signedWordAt:" |
|
1758 |
||
1759 |
^ (self unsignedShortAt:index) signExtendedShortValue |
|
1760 |
||
1761 |
" |
|
1762 |
|b| |
|
1763 |
b := ByteArray new:2. |
|
1764 |
b unsignedShortAt:1 put:16rFFFF. |
|
1765 |
b shortAt:1 |
|
1766 |
" |
|
1767 |
||
1768 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
|
1769 |
"Created: / 5.3.1998 / 10:59:57 / stefan" |
|
1770 |
"Modified: / 5.3.1998 / 23:39:38 / stefan" |
|
3323 | 1771 |
! |
1772 |
||
3459 | 1773 |
shortAt:index bigEndian:msb |
1774 |
"return the 2-bytes starting at index as a signed Integer. |
|
3433 | 1775 |
The index is a smalltalk index (i.e. 1-based). |
3459 | 1776 |
The value is retrieved MSB-first, if the msb-arg is true; |
1777 |
LSB-first otherwise. |
|
1778 |
This is the ST80 equivalent of #signedWordAt:" |
|
1779 |
||
1780 |
^ (self unsignedShortAt:index bigEndian:msb) signExtendedShortValue |
|
1781 |
||
1782 |
" |
|
1783 |
|b| |
|
1784 |
b := ByteArray new:2. |
|
1785 |
b unsignedShortAt:1 put:16rFFFF. |
|
1786 |
b shortAt:1 |
|
1787 |
" |
|
3323 | 1788 |
|
3459 | 1789 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
1790 |
"Created: / 5.3.1998 / 23:41:21 / stefan" |
|
1791 |
! |
|
1792 |
||
1793 |
shortAt:index put:value |
|
1794 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1795 |
The index is a smalltalk index (i.e. 1-based). |
|
1796 |
The stored value must be in the range -32768 .. +32676. |
|
1797 |
The value is stored in the machines natural byteorder. |
|
1798 |
This may be worth a primitive. |
|
1799 |
This is the ST80 equivalent of #signedWordAt:put:" |
|
1800 |
||
3323 | 1801 |
|
3459 | 1802 |
|v| |
1803 |
||
1804 |
value >= 0 ifTrue:[ |
|
8017 | 1805 |
v := value |
3323 | 1806 |
] ifFalse:[ |
8017 | 1807 |
v := 16r10000 + value |
3323 | 1808 |
]. |
8017 | 1809 |
self unsignedShortAt:index put:v bigEndian:(UninterpretedBytes isBigEndian). |
3459 | 1810 |
^ value |
1811 |
||
1812 |
" |
|
1813 |
|b| |
|
1814 |
b := ByteArray new:6. |
|
1815 |
b shortAt:1 put:-1. |
|
1816 |
b shortAt:3 put:-2. |
|
1817 |
b shortAt:5 put:0. |
|
1818 |
b inspect |
|
1819 |
" |
|
1820 |
||
1821 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1822 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
1823 |
! |
|
1824 |
||
8017 | 1825 |
shortAt:index put:value bigEndian:bigEndian |
1826 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1827 |
The index is a smalltalk index (i.e. 1-based). |
|
1828 |
The stored value must be in the range -32768 .. +32676. |
|
8018 | 1829 |
The value is stored in the byteorder given by bigEndian. |
1830 |
This may be worth a primitive." |
|
8017 | 1831 |
|
1832 |
||
1833 |
|v| |
|
1834 |
||
1835 |
value >= 0 ifTrue:[ |
|
1836 |
v := value |
|
1837 |
] ifFalse:[ |
|
1838 |
v := 16r10000 + value |
|
1839 |
]. |
|
1840 |
self unsignedShortAt:index put:v bigEndian:bigEndian. |
|
1841 |
^ value |
|
1842 |
||
1843 |
" |
|
1844 |
|b| |
|
1845 |
b := ByteArray new:4. |
|
1846 |
b shortAt:1 put:1 bigEndian:true. |
|
1847 |
b shortAt:3 put:1 bigEndian:false. |
|
1848 |
b inspect |
|
1849 |
" |
|
1850 |
||
1851 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1852 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
1853 |
! |
|
1854 |
||
3459 | 1855 |
signedWordAt:index |
1856 |
"return the 2-bytes starting at index as a signed Integer. |
|
1857 |
The index is a smalltalk index (i.e. 1-based). |
|
1858 |
The value is retrieved in the machines natural byte order. |
|
1859 |
This may be worth a primitive." |
|
1860 |
||
1861 |
^ (self wordAt:index) signExtendedShortValue |
|
3323 | 1862 |
|
1863 |
" |
|
1864 |
|b| |
|
3459 | 1865 |
b := ByteArray new:2. |
1866 |
b wordAt:1 put:16rFFFF. |
|
1867 |
b signedWordAt:1 |
|
3323 | 1868 |
" |
1869 |
||
3459 | 1870 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
3323 | 1871 |
! |
1872 |
||
3459 | 1873 |
signedWordAt:index MSB:msb |
1874 |
"return the 2-bytes starting at index as a signed Integer. |
|
3433 | 1875 |
The index is a smalltalk index (i.e. 1-based). |
3459 | 1876 |
The value is retrieved MSB-first if the msb-arg is true, |
1877 |
LSB-first otherwise. |
|
1878 |
This may be worth a primitive." |
|
3323 | 1879 |
|
3459 | 1880 |
^ (self wordAt:index MSB:msb) signExtendedShortValue |
3323 | 1881 |
|
1882 |
" |
|
1883 |
|b| |
|
3459 | 1884 |
b := ByteArray new:2. |
1885 |
b wordAt:1 put:16r0080. |
|
1886 |
b signedWordAt:1 MSB:true. |
|
1887 |
b signedWordAt:1 MSB:false. |
|
1888 |
" |
|
1889 |
||
1890 |
"Modified: 1.7.1996 / 21:15:57 / cg" |
|
1891 |
! |
|
1892 |
||
1893 |
signedWordAt:index put:value |
|
1894 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1895 |
The index is a smalltalk index (i.e. 1-based). |
|
1896 |
The stored value must be in the range -32768 .. +32676. |
|
1897 |
The value is stored in the machines natural byteorder. |
|
1898 |
This may be worth a primitive. |
|
1899 |
This is the ST80 equivalent of #signedWordAt:put:" |
|
1900 |
||
1901 |
||
1902 |
|v| |
|
1903 |
||
1904 |
value >= 0 ifTrue:[ |
|
4308 | 1905 |
v := value |
3459 | 1906 |
] ifFalse:[ |
4308 | 1907 |
v := 16r10000 + value |
3459 | 1908 |
]. |
1909 |
self unsignedShortAt:index put:v. |
|
1910 |
^ value |
|
1911 |
||
1912 |
" |
|
1913 |
|b| |
|
1914 |
b := ByteArray new:6. |
|
1915 |
b shortAt:1 put:-1. |
|
1916 |
b shortAt:3 put:-2. |
|
1917 |
b shortAt:5 put:0. |
|
3323 | 1918 |
b inspect |
1919 |
" |
|
1920 |
||
3459 | 1921 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
1922 |
"Modified: / 5.3.1998 / 11:01:30 / stefan" |
|
1923 |
! |
|
1924 |
||
1925 |
signedWordAt:index put:value MSB:msb |
|
1926 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1927 |
The index is a smalltalk index (i.e. 1-based). |
|
1928 |
The stored value must be in the range -32768 .. +32676. |
|
1929 |
The value is stored MSB-first, if the msb-arg is true; |
|
1930 |
LSB-first otherwise. |
|
1931 |
This may be worth a primitive." |
|
1932 |
||
1933 |
|v| |
|
1934 |
||
1935 |
value >= 0 ifTrue:[ |
|
1936 |
v := value |
|
1937 |
] ifFalse:[ |
|
1938 |
v := 16r10000 + value |
|
1939 |
]. |
|
1940 |
self wordAt:index put:v MSB:msb. |
|
1941 |
^ value |
|
1942 |
||
1943 |
" |
|
1944 |
|b| |
|
1945 |
b := ByteArray new:4. |
|
1946 |
b signedWordAt:1 put:-1. |
|
1947 |
b signedWordAt:3 put:-2. |
|
1948 |
b inspect |
|
1949 |
" |
|
1950 |
||
1951 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
3323 | 1952 |
! |
1953 |
||
1954 |
unsignedShortAt:index |
|
1955 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
3433 | 1956 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1957 |
The value is retrieved in the machines natural byte order |
1958 |
Subclasses may redefine this for better performance. |
|
1959 |
This is the ST80 equivalent of #wordAt:" |
|
1960 |
||
1961 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1962 |
^ self unsignedShortAt:index bigEndian:(UninterpretedBytes isBigEndian) |
3323 | 1963 |
|
1964 |
"Created: / 5.3.1998 / 11:38:25 / stefan" |
|
1965 |
"Modified: / 5.3.1998 / 14:59:25 / stefan" |
|
1966 |
! |
|
1967 |
||
1968 |
unsignedShortAt:index bigEndian:msb |
|
1969 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
3433 | 1970 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1971 |
The value is retrieved MSB-first (high 8 bits at lower index) if msb is true; |
1972 |
LSB-first (i.e. low 8-bits at lower byte index) if its false)" |
|
1973 |
||
1974 |
|b1 "{ Class: SmallInteger }" |
|
1975 |
b2 "{ Class: SmallInteger }"| |
|
1976 |
||
1977 |
b1 := self at:index. |
|
1978 |
b2 := self at:(index + 1). |
|
1979 |
msb ifTrue:[ |
|
4308 | 1980 |
^ (b1 bitShift:8) + b2 |
3323 | 1981 |
]. |
1982 |
^ (b2 bitShift:8) + b1 |
|
1983 |
||
1984 |
"Modified: / 21.1.1998 / 17:46:07 / cg" |
|
1985 |
"Created: / 5.3.1998 / 11:49:29 / stefan" |
|
1986 |
! |
|
1987 |
||
1988 |
unsignedShortAt:index put:value |
|
1989 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 1990 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1991 |
The stored value must be in the range 0 .. 16rFFFF. |
1992 |
The value is stored in the machines natural byteorder." |
|
1993 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1994 |
^ self unsignedShortAt:index put:value bigEndian:(UninterpretedBytes isBigEndian) |
3323 | 1995 |
|
1996 |
" |
|
1997 |
|b| |
|
1998 |
b := ByteArray new:4. |
|
1999 |
b unsignedShortAt:1 put:16r0102. |
|
2000 |
b unsignedShortAt:3 put:16r0304. |
|
2001 |
b inspect |
|
2002 |
" |
|
2003 |
||
2004 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
2005 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
2006 |
! |
|
2007 |
||
2008 |
unsignedShortAt:index put:value bigEndian:msb |
|
2009 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 2010 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2011 |
The stored value must be in the range 0 .. 16rFFFF. |
2012 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
|
2013 |
lower index) if msb is false, MSB-first otherwise" |
|
2014 |
||
2015 |
|b1 b2 |
|
2016 |
iVal "{ Class: SmallInteger }"| |
|
2017 |
||
2018 |
iVal := value. |
|
2019 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2020 |
^ self elementBoundsError:iVal |
3323 | 2021 |
]. |
2022 |
msb ifTrue:[ |
|
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2023 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2024 |
b2 := (iVal bitAnd:16rFF). |
3323 | 2025 |
] ifFalse:[ |
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2026 |
b1 := (iVal bitAnd:16rFF). |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2027 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
3323 | 2028 |
]. |
2029 |
self at:index put:b1. |
|
2030 |
self at:index+1 put:b2. |
|
2031 |
^ value |
|
2032 |
||
2033 |
" |
|
2034 |
|b| |
|
2035 |
b := ByteArray new:8. |
|
2036 |
b unsignedShortAt:1 put:16r0102 bigEndian:false. |
|
2037 |
b unsignedShortAt:3 put:16r0304 bigEndian:false. |
|
2038 |
b unsignedShortAt:5 put:16r0102 bigEndian:true. |
|
2039 |
b unsignedShortAt:7 put:16r0304 bigEndian:true. |
|
2040 |
b inspect |
|
2041 |
" |
|
2042 |
||
2043 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
2044 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
2045 |
! |
|
2046 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2047 |
wordAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2048 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 2049 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2050 |
The value is retrieved in the machines natural byte order |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2051 |
Subclasses may redefine this for better performance." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2052 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2053 |
^ self wordAt:index MSB:(UninterpretedBytes isBigEndian) |
3323 | 2054 |
|
2055 |
"Modified: / 5.3.1998 / 14:59:51 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2056 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2057 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2058 |
wordAt:index MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2059 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 2060 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2061 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2062 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2063 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2064 |
|
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2065 |
|b1 "{ Class: SmallInteger }" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2066 |
b2 "{ Class: SmallInteger }"| |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2067 |
|
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2068 |
b1 := self at:index. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2069 |
b2 := self at:(index + 1). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2070 |
msb ifTrue:[ |
4308 | 2071 |
^ (b1 bitShift:8) + b2 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2072 |
]. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2073 |
^ (b2 bitShift:8) + b1 |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2074 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2075 |
"Modified: / 21.1.1998 / 17:46:07 / cg" |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2076 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2077 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2078 |
wordAt:index put:value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2079 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 2080 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2081 |
The stored value must be in the range 0 .. 16rFFFF. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2082 |
The value is stored in the machines natural byteorder. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2083 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2084 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2085 |
^ self wordAt:index put:value MSB:(UninterpretedBytes isBigEndian) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2086 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2087 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2088 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2089 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2090 |
b wordAt:1 put:16r0102. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2091 |
b wordAt:3 put:16r0304. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2092 |
b inspect |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2093 |
" |
3323 | 2094 |
|
2095 |
"Modified: / 5.3.1998 / 15:00:03 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2096 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2097 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2098 |
wordAt:index put:value MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2099 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 2100 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2101 |
The stored value must be in the range 0 .. 16rFFFF. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2102 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2103 |
lower index) if msb is false, MSB-first otherwise. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2104 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2105 |
|
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2106 |
|b1 b2 |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2107 |
iVal "{ Class: SmallInteger }"| |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2108 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2109 |
iVal := value. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2110 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2111 |
^ self elementBoundsError:iVal |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2112 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2113 |
msb ifTrue:[ |
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2114 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2115 |
b2 := (iVal bitAnd:16rFF). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2116 |
] ifFalse:[ |
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2117 |
b1 := (iVal bitAnd:16rFF). |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2118 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2119 |
]. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2120 |
self at:index put:b1. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2121 |
self at:index+1 put:b2. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2122 |
^ value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2123 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2124 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2125 |
b := ByteArray new:8. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2126 |
b wordAt:1 put:16r0102 MSB:false. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2127 |
b wordAt:3 put:16r0304 MSB:false. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2128 |
b wordAt:5 put:16r0102 MSB:true. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2129 |
b wordAt:7 put:16r0304 MSB:true. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2130 |
b inspect |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2131 |
" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2132 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2133 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2134 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2135 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2136 |
wordAtWordIndex:index |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2137 |
"return the unsigned short at index, anInteger. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2138 |
Fetching in the machines natural byte order. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2139 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2140 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2141 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2142 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2143 |
^ self wordAtWordIndex:index MSB:(UninterpretedBytes isBigEndian) |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2144 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2145 |
"Created: / 21.1.1998 / 17:48:26 / cg" |
3323 | 2146 |
"Modified: / 5.3.1998 / 15:00:16 / stefan" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2147 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2148 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2149 |
wordAtWordIndex:index MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2150 |
"return the unsigned short at index, anInteger. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2151 |
Fetching is MSB if msb is true, LSB otherwise. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2152 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2153 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2154 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2155 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2156 |
^ self wordAt:(index - 1 * 2 + 1) MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2157 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2158 |
"Created: / 21.1.1998 / 17:48:30 / cg" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2159 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2160 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2161 |
wordAtWordIndex:index put:value |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2162 |
"set the short at index, anInteger. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2163 |
Storing in the machines natural byte order. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2164 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2165 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2166 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2167 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2168 |
^ self wordAtWordIndex:index put:value MSB:(UninterpretedBytes isBigEndian) |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2169 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2170 |
"Created: / 21.1.1998 / 17:48:34 / cg" |
3323 | 2171 |
"Modified: / 5.3.1998 / 15:00:27 / stefan" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2172 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2173 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2174 |
wordAtWordIndex:index put:value MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2175 |
"set the short at index, anInteger. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2176 |
Storing is MSB if msb is true, LSB otherwise. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2177 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2178 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2179 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2180 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2181 |
^ self wordAt:(index - 1 * 2 + 1) put:value MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2182 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2183 |
"Created: / 21.1.1998 / 17:48:38 / cg" |
3459 | 2184 |
! ! |
2185 |
||
2186 |
!UninterpretedBytes methodsFor:'accessing-strings'! |
|
2187 |
||
2188 |
stringAt:index |
|
2189 |
"return a string starting at index up to the 0-byte. |
|
2190 |
The index is a smalltalk index (i.e. 1-based)." |
|
2191 |
||
2192 |
|stream i "{ Class: SmallInteger }" c| |
|
2193 |
||
2194 |
stream := WriteStream on:''. |
|
2195 |
i := index. |
|
2196 |
[(c := self basicAt:i) ~~ 0] whileTrue:[ |
|
4308 | 2197 |
stream nextPut:(Character value:c). |
2198 |
i := i + 1. |
|
3459 | 2199 |
]. |
2200 |
^ stream contents |
|
2201 |
||
2202 |
"Created: / 21.1.1998 / 17:44:50 / cg" |
|
2203 |
! |
|
2204 |
||
2205 |
stringAt:index put:aString |
|
2206 |
"copy aString to the externalBytes, starting at index up to |
|
7815 | 2207 |
(and including) the 0-byte (which is always written). |
3459 | 2208 |
The index is a smalltalk index (i.e. 1-based)." |
2209 |
||
2210 |
|i "{ Class: SmallInteger }"| |
|
2211 |
||
2212 |
i := index. |
|
2213 |
aString do:[:aChar | |
|
8092
0ad1f154622a
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8018
diff
changeset
|
2214 |
self basicAt:i put:aChar codePoint. |
7815 | 2215 |
i := i + 1. |
3459 | 2216 |
]. |
2217 |
self basicAt:i put:0. |
|
2218 |
^ aString |
|
2219 |
||
2220 |
" |
|
2221 |
|bytes| |
|
2222 |
||
2223 |
bytes := ExternalBytes new:10. |
|
2224 |
bytes stringAt:1 put:'hello'. |
|
2225 |
1 to:bytes size do:[:i | |
|
7815 | 2226 |
Transcript showCR:(bytes at:i) |
3459 | 2227 |
] |
2228 |
" |
|
2229 |
||
2230 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
|
2231 |
! |
|
2232 |
||
7812 | 2233 |
stringAt:index put:aString size:maxSize |
2234 |
"copy aString to the externalBytes, starting at index up to either maxSize characters, |
|
2235 |
or (and including) the 0-byte, whichever is encountered first. |
|
7815 | 2236 |
The final 0-byte is only written, if the string is shorter than maxSize. |
7812 | 2237 |
The index is a smalltalk index (i.e. 1-based)." |
2238 |
||
2239 |
|remaining "{ Class: SmallInteger }" |
|
2240 |
i "{ Class: SmallInteger }"| |
|
2241 |
||
2242 |
remaining := maxSize. |
|
7816 | 2243 |
remaining <= 0 ifTrue:[^ aString]. |
7812 | 2244 |
|
2245 |
i := index. |
|
2246 |
aString do:[:aChar | |
|
8092
0ad1f154622a
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8018
diff
changeset
|
2247 |
self basicAt:i put:aChar codePoint. |
7812 | 2248 |
i := i + 1. |
2249 |
remaining := remaining - 1. |
|
7815 | 2250 |
remaining <= 0 ifTrue:[^ aString]. |
7812 | 2251 |
]. |
2252 |
self basicAt:i put:0. |
|
2253 |
^ aString |
|
2254 |
||
2255 |
" |
|
2256 |
|bytes| |
|
2257 |
||
2258 |
bytes := ExternalBytes new:10. |
|
2259 |
bytes stringAt:1 put:'hello' size:3. |
|
2260 |
1 to:bytes size do:[:i | |
|
2261 |
Transcript showCR:(bytes at:i) |
|
2262 |
] |
|
2263 |
" |
|
2264 |
" |
|
2265 |
|bytes| |
|
2266 |
||
2267 |
bytes := ByteArray new:10 withAll:16rFF. |
|
2268 |
bytes stringAt:1 put:'he' size:3. |
|
2269 |
1 to:bytes size do:[:i | |
|
2270 |
Transcript showCR:(bytes at:i) |
|
2271 |
] |
|
2272 |
" |
|
2273 |
||
2274 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
|
2275 |
! |
|
2276 |
||
3459 | 2277 |
stringAt:index size:maxSize |
2278 |
"return a string starting at index up to maxSize, or a 0-byte. |
|
2279 |
The index is a smalltalk index (i.e. 1-based)." |
|
2280 |
||
2281 |
|stream c i "{ Class: SmallInteger }"| |
|
2282 |
||
2283 |
stream := WriteStream on:(String new:maxSize). |
|
2284 |
i := index. |
|
2285 |
[(i <= maxSize) |
|
2286 |
and:[(c := self basicAt:i) ~~ 0]] whileTrue:[ |
|
4308 | 2287 |
stream nextPut:(Character value:c). |
2288 |
i := i + 1. |
|
3459 | 2289 |
]. |
2290 |
^ stream contents |
|
2291 |
||
2292 |
"Modified: / 21.1.1998 / 17:45:23 / cg" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2293 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2294 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2295 |
zeroByteStringAt:index maximumSize:count |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2296 |
"extract a zeroByte-delimited string, given initial index and |
3433 | 2297 |
maximum number of characters (bytes). |
2298 |
The index is a smalltalk index (i.e. 1-based)." |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2299 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2300 |
|bytes idx| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2301 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2302 |
bytes := self copyFrom:index to:(index + count - 1). |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2303 |
idx := bytes indexOf:0. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2304 |
idx ~~ 0 ifTrue:[ bytes := bytes copyTo:idx-1 ]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2305 |
^ bytes asString |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2306 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2307 |
"Created: 9.9.1996 / 15:28:34 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2308 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2309 |
|
4782 | 2310 |
!UninterpretedBytes methodsFor:'filling & replacing'! |
2311 |
||
2312 |
replaceBytesFrom:start to:stop with:sourceBytes startingAt:sourceIndex |
|
7252
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
2313 |
|srcIdx| |
4782 | 2314 |
|
7252
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
2315 |
srcIdx := sourceIndex. |
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
2316 |
start to:stop do:[:dstIdx | |
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
2317 |
self at:dstIdx put:(sourceBytes at:srcIdx). |
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
2318 |
srcIdx := srcIdx + 1 |
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
2319 |
]. |
4782 | 2320 |
! ! |
2321 |
||
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2322 |
!UninterpretedBytes methodsFor:'misc'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2323 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2324 |
swapLongAt:byteIndex |
3433 | 2325 |
"swap the byteOrder of a long. |
2326 |
The index is a smalltalk index (i.e. 1-based)." |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2327 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2328 |
|t| |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2329 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2330 |
t := self byteAt:byteIndex. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2331 |
self byteAt:byteIndex put:(self byteAt:(byteIndex + 3)). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2332 |
self byteAt:(byteIndex + 3) put:t. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2333 |
t := self byteAt:(byteIndex + 1). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2334 |
self byteAt:(byteIndex + 1) put:(self byteAt:(byteIndex + 2)). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2335 |
self byteAt:(byteIndex + 2) put:t |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2336 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2337 |
"Created: / 3.4.1998 / 13:37:01 / cg" |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2338 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2339 |
|
3323 | 2340 |
!UninterpretedBytes methodsFor:'queries'! |
2341 |
||
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2342 |
defaultElement |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2343 |
^ 0 |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2344 |
! |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
2345 |
|
3323 | 2346 |
sizeInBytes |
2347 |
"return the number of 8-bit bytes in the receiver. |
|
2348 |
This is needed since subclasse may redefine #size (TwoByteString)" |
|
2349 |
||
2350 |
^ super size |
|
2351 |
||
2352 |
"Created: / 5.3.1998 / 10:41:13 / stefan" |
|
2353 |
! ! |
|
2354 |
||
8986 | 2355 |
!UninterpretedBytes methodsFor:'testing'! |
2356 |
||
2357 |
isByteCollection |
|
2358 |
"return true, if the receiver has access methods for bytes; |
|
2359 |
true is returned here - the method is redefined from Object." |
|
2360 |
||
2361 |
^ true |
|
9005 | 2362 |
! |
2363 |
||
2364 |
isNonByteCollection |
|
2365 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
2366 |
false is returned here - the method is redefined from Collection." |
|
2367 |
||
2368 |
^ false |
|
8986 | 2369 |
! ! |
2370 |
||
695 | 2371 |
!UninterpretedBytes class methodsFor:'documentation'! |
2372 |
||
2373 |
version |
|
9005 | 2374 |
^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.60 2005-11-30 22:06:48 stefan Exp $' |
695 | 2375 |
! ! |