author | Claus Gittinger <cg@exept.de> |
Mon, 14 Nov 2016 17:33:01 +0100 | |
changeset 20961 | a8e7825ad3c0 |
parent 20960 | bdad938cfe9d |
child 21024 | 8734987eb5c7 |
child 21320 | 8b0aaee195e6 |
permissions | -rw-r--r-- |
20961 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
19368 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
6492 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
18284 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
18 |
ArrayedCollection subclass:#UninterpretedBytes |
20372 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'IsBigEndian' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Collections-Abstract' |
|
1 | 23 |
! |
24 |
||
3433 | 25 |
!UninterpretedBytes primitiveDefinitions! |
26 |
%{ |
|
27 |
/* |
|
28 |
* Notice: I am abstract, and my subclasses may be anything. |
|
29 |
* Therefore, the code must always handle the fallback case |
|
30 |
* where the receiver is neither an ExternalBytes nor a ByteArray. |
|
31 |
* (which are, however, the most common) |
|
32 |
* |
|
33 |
* macro to fetch my byte address and size-in-bytes; |
|
34 |
* convenient for inline-C code. |
|
35 |
* (yes, C is bad ...) |
|
36 |
*/ |
|
37 |
#define __fetchBytePointerAndSize__(o, pPtr, pSize) \ |
|
38 |
{\ |
|
39 |
if (__isNonNilObject(o)) { \ |
|
19368 | 40 |
if (__isByteArrayLike(o)) { \ |
41 |
*(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \ |
|
42 |
*(pSize) = __byteArraySize(o); \ |
|
43 |
} else if (__qIsExternalBytesLike(o)) { \ |
|
44 |
OBJ __sz__ = __externalBytesSize(o); \ |
|
45 |
if (__isSmallInteger(__sz__)) { \ |
|
46 |
*(pSize) = __intVal(__sz__); \ |
|
47 |
*(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \ |
|
48 |
} else { \ |
|
49 |
*(pSize) = 0; \ |
|
50 |
*(pPtr) = (unsigned char *)0; \ |
|
51 |
} \ |
|
52 |
} else { \ |
|
53 |
*(pSize) /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(o))->c_ninstvars)); \ |
|
54 |
*(pPtr) = (char *)(__InstPtr(self)) + *(pSize) /* nInstBytes */; \ |
|
55 |
*(pSize) = __qSize(self) - *(pSize) /* nInstBytes */; \ |
|
56 |
} \ |
|
3433 | 57 |
} else { \ |
19368 | 58 |
*(pSize) = 0; \ |
59 |
*(pPtr) = (unsigned char *)0; \ |
|
3433 | 60 |
} \ |
61 |
} |
|
62 |
||
63 |
%} |
|
64 |
! ! |
|
65 |
||
68 | 66 |
!UninterpretedBytes class methodsFor:'documentation'! |
1 | 67 |
|
88 | 68 |
copyright |
69 |
" |
|
70 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
19368 | 71 |
All Rights Reserved |
88 | 72 |
|
73 |
This software is furnished under a license and may be used |
|
74 |
only in accordance with the terms of that license and with the |
|
75 |
inclusion of the above copyright notice. This software may not |
|
76 |
be provided or otherwise made available to, or used by, any |
|
77 |
other person. No title to or ownership of the software is |
|
78 |
hereby transferred. |
|
79 |
" |
|
80 |
! |
|
81 |
||
68 | 82 |
documentation |
83 |
" |
|
13575 | 84 |
UninterpretedBytes provides the common protocol for byte-storage |
85 |
containers; concrete subclasses are |
|
19101 | 86 |
ByteArray (which store the bytes within the Smalltalk object memory) |
87 |
String (knows that the bytes represent characters) |
|
13575 | 88 |
and |
19101 | 89 |
ExternalBytes (which store the bytes in the malloc-heap). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
90 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
91 |
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
|
92 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
93 |
[See also:] |
19101 | 94 |
ByteArray String ExternalBytes |
1294 | 95 |
|
96 |
[author:] |
|
19101 | 97 |
Claus Gittinger |
3433 | 98 |
|
99 |
[Notice:] |
|
19101 | 100 |
Notice the confusion due to multiple methods with the same |
101 |
functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:'). |
|
102 |
The reason is that at the time this class was written, |
|
103 |
ST80 did not offer protocol to specify the byteOrder, and |
|
104 |
ST/X provided methods ending in 'MSB:' for this. |
|
105 |
In the meanwhile, VW added protocol ending in 'bigEndian:', |
|
106 |
which has been added here for compatibility. |
|
107 |
(certainly a point, where an ansi-standard will help) |
|
68 | 108 |
" |
109 |
! ! |
|
1 | 110 |
|
18284 | 111 |
!UninterpretedBytes class methodsFor:'initialization'! |
112 |
||
113 |
initialize |
|
114 |
IsBigEndian := self isBigEndian. |
|
115 |
! ! |
|
116 |
||
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
117 |
!UninterpretedBytes class methodsFor:'instance creation'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
118 |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
119 |
from:aByteArray |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
120 |
"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
|
121 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
122 |
|len bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
123 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
124 |
len := aByteArray size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
125 |
bytes := self new:len. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
126 |
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
|
127 |
^ 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 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
130 |
String from:#[40 41 42] |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
131 |
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
|
132 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
133 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
134 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
135 |
fromHexString:aString |
15717 | 136 |
"decode a byteArray from a hex string (as generated by hexPrintOn:)" |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
137 |
|
12551 | 138 |
| sz bytes s hi lo | |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
139 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
140 |
sz := aString size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
141 |
sz == 0 ifTrue:[^ self new]. |
14970 | 142 |
sz odd ifTrue:[ ConversionError raiseWith:aString errorString:'invalid hex string (odd size)' ]. |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
143 |
|
12551 | 144 |
bytes := self new: sz // 2. |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
145 |
s := aString readStream. |
12551 | 146 |
1 to: sz // 2 do: [ :idx | |
19368 | 147 |
hi := s next digitValue. |
148 |
lo := s next digitValue. |
|
149 |
bytes at:idx put: ((hi bitShift:4) bitOr: lo) |
|
8995
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 |
^ bytes |
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 |
ByteArray fromHexString:'1234FEFF' |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
155 |
ExternalBytes fromHexString:'1234FEFF' |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
156 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
157 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
158 |
|s| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
159 |
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
|
160 |
ByteArray fromHexString:s |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
161 |
" |
12551 | 162 |
" |
163 |
Time millisecondsToRun:[ |
|
19368 | 164 |
1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ] |
12551 | 165 |
]. |
166 |
" |
|
15717 | 167 |
|
168 |
"Modified (comment): / 28-08-2013 / 20:40:04 / cg" |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
169 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
170 |
|
11874
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
171 |
fromHexStringWithSeparators:aString |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
172 |
"read a bytearray from a printed string representation, where |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
173 |
individual bytes are encoded as two hex digits, optionally separated by whiteSpace. |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
174 |
See also fromHexString:, which does something similar, but does not allow for spaces" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
175 |
|
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
176 |
^ self streamContents:[:outStream | |
19368 | 177 |
|inStream h| |
178 |
||
179 |
inStream := aString readStream. |
|
180 |
||
181 |
[ |
|
182 |
inStream skipSeparators. |
|
183 |
inStream atEnd |
|
184 |
] whileFalse:[ |
|
185 |
h := inStream next:2. |
|
186 |
outStream nextPut:(Integer readFrom:h base:16). |
|
187 |
]. |
|
11874
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
188 |
]. |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
189 |
|
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
190 |
" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
191 |
ByteArray fromHexString:'1234FEFF' |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
192 |
ByteArray fromHexStringWithSeparators:' 12 34 FE FF' |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
193 |
" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
194 |
! |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
195 |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
196 |
fromPackedString:aString |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
197 |
"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
|
198 |
6bits are encoded per character. The argument, aString must be a multiple |
18633 | 199 |
of 4 in size (since 24 is the lcm of 6 and 8). |
200 |
Every 6 bit packet is encoded as a character in 32..95. |
|
201 |
Characters below 32 are ignored (so line breaks can be inserted at any place). |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
202 |
An addition final byte defines how many bytes of the last triple are valid. |
18633 | 203 |
This is somewhat like the radix-encoding used in good old PDP11 times ;-) |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
204 |
ST-80 uses this encoding for Images ... |
16798 | 205 |
This is a base64 encoding, very similar (but not equal) to the algorithm used in RFC1421. |
18346 | 206 |
PS: It took a while to figure that one out ... |
18633 | 207 |
PPS: I don't like it ;-)" |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
208 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
209 |
|index "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
210 |
dstIndex "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
211 |
stop "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
212 |
sixBits "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
213 |
n "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
214 |
sz "{ Class: SmallInteger }" |
12551 | 215 |
last bytes| |
8995
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 |
sz := aString size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
218 |
sz == 0 ifTrue:[^ self new]. |
12551 | 219 |
sz := sz - (aString count:[:ch | ch codePoint < 32]). |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
220 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
221 |
stop := sz // 4 * 3. |
12551 | 222 |
"the size modulo 3 is encoded in the last character, if it is in the |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
223 |
range 97 .. otherwise, its exact." |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
224 |
|
12551 | 225 |
last := aString last codePoint. |
226 |
last > 96 ifTrue:[ |
|
19368 | 227 |
stop := stop - 3 + (last - 96) |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
228 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
229 |
bytes := self new:stop. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
230 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
231 |
index := 1. dstIndex := 1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
232 |
[dstIndex <= stop] whileTrue:[ |
19368 | 233 |
"/ take 4 characters ... |
234 |
"/ allow a line break before each group of 4 |
|
235 |
sixBits := (aString at:index) codePoint. |
|
236 |
[sixBits < 32] whileTrue:[ |
|
237 |
index := index + 1. |
|
238 |
sixBits := (aString at:index) codePoint. |
|
239 |
]. |
|
240 |
sixBits := sixBits bitAnd:16r3F. |
|
241 |
n := sixBits. |
|
242 |
||
243 |
"/ self assert:(aString at:index+1) codePoint >= 32. |
|
244 |
sixBits := (aString at:index+1) codePoint bitAnd:16r3F. |
|
245 |
n := (n bitShift:6) + sixBits. |
|
246 |
||
247 |
"/ self assert:(aString at:index+2) codePoint >= 32. |
|
248 |
sixBits := (aString at:index+2) codePoint bitAnd:16r3F. |
|
249 |
n := (n bitShift:6) + sixBits. |
|
250 |
||
251 |
"/ self assert:(aString at:index+3) codePoint >= 32. |
|
252 |
sixBits := (aString at:index+3) codePoint bitAnd:16r3F. |
|
253 |
n := (n bitShift:6) + sixBits. |
|
254 |
||
255 |
index := index + 4. |
|
256 |
||
257 |
"/ now have 24 bits in n |
|
258 |
||
259 |
bytes at:dstIndex put:(n bitShift:-16). |
|
260 |
||
261 |
dstIndex < stop ifTrue:[ |
|
262 |
bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF). |
|
263 |
dstIndex+2 <= stop ifTrue:[ |
|
264 |
bytes at:dstIndex+2 put:(n bitAnd:16rFF). |
|
265 |
] |
|
266 |
]. |
|
267 |
dstIndex := dstIndex + 3. |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
268 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
269 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
270 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
271 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
272 |
ByteArray fromPackedString:(#[1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
273 |
ByteArray fromPackedString:(#[1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1 1] asPackedString) |
18633 | 277 |
ByteArray fromPackedString:((ByteArray new:256) asPackedString) |
278 |
ByteArray fromPackedString:((ByteArray new:128) asPackedString) |
|
279 |
ByteArray fromPackedString:((ByteArray new:129) asPackedString) |
|
280 |
ByteArray fromPackedString:((ByteArray new:130) asPackedString) |
|
281 |
ByteArray fromPackedString:((ByteArray new:131) asPackedString) |
|
282 |
ByteArray fromPackedString:((ByteArray new:132) asPackedString) |
|
283 |
ByteArray fromPackedString:((ByteArray new:64) asPackedString) |
|
284 |
||
285 |
0 to:256 do:[:l | |
|
19368 | 286 |
|orig copy| |
287 |
||
288 |
0 to:255 do:[:fill | |
|
289 |
orig := ByteArray new:l withAll:fill. |
|
290 |
copy := ByteArray fromPackedString:(orig asPackedString). |
|
291 |
self assert:(orig = copy). |
|
292 |
] |
|
18633 | 293 |
] |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
294 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
295 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
296 |
"Modified: / 6.3.1997 / 15:28:52 / cg" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
297 |
"Modified: / 18.12.1997 / 17:17:11 / stefan" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
298 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
299 |
|
18284 | 300 |
uninitializedNew:anInteger |
301 |
"return a new instance of the receiver with uninitialized |
|
302 |
(i.e. undefined) contents. The indexed elements have any random |
|
303 |
value. However, any named instance variables are still nilled. |
|
304 |
For use, when contents will be set anyway shortly after - this |
|
305 |
is a bit faster than the regular basicNew:, which clears the bytes. |
|
306 |
Of course, it only makes a difference for very big ByteArrays, such |
|
307 |
as used for images/bitmaps. |
|
308 |
||
309 |
Notice: if you want to port code using uninitializedNew: to another |
|
310 |
smalltalk, you have to add an 'uninitializedNew: -> basicNew:'-calling |
|
311 |
method to the ByteArray class of the other smalltalk." |
|
312 |
||
313 |
%{ /* NOCONTEXT */ |
|
314 |
OBJ newobj; |
|
315 |
INT instsize, nInstVars, nindexedinstvars; |
|
316 |
REGISTER OBJ *op; |
|
317 |
||
318 |
if (__isSmallInteger(anInteger)) { |
|
19368 | 319 |
nindexedinstvars = __intVal(anInteger); |
320 |
if (nindexedinstvars >= 0) { |
|
321 |
if (self == ByteArray) { |
|
322 |
/* |
|
323 |
* the most common case |
|
324 |
*/ |
|
325 |
instsize = OHDR_SIZE + nindexedinstvars; |
|
326 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
327 |
__qCheckedNew(newobj, instsize); |
|
328 |
__InstPtr(newobj)->o_class = self; |
|
329 |
__qSTORE(newobj, self); |
|
330 |
RETURN (newobj ); |
|
331 |
} |
|
332 |
} else { |
|
333 |
/* |
|
334 |
* Take care for subclasses like TwoByteString |
|
335 |
*/ |
|
336 |
switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) { |
|
337 |
case BYTEARRAY: |
|
338 |
break; |
|
339 |
||
340 |
case WORDARRAY: |
|
341 |
case SWORDARRAY: |
|
342 |
nindexedinstvars *= 2; |
|
343 |
break; |
|
344 |
||
345 |
case LONGARRAY: |
|
346 |
case SLONGARRAY: |
|
347 |
nindexedinstvars *= 4; |
|
348 |
break; |
|
349 |
||
350 |
default: |
|
351 |
/* don't know about this array type, delegate to super */ |
|
352 |
goto out; |
|
353 |
} |
|
354 |
} |
|
355 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
356 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars; |
|
357 |
__PROTECT_CONTEXT__ |
|
358 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
359 |
__UNPROTECT_CONTEXT__ |
|
360 |
if (newobj != nil) { |
|
361 |
__InstPtr(newobj)->o_class = self; |
|
362 |
__qSTORE(newobj, self); |
|
363 |
if (nInstVars) { |
|
364 |
/* |
|
365 |
* still have to nil out named instvars ... |
|
366 |
*/ |
|
18284 | 367 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) |
19368 | 368 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
18284 | 369 |
#else |
370 |
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES) |
|
19368 | 371 |
/* |
372 |
* knowing that nil is 0 |
|
373 |
*/ |
|
374 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
18284 | 375 |
# else |
19368 | 376 |
op = __InstPtr(newobj)->i_instvars; |
377 |
while (nInstVars--) |
|
378 |
*op++ = nil; |
|
18284 | 379 |
# endif |
380 |
#endif |
|
19368 | 381 |
} |
382 |
RETURN ( newobj ); |
|
383 |
} |
|
384 |
} |
|
18284 | 385 |
} |
386 |
out:; |
|
387 |
%}. |
|
388 |
^ self basicNew:anInteger |
|
389 |
! |
|
390 |
||
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
391 |
with:aByteArray from:start to:stop |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
392 |
"return new instance with a copy of aByteArray |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
393 |
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
|
394 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
395 |
|len bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
396 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
397 |
len := stop-start+1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
398 |
bytes := self new:len. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
399 |
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
|
400 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
401 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
402 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
403 |
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
|
404 |
" |
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
405 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
406 |
|
1 | 407 |
!UninterpretedBytes class methodsFor:'queries'! |
408 |
||
8893 | 409 |
isAbstract |
11220 | 410 |
"Return if this class is an abstract class. |
411 |
True is returned for UninterpretedBytes here; false for subclasses. |
|
19461 | 412 |
Abstract subclasses must redefine this again." |
11220 | 413 |
|
8893 | 414 |
^ self == UninterpretedBytes |
415 |
! |
|
416 |
||
1 | 417 |
isBigEndian |
77 | 418 |
"return true, if words/shorts store the most-significant |
13575 | 419 |
byte first (MSB), false if least-sign.-first (LSB). |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
420 |
I.e. false for vax, intel; true for m68k, sun. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
421 |
|
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
422 |
Notice: UninterpretedBytes isBigEndian |
19368 | 423 |
this is inlined both by stc and the jit compiler" |
1 | 424 |
|
425 |
%{ /* NOCONTEXT */ |
|
426 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
427 |
#if defined(__MSBFIRST__) |
3936 | 428 |
RETURN (true); |
429 |
#else |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
430 |
# if defined(__LSBFIRST__) |
4275 | 431 |
RETURN (false); |
432 |
# else |
|
1 | 433 |
/* |
20816 | 434 |
* I don't like ifdefs - you always forget some ... |
3433 | 435 |
* therefore we look into a structure at run-time. |
436 |
* (also, there are CPUs around [mips], where the byteorder |
|
437 |
* is programmable, and which come in different flavours) |
|
438 |
* |
|
13575 | 439 |
* NOTICE: |
440 |
* both the JIT and stc may inline this to a |
|
3433 | 441 |
* constant for systems where this is known. |
1 | 442 |
*/ |
443 |
union { |
|
19368 | 444 |
unsigned int u_l; |
445 |
char u_c[sizeof(int)]; |
|
1 | 446 |
} u; |
447 |
||
448 |
u.u_l = 0x87654321; |
|
77 | 449 |
if (u.u_c[0] == 0x21) RETURN (false); |
450 |
RETURN (true); |
|
4275 | 451 |
# endif |
3936 | 452 |
#endif |
18346 | 453 |
%}. |
454 |
^ false "/ an arbitrary default |
|
455 |
||
3433 | 456 |
" |
457 |
UninterpretedBytes isBigEndian |
|
458 |
" |
|
3209 | 459 |
! |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
460 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
461 |
isBuiltInClass |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
462 |
"return true if this class is known by the run-time-system. |
3323 | 463 |
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
|
464 |
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
|
465 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
466 |
^ self == UninterpretedBytes |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
467 |
|
3323 | 468 |
"Modified: / 23.4.1996 / 15:56:25 / cg" |
469 |
"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
|
470 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
471 |
|
20961 | 472 |
!UninterpretedBytes methodsFor:'@ OLE Extensions'! |
473 |
||
474 |
addressAtOffset: index0Based |
|
475 |
"Answer the bytes starting at index0Based (0 based offset) |
|
476 |
as anExternalAddress. Answer nil if there is no address. |
|
477 |
Notice: Offsets are zero relative." |
|
478 |
||
479 |
| address | |
|
480 |
||
481 |
address := self pointerValueAt: index0Based + 1. |
|
482 |
^ address = 0 |
|
483 |
ifTrue: [ nil ] |
|
484 |
ifFalse: [ ExternalAddress newAddress: address ] |
|
485 |
||
486 |
"Modified: / 30-03-2016 / 11:00:19 / cg" |
|
487 |
! |
|
488 |
||
489 |
addressAtOffset: index0Based put: anExternalAddress |
|
490 |
"Set the bytes starting at index0Based (0 based offset) |
|
491 |
from the contents of anExternalAddress. |
|
492 |
Notice: Offsets are zero relative." |
|
493 |
||
494 |
|anAddress | |
|
495 |
||
496 |
anAddress := anExternalAddress isNil |
|
497 |
ifTrue:[0] |
|
498 |
ifFalse:[anExternalAddress address]. |
|
499 |
self pointerAt: index0Based + 1 put: anAddress |
|
500 |
! |
|
501 |
||
502 |
addressValueAtOffset: index0Based |
|
503 |
"Answer the pointer-value starting at index0Based (0 based offset) |
|
504 |
as unsigned integer. |
|
505 |
Notice: Offsets are zero relative." |
|
506 |
||
507 |
^ self pointerValueAt: index0Based + 1. |
|
508 |
! |
|
509 |
||
510 |
addressValueAtOffset: index0Based put:anAddress |
|
511 |
"Set the pointer-value starting at index0Based (0 based offset) |
|
512 |
as unsigned integer. |
|
513 |
Notice: Offsets are zero relative." |
|
514 |
||
515 |
self pointerAt: index0Based + 1 put:anAddress. |
|
516 |
! |
|
517 |
||
518 |
byteAtOffset:index0Based |
|
519 |
"return the byte at index0Based. |
|
520 |
For ByteArray, this is the same as basicAt: |
|
521 |
however, for strings or symbols, |
|
522 |
this returns a numeric byteValue instead of a character. |
|
523 |
Notice: Offsets are zero relative." |
|
524 |
||
525 |
^ self byteAt:(index0Based + 1) |
|
526 |
! |
|
527 |
||
528 |
byteAtOffset:index0Based put:value |
|
529 |
"set the byte at index. For ByteArray, this is the same as basicAt:put:. |
|
530 |
However, for Strings, this expects a byteValue to be stored. |
|
531 |
Notice: Offsets are zero relative." |
|
532 |
||
533 |
^ self byteAt:(index0Based + 1) put:value |
|
534 |
! |
|
535 |
||
536 |
bytesAtOffset: index0Based count: count |
|
537 |
"Answer a ByteArray with count bytes copied |
|
538 |
from the receiver starting at index0Based. |
|
539 |
Notice: Offsets are zero relative." |
|
540 |
||
541 |
|newBytes | |
|
542 |
||
543 |
newBytes := ByteArray new: count. |
|
544 |
newBytes replaceBytesFrom:1 to:count with:self startingAt:(index0Based + 1). |
|
545 |
^newBytes |
|
546 |
||
547 |
" |
|
548 |
#[83 0 0 0 0 0 0 0 120 237 14 0 4 0 0 ] bytesAtOffset: 9 count: 3 |
|
549 |
" |
|
550 |
||
551 |
"Modified (comment): / 30-03-2016 / 11:24:41 / cg" |
|
552 |
! |
|
553 |
||
554 |
bytesAtOffset: index0Based put: aByteObject |
|
555 |
"Store aByteObject at anInteger in the receiver. |
|
556 |
Notice: Offsets are zero relative." |
|
557 |
||
558 |
^ self |
|
559 |
replaceBytesFrom:(index0Based + 1) to:(index0Based + aByteObject size) |
|
560 |
with:aByteObject startingAt:1. |
|
561 |
! |
|
562 |
||
563 |
fillFromAddress: anAddress |
|
564 |
"Fill the receiver by copying mySize bytes from host memory at anAddress. |
|
565 |
Warning: because anAddress might not know, how big it is, |
|
566 |
the size of the receiver must already be correct. |
|
567 |
(i.e. the receiver must have been allocated from a returned size value)" |
|
568 |
||
569 |
self |
|
570 |
replaceFrom:1 to:self size |
|
571 |
with:anAddress asExternalBytes |
|
572 |
startingAt:1 |
|
573 |
! |
|
574 |
||
575 |
longAtOffset: index0Based |
|
576 |
"same as longAt:, but with a 0-based offset. |
|
577 |
Notice: Offsets are zero relative." |
|
578 |
||
579 |
^self signedInt32At:(index0Based + 1) |
|
580 |
! |
|
581 |
||
582 |
longAtOffset: index0Based put: value |
|
583 |
"same as longAtput::, but with a 0-based offset. |
|
584 |
Notice: Offsets are zero relative." |
|
585 |
||
586 |
^self signedInt32At:index0Based +1 put:value |
|
587 |
! |
|
588 |
||
589 |
shortAtOffset: index0Based |
|
590 |
"same as shortAt:, but with a 0-based offset. |
|
591 |
Notice: Offsets are zero relative." |
|
592 |
||
593 |
^self signedInt16At: index0Based + 1 |
|
594 |
! |
|
595 |
||
596 |
shortAtOffset: index0Based put: value |
|
597 |
"same as shortAt:put:, but with a 0-based offset. |
|
598 |
Notice: Offsets are zero relative." |
|
599 |
||
600 |
^self signedInt16At: index0Based + 1 put: value |
|
601 |
! |
|
602 |
||
603 |
uLongAtOffset: index0Based |
|
604 |
"same as unsignedLongAt:, but with a 0-based offset. |
|
605 |
Notice: Offsets are zero relative." |
|
606 |
||
607 |
^ self unsignedInt32At:(index0Based + 1) |
|
608 |
! |
|
609 |
||
610 |
uLongAtOffset: index0Based put: value |
|
611 |
"same as unsignedLongAt:put:, but with a 0-based offset. |
|
612 |
Notice: Offsets are zero relative." |
|
613 |
||
614 |
^ self unsignedInt32At:(index0Based + 1) put: value |
|
615 |
! |
|
616 |
||
617 |
uShortAtOffset: index0Based |
|
618 |
"same as unsignedShortAt:, but with a 0-based offset. |
|
619 |
Notice: Offsets are zero relative." |
|
620 |
||
621 |
^ self unsignedInt16At:(index0Based + 1) |
|
622 |
! |
|
623 |
||
624 |
uShortAtOffset: index0Based put: value |
|
625 |
"same as unsignedShortAt:put:, but with a 0-based offset. |
|
626 |
Notice: Offsets are zero relative." |
|
627 |
||
628 |
^ self unsignedInt16At:(index0Based + 1) put: value |
|
629 |
! |
|
630 |
||
631 |
unsignedLongAtOffset: index0Based |
|
632 |
"same as unsignedLongAt:, but with a 0-based offset. |
|
633 |
Notice: Offsets are zero relative." |
|
634 |
||
635 |
^self unsignedInt32At: index0Based + 1 |
|
636 |
! |
|
637 |
||
638 |
unsignedLongAtOffset: index0Based put: value |
|
639 |
"same as unsignedLongAt:put:, but with a 0-based offset. |
|
640 |
Notice: Offsets are zero relative." |
|
641 |
||
642 |
^self unsignedInt32At: index0Based + 1 put: value |
|
643 |
! |
|
644 |
||
645 |
unsignedShortAtOffset: index0Based |
|
646 |
"same as unsignedShortAt:, but with a 0-based offset. |
|
647 |
Notice: Offsets are zero relative." |
|
648 |
||
649 |
^self unsignedInt16At: index0Based + 1 |
|
650 |
! |
|
651 |
||
652 |
unsignedShortAtOffset: index0Based put: value |
|
653 |
"same as unsignedShortAt:put:, but with a 0-based offset. |
|
654 |
Notice: Offsets are zero relative." |
|
655 |
||
656 |
^self unsignedInt16At:(index0Based + 1) put: value |
|
657 |
! ! |
|
658 |
||
19349 | 659 |
!UninterpretedBytes methodsFor:'Compatibility'! |
660 |
||
661 |
doubleWordAt:index |
|
662 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
663 |
The index is a smalltalk index (i.e. 1-based). |
|
664 |
The value is retrieved in the machines natural byte order." |
|
665 |
||
666 |
^ self unsignedInt32At:index MSB:IsBigEndian |
|
667 |
||
668 |
" |
|
669 |
|b| |
|
670 |
||
671 |
b := ByteArray withAll:#(1 2 3 4). |
|
672 |
(b doubleWordAt:1) printStringRadix:16 |
|
673 |
" |
|
674 |
||
675 |
"Modified: / 5.3.1998 / 14:57:35 / stefan" |
|
676 |
! |
|
677 |
||
678 |
doubleWordAt:index MSB:msb |
|
679 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
680 |
The index is a smalltalk index (i.e. 1-based). |
|
681 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
682 |
LSB-first otherwise." |
|
683 |
||
684 |
^ self unsignedInt32At:index MSB:msb |
|
685 |
||
686 |
" |
|
687 |
|b| |
|
688 |
||
689 |
b := ByteArray withAll:#(1 2 3 4). |
|
690 |
(b doubleWordAt:1 MSB:true) printStringRadix:16. |
|
691 |
(b doubleWordAt:1 MSB:false) printStringRadix:16 |
|
692 |
" |
|
693 |
! |
|
694 |
||
695 |
doubleWordAt:byteIndex put:anInteger |
|
696 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
697 |
The index is a smalltalk index (i.e. 1-based). |
|
698 |
The value should be in the range 0 to 16rFFFFFFFF |
|
699 |
(for negative values, the stored value is not defined). |
|
700 |
The value is stored in the machines natural byte order." |
|
701 |
||
702 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:IsBigEndian |
|
703 |
||
704 |
" |
|
705 |
|b| |
|
706 |
b := ByteArray new:4. |
|
707 |
b doubleWordAt:1 put:16r04030201. |
|
708 |
b inspect |
|
709 |
" |
|
710 |
||
711 |
"Modified: / 5.3.1998 / 14:57:48 / stefan" |
|
712 |
! |
|
713 |
||
714 |
doubleWordAt:byteIndex put:anInteger MSB:msb |
|
715 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
716 |
The index is a smalltalk index (i.e. 1-based). |
|
717 |
The value must be in the range 0 to 16rFFFFFFFF. |
|
718 |
The value is stored MSB-first if msb is true; LSB-first otherwise." |
|
719 |
||
720 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:msb |
|
721 |
||
722 |
" |
|
723 |
|b| |
|
724 |
b := ByteArray new:8. |
|
725 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
|
726 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
727 |
b inspect |
|
728 |
" |
|
729 |
||
730 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
731 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
|
732 |
! |
|
733 |
||
734 |
doubleWordAtDoubleWordIndex:int32Index |
|
735 |
"return the unsigned long (int32) at index, anInteger. |
|
736 |
Fetching in the machine's natural byte order. |
|
737 |
Indices are 1-based and scaled as appropriate to allow |
|
738 |
accessing the memory as an array of doubleWord entries. |
|
739 |
(i.e. indices are 1, 2, ...)" |
|
740 |
||
741 |
^ self doubleWordAtDoubleWordIndex:int32Index MSB:IsBigEndian |
|
742 |
||
743 |
"Created: / 21.1.1998 / 17:43:53 / cg" |
|
744 |
"Modified: / 5.3.1998 / 14:58:06 / stefan" |
|
745 |
! |
|
746 |
||
747 |
doubleWordAtDoubleWordIndex:int32Index MSB:msb |
|
748 |
"return the unsigned long (int32) at index, anInteger. |
|
749 |
Fetching is MSB if msb is true, LSB otherwise. |
|
750 |
Indices are 1-based and scaled as appropriate to allow |
|
751 |
accessing the memory as an array of doubleWord entries. |
|
752 |
(i.e. indices are 1, 2, ...)" |
|
753 |
||
754 |
^ self unsignedInt32At:((int32Index - 1) * 4 + 1) MSB:msb |
|
755 |
||
756 |
"Created: / 21.1.1998 / 17:44:07 / cg" |
|
757 |
! |
|
758 |
||
759 |
doubleWordAtDoubleWordIndex:int32Index put:anInteger |
|
760 |
"set the long at index, anInteger. |
|
761 |
Storing in the machines natural byte order. |
|
762 |
Indices are 1-based and scaled as appropriate to allow |
|
763 |
accessing the memory as an array of doubleWord entries. |
|
764 |
(i.e. indices are 1, 2, ...)" |
|
765 |
||
766 |
^ self doubleWordAtDoubleWordIndex:int32Index put:anInteger MSB:IsBigEndian |
|
767 |
||
768 |
"Created: / 21.1.1998 / 17:44:13 / cg" |
|
769 |
"Modified: / 5.3.1998 / 14:58:19 / stefan" |
|
770 |
! |
|
771 |
||
772 |
doubleWordAtDoubleWordIndex:int32Index put:anInteger MSB:msb |
|
773 |
"set the long at index, anInteger. |
|
774 |
Storing is MSB if msb is true, LSB otherwise. |
|
775 |
Indices are 1-based and scaled as appropriate to allow |
|
776 |
accessing the memory as an array of doubleWord entries. |
|
777 |
(i.e. indices are 1, 2, ...)" |
|
778 |
||
779 |
^ self unsignedInt32At:((int32Index - 1) * 4 + 1) put:anInteger MSB:msb |
|
780 |
||
781 |
"Created: / 21.1.1998 / 17:44:19 / cg" |
|
782 |
! |
|
783 |
||
784 |
int16At:byteIndex |
|
785 |
"return the 2-bytes starting at index as a signed Integer. |
|
786 |
The index is a smalltalk index (i.e. 1-based). |
|
787 |
The value is retrieved in the machines natural byte order. |
|
788 |
This may be worth a primitive." |
|
789 |
||
790 |
^ self signedInt16At:byteIndex |
|
791 |
||
792 |
" |
|
793 |
|b| |
|
794 |
b := ByteArray new:2. |
|
795 |
b wordAt:1 put:16rFFFF. |
|
796 |
b signedWordAt:1 |
|
797 |
" |
|
798 |
||
799 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
800 |
! |
|
801 |
||
802 |
int16At:byteIndex MSB:msb |
|
803 |
"return the 2-bytes starting at index as a signed Integer. |
|
804 |
The index is a smalltalk index (i.e. 1-based). |
|
805 |
The value is retrieved in the machines natural byte order. |
|
806 |
This may be worth a primitive." |
|
807 |
||
808 |
^ self signedInt16At:byteIndex MSB:msb |
|
809 |
||
810 |
" |
|
811 |
|b| |
|
812 |
b := ByteArray new:2. |
|
813 |
b wordAt:1 put:16rFFFF. |
|
814 |
b signedWordAt:1 |
|
815 |
" |
|
816 |
||
817 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
818 |
! |
|
819 |
||
820 |
int16At:index put:anInteger |
|
821 |
"set the 2-bytes starting at index from the signed Integer value. |
|
822 |
The index is a smalltalk index (i.e. 1-based). |
|
823 |
The stored value must be in the range -32768 .. +32676. |
|
824 |
The value is stored in the machine's natural byteorder" |
|
825 |
||
826 |
^ self signedInt16At:index put:anInteger MSB:IsBigEndian |
|
827 |
||
828 |
" |
|
829 |
|b| |
|
830 |
b := ByteArray new:4. |
|
831 |
b shortAt:1 put:1 bigEndian:true. |
|
832 |
b shortAt:3 put:1 bigEndian:false. |
|
833 |
b inspect |
|
834 |
" |
|
835 |
||
836 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
837 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
838 |
! |
|
839 |
||
840 |
int16At:index put:anInteger MSB:bigEndian |
|
841 |
"set the 2-bytes starting at index from the signed Integer value. |
|
842 |
The index is a smalltalk index (i.e. 1-based). |
|
843 |
The stored value must be in the range -32768 .. +32676. |
|
844 |
The value is stored in the byteorder given by bigEndian. |
|
845 |
This may be worth a primitive." |
|
846 |
||
847 |
||
848 |
^ self signedInt16At:index put:anInteger MSB:bigEndian |
|
849 |
||
850 |
" |
|
851 |
|b| |
|
852 |
b := ByteArray new:4. |
|
853 |
b shortAt:1 put:1 bigEndian:true. |
|
854 |
b shortAt:3 put:1 bigEndian:false. |
|
855 |
b inspect |
|
856 |
" |
|
857 |
||
858 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
859 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
860 |
! |
|
861 |
||
862 |
longAt:index |
|
863 |
"return the 4-bytes starting at index as a signed Integer. |
|
864 |
The index is a smalltalk index (i.e. 1-based). |
|
865 |
The value is retrieved in the machines natural byte order, |
|
866 |
therefore, this should only be used for byte-data which is |
|
867 |
only used inside this machine. |
|
868 |
To setup data packets which are to be sent to other machines, |
|
869 |
or stored into a file, always use longAt:MSB: and specify |
|
870 |
a definite byteOrder." |
|
871 |
||
872 |
^ self signedInt32At:index |
|
873 |
||
874 |
" |
|
875 |
|b| |
|
876 |
b := ByteArray new:4. |
|
877 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
878 |
(b longAt:1) |
|
879 |
" |
|
880 |
||
881 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
882 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
883 |
! |
|
884 |
||
885 |
longAt:index bigEndian:msb |
|
886 |
"return the 4-bytes starting at index as a signed Integer. |
|
887 |
The index is a smalltalk index (i.e. 1-based). |
|
888 |
Depending on msb, the value is retrieved MSB-first or LSB-first. |
|
889 |
This may be worth a primitive." |
|
890 |
||
891 |
^ self signedInt32At:index MSB:msb |
|
892 |
||
893 |
" |
|
894 |
|b| |
|
895 |
b := ByteArray new:4. |
|
896 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
897 |
(b longAt:1) |
|
898 |
" |
|
899 |
||
900 |
"Modified: / 1.7.1996 / 21:11:33 / cg" |
|
901 |
"Created: / 5.3.1998 / 14:02:03 / stefan" |
|
902 |
! |
|
903 |
||
904 |
longAt:index put:value |
|
905 |
"set the 4-bytes starting at index from the signed Integer value. |
|
906 |
The index is a smalltalk index (i.e. 1-based). |
|
907 |
The value is stored in the machine's natural byte order." |
|
908 |
||
909 |
^ self signedInt32At:index put:value MSB:IsBigEndian |
|
910 |
||
911 |
" |
|
912 |
|b| |
|
913 |
b := ByteArray new:4. |
|
914 |
b longAt:1 put:-1. |
|
915 |
(b unsignedLongAt:1) printStringRadix:16 |
|
916 |
" |
|
917 |
||
918 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
|
919 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
920 |
! |
|
921 |
||
922 |
longAt:byteIndex put:anInteger bigEndian:msb |
|
923 |
"store a signed long (32bit) integer. |
|
924 |
The index is a smalltalk index (i.e. 1-based)." |
|
925 |
||
926 |
^ self signedInt32At:byteIndex put:anInteger MSB:msb |
|
927 |
||
928 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
929 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
930 |
! |
|
931 |
||
932 |
longLongAt:index |
|
933 |
"return the 8-bytes starting at index as a signed Integer. |
|
934 |
The index is a smalltalk index (i.e. 1-based). |
|
20961 | 935 |
The value is retrieved in the machineÄs natural byte order. |
19349 | 936 |
This may be worth a primitive." |
937 |
||
938 |
^ self signedInt64At:index MSB:IsBigEndian |
|
939 |
||
940 |
" |
|
941 |
|b| |
|
942 |
b := ByteArray new:4. |
|
943 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
944 |
(b longLongAt:1) |
|
945 |
" |
|
946 |
||
947 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
948 |
"Created: / 5.3.1998 / 14:40:05 / stefan" |
|
949 |
"Modified: / 5.3.1998 / 14:58:32 / stefan" |
|
950 |
! |
|
951 |
||
952 |
longLongAt:index bigEndian:msb |
|
953 |
"return the 8-bytes starting at index as a signed Integer. |
|
954 |
The index is a smalltalk index (i.e. 1-based). |
|
955 |
The value is retrieved in the given byte order. |
|
956 |
This may be worth a primitive." |
|
957 |
||
958 |
^ self signedInt64At:index MSB:msb |
|
959 |
||
960 |
" |
|
961 |
|b| |
|
962 |
b := ByteArray new:4. |
|
963 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
964 |
(b longLongAt:1 msb:true) |
|
965 |
" |
|
966 |
||
967 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
968 |
"Created: / 5.3.1998 / 14:40:54 / stefan" |
|
969 |
"Modified: / 9.5.1998 / 01:10:59 / cg" |
|
970 |
! |
|
971 |
||
972 |
longLongAt:byteIndex put:anInteger |
|
973 |
"store a signed longLong (64bit) integer. |
|
974 |
The index is a smalltalk index (i.e. 1-based). |
|
975 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
976 |
||
977 |
^ self signedInt64At:byteIndex put:anInteger MSB:IsBigEndian |
|
978 |
! |
|
979 |
||
980 |
longLongAt:byteIndex put:anInteger bigEndian:msb |
|
981 |
"store a signed longLong (64bit) integer. |
|
982 |
The index is a smalltalk index (i.e. 1-based). |
|
983 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
984 |
||
985 |
^ self signedInt64At:byteIndex put:anInteger MSB:msb |
|
986 |
||
987 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
988 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
989 |
! |
|
990 |
||
991 |
quadWordAt:index MSB:msb |
|
992 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
993 |
The index is a smalltalk index (i.e. 1-based). |
|
994 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
995 |
||
996 |
^ self unsignedInt64At:index MSB:msb |
|
997 |
||
998 |
" |
|
999 |
|b| |
|
1000 |
||
1001 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
1002 |
(b quadWordAt:1 MSB:false) printStringRadix:16 |
|
1003 |
" |
|
1004 |
||
1005 |
"Modified: 5.11.1996 / 14:06:21 / cg" |
|
1006 |
! |
|
1007 |
||
1008 |
quadWordAt:index put:anInteger MSB:msb |
|
1009 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1010 |
The index is a smalltalk index (i.e. 1-based). |
|
1011 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1012 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
1013 |
||
1014 |
^ self unsignedInt64At:index put:anInteger MSB:msb |
|
1015 |
||
1016 |
" |
|
1017 |
|b| |
|
1018 |
b := ByteArray new:8. |
|
1019 |
b quadWordAtIndex:1 put:16r0807060504030201 MSB:false. |
|
1020 |
b inspect |
|
1021 |
" |
|
1022 |
! |
|
1023 |
||
1024 |
shortAt:index |
|
1025 |
"return the 2-bytes starting at index as a signed Integer. |
|
1026 |
The index is a smalltalk index (i.e. 1-based). |
|
1027 |
The value is retrieved in the machines natural byte order. |
|
1028 |
This may be worth a primitive. |
|
1029 |
This is the ST80 equivalent of #signedWordAt:" |
|
1030 |
||
19368 | 1031 |
^ self signedInt16At:index MSB:IsBigEndian |
19349 | 1032 |
|
1033 |
" |
|
1034 |
|b| |
|
1035 |
b := ByteArray new:2. |
|
1036 |
b unsignedShortAt:1 put:16rFFFF. |
|
1037 |
b shortAt:1 |
|
1038 |
" |
|
1039 |
||
1040 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
|
1041 |
"Created: / 5.3.1998 / 10:59:57 / stefan" |
|
1042 |
"Modified: / 5.3.1998 / 23:39:38 / stefan" |
|
1043 |
! |
|
1044 |
||
1045 |
shortAt:index bigEndian:msb |
|
1046 |
"return the 2-bytes starting at index as a signed Integer. |
|
1047 |
The index is a smalltalk index (i.e. 1-based). |
|
1048 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
1049 |
LSB-first otherwise. |
|
1050 |
This is the ST80 equivalent of #signedWordAt:" |
|
1051 |
||
19368 | 1052 |
^ self signedInt16At:index MSB:msb |
19349 | 1053 |
|
1054 |
" |
|
1055 |
|b| |
|
1056 |
b := ByteArray new:2. |
|
1057 |
b unsignedShortAt:1 put:16rFFFF. |
|
1058 |
b shortAt:1 |
|
1059 |
" |
|
1060 |
||
1061 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
|
1062 |
"Created: / 5.3.1998 / 23:41:21 / stefan" |
|
1063 |
! |
|
1064 |
||
1065 |
shortAt:index put:value |
|
1066 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1067 |
The index is a smalltalk index (i.e. 1-based). |
|
1068 |
The stored value must be in the range -32768 .. +32676. |
|
1069 |
The value is stored in the machines natural byteorder. |
|
1070 |
This may be worth a primitive. |
|
1071 |
This is the ST80 equivalent of #signedWordAt:put:" |
|
1072 |
||
1073 |
^ self signedInt16At:index put:value MSB:IsBigEndian |
|
1074 |
||
1075 |
" |
|
1076 |
|b| |
|
1077 |
b := ByteArray new:6. |
|
1078 |
b shortAt:1 put:-1. |
|
1079 |
b shortAt:3 put:-2. |
|
1080 |
b shortAt:5 put:0. |
|
1081 |
b inspect |
|
1082 |
" |
|
1083 |
||
1084 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1085 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
1086 |
! |
|
1087 |
||
1088 |
shortAt:index put:value bigEndian:bigEndian |
|
1089 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1090 |
The index is a smalltalk index (i.e. 1-based). |
|
1091 |
The stored value must be in the range -32768 .. +32676. |
|
1092 |
The value is stored in the byteorder given by bigEndian. |
|
1093 |
This may be worth a primitive." |
|
1094 |
||
1095 |
^ self signedInt16At:index put:value MSB:IsBigEndian |
|
1096 |
||
1097 |
" |
|
1098 |
|b| |
|
1099 |
b := ByteArray new:4. |
|
1100 |
b shortAt:1 put:1 bigEndian:true. |
|
1101 |
b shortAt:3 put:1 bigEndian:false. |
|
1102 |
b inspect |
|
1103 |
" |
|
1104 |
||
1105 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1106 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
1107 |
! |
|
1108 |
||
1109 |
signedDoubleWordAt:index |
|
1110 |
"return the 4-bytes starting at index as a signed Integer. |
|
1111 |
The index is a smalltalk index (i.e. 1-based). |
|
1112 |
The value is retrieved in the machines natural byte order. |
|
1113 |
This may be worth a primitive." |
|
1114 |
||
1115 |
^ self signedInt32At:index MSB:IsBigEndian |
|
1116 |
||
1117 |
" |
|
1118 |
|b| |
|
1119 |
b := ByteArray new:4. |
|
1120 |
b doubleWordAt:1 put:16rFFFFFFFF. |
|
1121 |
(b signedDoubleWordAt:1) |
|
1122 |
" |
|
1123 |
" |
|
1124 |
|b| |
|
1125 |
b := ByteArray new:4. |
|
1126 |
b signedDoubleWordAt:1 put:-1. |
|
1127 |
(b doubleWordAt:1) |
|
1128 |
" |
|
1129 |
||
1130 |
"Modified: 1.7.1996 / 21:11:28 / cg" |
|
1131 |
! |
|
1132 |
||
1133 |
signedDoubleWordAt:index MSB:msb |
|
1134 |
"return the 4-bytes starting at index as a (signed) Integer. |
|
1135 |
The index is a smalltalk index (i.e. 1-based). |
|
1136 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
1137 |
LSB-first otherwise." |
|
1138 |
||
1139 |
^ self signedInt32At:index MSB:msb |
|
1140 |
||
1141 |
" |
|
1142 |
|b| |
|
1143 |
||
1144 |
b := ByteArray withAll:#(1 2 3 4). |
|
1145 |
(b signedDoubleWordAt:1 MSB:true) printStringRadix:16. |
|
1146 |
(b signedDoubleWordAt:1 MSB:false) printStringRadix:16 |
|
1147 |
" |
|
1148 |
! |
|
1149 |
||
1150 |
signedDoubleWordAt:index put:value |
|
1151 |
"set the 4-bytes starting at index from the signed Integer value. |
|
1152 |
The index is a smalltalk index (i.e. 1-based). |
|
1153 |
The value is stored in the machines natural byte order. |
|
1154 |
This may be worth a primitive." |
|
1155 |
||
1156 |
^ self signedInt32At:index put:value MSB:IsBigEndian |
|
1157 |
||
1158 |
" |
|
1159 |
|b| |
|
1160 |
b := ByteArray new:4. |
|
1161 |
b signedDoubleWordAt:1 put:-1. |
|
1162 |
(b doubleWordAt:1) printStringRadix:16 |
|
1163 |
" |
|
1164 |
||
1165 |
"Modified: 1.7.1996 / 21:11:39 / cg" |
|
1166 |
! |
|
1167 |
||
1168 |
signedDoubleWordAt:index put:value MSB:msb |
|
1169 |
"set the 4-bytes starting at index from the signed Integer value. |
|
1170 |
The index is a smalltalk index (i.e. 1-based). |
|
1171 |
Depending on msb, the value is stored MSB-first or LSB-first. |
|
1172 |
This may be worth a primitive." |
|
1173 |
||
1174 |
^ self signedInt32At:index put:value MSB:msb |
|
1175 |
||
1176 |
" |
|
1177 |
|b| |
|
1178 |
b := ByteArray new:4. |
|
1179 |
b signedDoubleWordAt:1 put:-1. |
|
1180 |
(b doubleWordAt:1) printStringRadix:16 |
|
1181 |
" |
|
1182 |
||
1183 |
"Modified: 1.7.1996 / 21:11:46 / cg" |
|
15087 | 1184 |
! |
1185 |
||
1186 |
signedLongAt:index |
|
1187 |
"return the 4-bytes starting at index as a signed Integer. |
|
1188 |
The index is a smalltalk index (i.e. 1-based). |
|
19415 | 1189 |
The value is retrieved in the machine's natural byte order." |
1190 |
||
1191 |
^ self signedInt32At:index |
|
15087 | 1192 |
|
1193 |
" |
|
1194 |
|b| |
|
1195 |
b := ByteArray new:4. |
|
1196 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
1197 |
b signedLongAt:1 |
|
1198 |
" |
|
1199 |
||
1200 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
1201 |
! |
|
1202 |
||
1203 |
signedLongAt:index put:newValue |
|
19415 | 1204 |
"store a 4-bytes signed value starting at index. |
15087 | 1205 |
The index is a smalltalk index (i.e. 1-based). |
19415 | 1206 |
The value is in the machine's natural byte order." |
1207 |
||
1208 |
^ self signedInt32At:index put:newValue |
|
15087 | 1209 |
|
1210 |
" |
|
1211 |
|b| |
|
1212 |
b := ByteArray new:4. |
|
1213 |
b signedLongAt:1 put:-1. |
|
1214 |
b unsignedLongAt:1 |
|
1215 |
" |
|
1216 |
||
1217 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
19349 | 1218 |
! |
1219 |
||
1220 |
signedWordAt:index |
|
1221 |
"return the 2-bytes starting at index as a signed Integer. |
|
1222 |
The index is a smalltalk index (i.e. 1-based). |
|
1223 |
The value is retrieved in the machines natural byte order. |
|
1224 |
This may be worth a primitive." |
|
1225 |
||
1226 |
^ (self unsignedInt16At:index MSB:IsBigEndian) signExtendedShortValue |
|
1227 |
||
1228 |
" |
|
1229 |
|b| |
|
1230 |
b := ByteArray new:2. |
|
1231 |
b wordAt:1 put:16rFFFF. |
|
1232 |
b signedWordAt:1 |
|
1233 |
" |
|
1234 |
||
1235 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
1236 |
! |
|
1237 |
||
1238 |
signedWordAt:index MSB:msb |
|
1239 |
"return the 2-bytes starting at index as a signed Integer. |
|
1240 |
The index is a smalltalk index (i.e. 1-based). |
|
1241 |
The value is retrieved MSB-first if the msb-arg is true, |
|
1242 |
LSB-first otherwise. |
|
1243 |
This may be worth a primitive." |
|
1244 |
||
1245 |
^ (self unsignedInt16At:index MSB:msb) signExtendedShortValue |
|
1246 |
||
1247 |
" |
|
1248 |
|b| |
|
1249 |
b := ByteArray new:2. |
|
1250 |
b wordAt:1 put:16r0080. |
|
1251 |
b signedWordAt:1 MSB:true. |
|
1252 |
b signedWordAt:1 MSB:false. |
|
1253 |
" |
|
1254 |
||
1255 |
"Modified: 1.7.1996 / 21:15:57 / cg" |
|
1256 |
! |
|
1257 |
||
1258 |
signedWordAt:byteIndex put:anInteger |
|
1259 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1260 |
The index is a smalltalk index (i.e. 1-based). |
|
1261 |
The stored value must be in the range -32768 .. +32676. |
|
1262 |
The value is stored in the machine's natural byteorder." |
|
1263 |
||
1264 |
^ self signedInt16At:byteIndex put:anInteger MSB:IsBigEndian |
|
1265 |
||
1266 |
" |
|
1267 |
|b| |
|
1268 |
b := ByteArray new:6. |
|
1269 |
b shortAt:1 put:-1. |
|
1270 |
b shortAt:3 put:-2. |
|
1271 |
b shortAt:5 put:0. |
|
1272 |
b inspect |
|
1273 |
" |
|
1274 |
||
1275 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1276 |
"Modified: / 5.3.1998 / 11:01:30 / stefan" |
|
1277 |
! |
|
1278 |
||
1279 |
signedWordAt:byteIndex put:anInteger MSB:msb |
|
1280 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1281 |
The index is a smalltalk index (i.e. 1-based). |
|
1282 |
The stored value must be in the range -32768 .. +32676. |
|
1283 |
The value is stored MSB-first, if the msb-arg is true; |
|
1284 |
LSB-first otherwise." |
|
1285 |
||
19415 | 1286 |
^ self signedInt16At:byteIndex put:anInteger MSB:msb |
19349 | 1287 |
|
1288 |
" |
|
1289 |
|b| |
|
1290 |
b := ByteArray new:4. |
|
1291 |
b signedWordAt:1 put:-1. |
|
1292 |
b signedWordAt:3 put:-2. |
|
1293 |
b inspect |
|
1294 |
" |
|
1295 |
||
1296 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
1297 |
! |
|
1298 |
||
1299 |
unsignedLongAt:index |
|
1300 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1301 |
The index is a smalltalk index (i.e. 1-based). |
|
1302 |
The value is retrieved in the machine's natural byte order. |
|
1303 |
Subclasses may redefine this for better performance. |
|
1304 |
Same as doubleWordAt: for protocol completeness" |
|
1305 |
||
1306 |
^ self unsignedInt32At:index MSB:IsBigEndian |
|
1307 |
||
1308 |
" |
|
1309 |
|b| |
|
1310 |
||
1311 |
b := ByteArray withAll:#(1 2 3 4). |
|
1312 |
(b unsignedLongAt:1) printStringRadix:16 |
|
1313 |
" |
|
1314 |
||
1315 |
"Created: / 5.3.1998 / 11:56:53 / stefan" |
|
1316 |
"Modified: / 5.3.1998 / 14:58:48 / stefan" |
|
1317 |
! |
|
1318 |
||
1319 |
unsignedLongAt:index bigEndian:msb |
|
1320 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1321 |
The index is a smalltalk index (i.e. 1-based). |
|
1322 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
1323 |
LSB-first otherwise. |
|
1324 |
Subclasses may redefine this for better performance. |
|
1325 |
Same as doubleWordAt:MSB: for protocol completeness" |
|
1326 |
||
1327 |
^ self unsignedInt32At:index MSB:msb |
|
1328 |
||
1329 |
" |
|
1330 |
|b| |
|
1331 |
||
1332 |
b := ByteArray withAll:#(1 2 3 4). |
|
1333 |
(b unsignedLongAt:1 bigEndian:true) printStringRadix:16. |
|
1334 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1335 |
" |
|
1336 |
||
1337 |
"Modified: / 21.1.1998 / 17:42:30 / cg" |
|
1338 |
"Created: / 5.3.1998 / 11:46:05 / stefan" |
|
1339 |
! |
|
1340 |
||
1341 |
unsignedLongAt:index put:value |
|
1342 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1343 |
The index is a smalltalk index (i.e. 1-based). |
|
1344 |
The value should be in the range 0 to 16rFFFFFFFF |
|
1345 |
(for negative values, the stored value is not defined). |
|
1346 |
The value is stored in the machines natural byte order. |
|
1347 |
Subclasses may redefine this for better performance. |
|
1348 |
Same as doubleWordAt:put: for protocol completeness" |
|
1349 |
||
1350 |
^ self unsignedInt32At:index put:value MSB:IsBigEndian |
|
1351 |
||
1352 |
" |
|
1353 |
|b| |
|
1354 |
b := ByteArray new:4. |
|
1355 |
b unsignedLongAt:1 put:16r04030201. |
|
1356 |
b inspect |
|
1357 |
" |
|
1358 |
||
1359 |
"Created: / 5.3.1998 / 11:57:44 / stefan" |
|
1360 |
"Modified: / 5.3.1998 / 14:58:59 / stefan" |
|
1361 |
! |
|
1362 |
||
1363 |
unsignedLongAt:index put:aNumber bigEndian:msb |
|
1364 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1365 |
The index is a smalltalk index (i.e. 1-based). |
|
1366 |
The value must be in the range 0 to 16rFFFFFFFF. |
|
1367 |
The value is stored MSB-first if msb is true; LSB-first otherwise. |
|
1368 |
Subclasses may redefine this for better performance. |
|
1369 |
Same as doubleWordAt:put:MSB: for protocol completeness" |
|
1370 |
||
1371 |
^ self unsignedInt32At:index put:aNumber MSB:msb |
|
1372 |
||
1373 |
" |
|
1374 |
|b| |
|
1375 |
b := ByteArray new:8. |
|
1376 |
b unsignedLongAt:1 put:16r04030201 bigEndian:true. |
|
1377 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1378 |
" |
|
1379 |
||
1380 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
1381 |
"Created: / 5.3.1998 / 11:43:53 / stefan" |
|
1382 |
"Modified: / 5.3.1998 / 11:47:30 / stefan" |
|
1383 |
! |
|
1384 |
||
1385 |
unsignedLongLongAt:index bigEndian:msb |
|
1386 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
1387 |
The index is a smalltalk index (i.e. 1-based). |
|
1388 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
1389 |
||
1390 |
^ self unsignedInt64At:index MSB:msb |
|
1391 |
||
1392 |
" |
|
1393 |
|b| |
|
1394 |
||
1395 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
1396 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
|
1397 |
" |
|
1398 |
||
1399 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
1400 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
1401 |
! |
|
1402 |
||
1403 |
unsignedLongLongAt:index put:anInteger |
|
1404 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1405 |
The index is a smalltalk index (i.e. 1-based). |
|
1406 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1407 |
The value is stored in natural byte order." |
|
1408 |
||
1409 |
^ self unsignedInt64At:index put:anInteger MSB:IsBigEndian |
|
1410 |
||
1411 |
"Created: / 5.3.1998 / 14:44:00 / stefan" |
|
1412 |
"Modified: / 5.3.1998 / 15:02:32 / stefan" |
|
1413 |
! |
|
1414 |
||
1415 |
unsignedLongLongAt:index put:anInteger bigEndian:msb |
|
1416 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1417 |
The index is a smalltalk index (i.e. 1-based). |
|
1418 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1419 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
1420 |
||
1421 |
^ self unsignedInt64At:index put:anInteger MSB:msb |
|
1422 |
||
1423 |
" |
|
1424 |
|b| |
|
1425 |
b := ByteArray new:8. |
|
1426 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
1427 |
b inspect |
|
1428 |
" |
|
1429 |
||
1430 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
1431 |
! |
|
1432 |
||
1433 |
unsignedShortAt:index |
|
1434 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1435 |
The index is a smalltalk index (i.e. 1-based). |
|
1436 |
The value is retrieved in the machines natural byte order |
|
1437 |
Subclasses may redefine this for better performance. |
|
1438 |
This is the ST80 equivalent of #wordAt:" |
|
1439 |
||
1440 |
||
1441 |
^ self unsignedInt16At:index MSB:IsBigEndian |
|
1442 |
||
1443 |
"Created: / 5.3.1998 / 11:38:25 / stefan" |
|
1444 |
"Modified: / 5.3.1998 / 14:59:25 / stefan" |
|
1445 |
! |
|
1446 |
||
1447 |
unsignedShortAt:index bigEndian:msb |
|
1448 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1449 |
The index is a smalltalk index (i.e. 1-based). |
|
1450 |
The value is retrieved MSB-first (high 8 bits at lower index) if msb is true; |
|
1451 |
LSB-first (i.e. low 8-bits at lower byte index) if its false)" |
|
1452 |
||
1453 |
^ self unsignedInt16At:index MSB:msb |
|
1454 |
||
1455 |
"Modified: / 21.1.1998 / 17:46:07 / cg" |
|
1456 |
"Created: / 5.3.1998 / 11:49:29 / stefan" |
|
1457 |
! |
|
1458 |
||
1459 |
unsignedShortAt:index put:value |
|
1460 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1461 |
The index is a smalltalk index (i.e. 1-based). |
|
1462 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1463 |
The value is stored in the machines natural byteorder." |
|
1464 |
||
1465 |
^ self unsignedInt16At:index put:value |
|
1466 |
||
1467 |
" |
|
1468 |
|b| |
|
1469 |
b := ByteArray new:4. |
|
1470 |
b unsignedShortAt:1 put:16r0102. |
|
1471 |
b unsignedShortAt:3 put:16r0304. |
|
1472 |
b inspect |
|
1473 |
" |
|
1474 |
||
1475 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
1476 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
1477 |
! |
|
1478 |
||
1479 |
unsignedShortAt:index put:value bigEndian:msb |
|
1480 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1481 |
The index is a smalltalk index (i.e. 1-based). |
|
1482 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1483 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
|
1484 |
lower index) if msb is false, MSB-first otherwise" |
|
1485 |
||
1486 |
^ self unsignedInt16At:index put:value MSB:msb |
|
1487 |
||
1488 |
" |
|
1489 |
|b| |
|
1490 |
b := ByteArray new:8. |
|
1491 |
b unsignedShortAt:1 put:16r0102 bigEndian:false. |
|
1492 |
b unsignedShortAt:3 put:16r0304 bigEndian:false. |
|
1493 |
b unsignedShortAt:5 put:16r0102 bigEndian:true. |
|
1494 |
b unsignedShortAt:7 put:16r0304 bigEndian:true. |
|
1495 |
b inspect |
|
1496 |
" |
|
1497 |
||
1498 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
1499 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
1500 |
! |
|
1501 |
||
1502 |
wordAt:index |
|
1503 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1504 |
The index is a smalltalk index (i.e. 1-based). |
|
1505 |
The value is retrieved in the machines natural byte order |
|
1506 |
Subclasses may redefine this for better performance." |
|
1507 |
||
1508 |
^ self unsignedInt16At:index MSB:IsBigEndian |
|
1509 |
||
1510 |
"Modified: / 5.3.1998 / 14:59:51 / stefan" |
|
1511 |
! |
|
1512 |
||
1513 |
wordAt:index MSB:msb |
|
1514 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1515 |
The index is a smalltalk index (i.e. 1-based). |
|
1516 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
|
1517 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
|
1518 |
Notice: |
|
1519 |
the index is a byte index; thus, this allows for unaligned access to |
|
1520 |
words on any boundary. |
|
1521 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)" |
|
1522 |
||
1523 |
^ self unsignedInt16At:index MSB:msb |
|
1524 |
! |
|
1525 |
||
1526 |
wordAt:index put:value |
|
1527 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1528 |
The index is a smalltalk index (i.e. 1-based). |
|
1529 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1530 |
The value is stored in the machines natural byteorder. |
|
1531 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
|
1532 |
||
1533 |
^ self unsignedInt16At:index put:value MSB:IsBigEndian |
|
1534 |
||
1535 |
" |
|
1536 |
|b| |
|
1537 |
b := ByteArray new:4. |
|
1538 |
b wordAt:1 put:16r0102. |
|
1539 |
b wordAt:3 put:16r0304. |
|
1540 |
b inspect |
|
1541 |
" |
|
1542 |
||
1543 |
"Modified: / 5.3.1998 / 15:00:03 / stefan" |
|
1544 |
! |
|
1545 |
||
1546 |
wordAt:index put:value MSB:msb |
|
1547 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1548 |
The index is a smalltalk index (i.e. 1-based). |
|
1549 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1550 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
|
1551 |
lower index) if msb is false, MSB-first otherwise. |
|
1552 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
|
1553 |
||
1554 |
^ self unsignedInt16At:index put:value MSB:msb |
|
1555 |
||
1556 |
" |
|
1557 |
b := ByteArray new:8. |
|
1558 |
b wordAt:1 put:16r0102 MSB:false. |
|
1559 |
b wordAt:3 put:16r0304 MSB:false. |
|
1560 |
b wordAt:5 put:16r0102 MSB:true. |
|
1561 |
b wordAt:7 put:16r0304 MSB:true. |
|
1562 |
b inspect |
|
1563 |
" |
|
1564 |
||
1565 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
1566 |
! |
|
1567 |
||
1568 |
wordAtWordIndex:int16Index |
|
1569 |
"return the unsigned short (uint16) at index, anInteger. |
|
1570 |
Fetching in the machines natural byte order. |
|
1571 |
Indices are 1-based and scaled as appropriate to allow |
|
1572 |
accessing the memory as an array of word entries. |
|
1573 |
(i.e. indices are 1, 2, ...)" |
|
1574 |
||
1575 |
^ self unsignedInt16At:int16Index MSB:IsBigEndian |
|
1576 |
||
1577 |
"Created: / 21.1.1998 / 17:48:26 / cg" |
|
1578 |
"Modified: / 5.3.1998 / 15:00:16 / stefan" |
|
1579 |
! |
|
1580 |
||
1581 |
wordAtWordIndex:int16Index MSB:msb |
|
1582 |
"return the unsigned short (uint16) at index, anInteger. |
|
1583 |
Fetching is MSB if msb is true, LSB otherwise. |
|
1584 |
Indices are 1-based and scaled as appropriate to allow |
|
1585 |
accessing the memory as an array of word entries. |
|
1586 |
(i.e. indices are 1, 2, ...)" |
|
1587 |
||
1588 |
^ self unsignedInt16At:((int16Index - 1) * 2 + 1) MSB:msb |
|
1589 |
||
1590 |
"Created: / 21.1.1998 / 17:48:30 / cg" |
|
1591 |
! |
|
1592 |
||
1593 |
wordAtWordIndex:int16Index put:anInteger |
|
1594 |
"set the unsigned short (uint16) at index, anInteger. |
|
1595 |
Storing in the machine's natural byte order. |
|
1596 |
Indices are 1-based and scaled as appropriate to allow |
|
1597 |
accessing the memory as an array of word entries. |
|
1598 |
(i.e. indices are 1, 2, ...)" |
|
1599 |
||
1600 |
^ self unsignedInt16At:int16Index put:anInteger MSB:IsBigEndian |
|
1601 |
||
1602 |
"Created: / 21.1.1998 / 17:48:34 / cg" |
|
1603 |
"Modified: / 5.3.1998 / 15:00:27 / stefan" |
|
1604 |
! |
|
1605 |
||
1606 |
wordAtWordIndex:int16Index put:anInteger MSB:msb |
|
1607 |
"set the short at index, anInteger. |
|
1608 |
Storing is MSB if msb is true, LSB otherwise. |
|
1609 |
Indices are 1-based and scaled as appropriate to allow |
|
1610 |
accessing the memory as an array of word entries. |
|
1611 |
(i.e. indices are 1, 2, ...)" |
|
1612 |
||
1613 |
^ self unsignedInt16At:((int16Index - 1) * 2 + 1) put:anInteger MSB:msb |
|
1614 |
||
1615 |
"Created: / 21.1.1998 / 17:48:38 / cg" |
|
1616 |
! ! |
|
1617 |
||
1618 |
!UninterpretedBytes methodsFor:'Compatibility-Squeak'! |
|
1619 |
||
1620 |
copyFromByteArray:aByteArray |
|
1621 |
"copy as much as possible from aByteArray" |
|
1622 |
||
1623 |
self replaceBytesFrom:1 to:(self size min:aByteArray size) with:aByteArray startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
1624 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
1625 |
|
9185 | 1626 |
!UninterpretedBytes methodsFor:'Compatibility-V''Age'! |
1627 |
||
1628 |
uint32At:zeroBasedIndex |
|
1629 |
"return the 4-bytes starting at index as (unsigned) Integer. |
|
19415 | 1630 |
WARNING: The index is a C index (i.e. 0-based). |
19301 | 1631 |
The value is retrieved in the machine's natural byte order. |
19415 | 1632 |
Similar to unsignedInt32At:, except for the index base" |
1633 |
||
1634 |
^ self unsignedInt32At:zeroBasedIndex+1 |
|
9185 | 1635 |
|
1636 |
" |
|
1637 |
|b| |
|
1638 |
||
1639 |
b := ByteArray withAll:#(0 0 0 0). |
|
1640 |
b uint32At:0 put:16r12345678. |
|
1641 |
b uint32At:0. |
|
1642 |
b |
|
1643 |
" |
|
1644 |
! |
|
1645 |
||
1646 |
uint32At:zeroBasedIndex put:anInteger |
|
1647 |
"set the 4-bytes starting at index to the value given by (unsigned) Integer. |
|
19415 | 1648 |
WARNING: The index is a C index (i.e. 0-based). |
1649 |
The value is stored in the machine's natural byte order. |
|
1650 |
Similar to unsignedInt32At:put:, except for the index base" |
|
1651 |
||
1652 |
^ self unsignedInt32At:zeroBasedIndex+1 put:anInteger |
|
9185 | 1653 |
|
1654 |
" |
|
1655 |
|b| |
|
1656 |
||
1657 |
b := ByteArray withAll:#(0 0 0 0). |
|
1658 |
b uint32At:0 put:16r12345678. |
|
1659 |
b |
|
1660 |
" |
|
1661 |
! ! |
|
1662 |
||
16796 | 1663 |
!UninterpretedBytes methodsFor:'accessing-arbitrary-long ints'! |
1664 |
||
19349 | 1665 |
nativeIntAt:index |
1666 |
"return the 4- or 8-bytes (depending on the native integer/pointer size) |
|
1667 |
starting at index as a signed Integer. |
|
1668 |
The index is a smalltalk index (i.e. 1-based). |
|
1669 |
The value is retrieved in the machines natural byte order, |
|
1670 |
therefore, this should only be used for byte-data which is |
|
1671 |
only used inside this machine." |
|
1672 |
||
1673 |
|w| |
|
1674 |
||
1675 |
%{ |
|
1676 |
/* |
|
1677 |
* handle the most common cases fast ... |
|
1678 |
*/ |
|
1679 |
if (__isSmallInteger(index)) { |
|
1680 |
unsigned char *cp; |
|
1681 |
INT sz; |
|
1682 |
||
1683 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1684 |
if (cp) { |
|
1685 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1686 |
||
1687 |
if ((idx+(sizeof(INT)-1)) < sz) { |
|
1688 |
cp += idx; |
|
1689 |
#if defined(__i386__) |
|
1690 |
/* |
|
20816 | 1691 |
* aligned or not, we don't care (i386 can do both) |
19349 | 1692 |
*/ |
1693 |
{ |
|
1694 |
INT iVal = ((INT *)cp)[0]; |
|
1695 |
||
1696 |
RETURN (__MKINT(iVal)); |
|
1697 |
} |
|
1698 |
#else |
|
1699 |
/* |
|
1700 |
* aligned |
|
1701 |
*/ |
|
1702 |
if (((INT)cp & (sizeof(INT)-1)) == 0) { |
|
1703 |
INT iVal = ((INT *)cp)[0]; |
|
1704 |
||
1705 |
RETURN (__MKINT(iVal)); |
|
1706 |
} |
|
1707 |
#endif |
|
1708 |
} |
|
1709 |
} |
|
1710 |
} |
|
1711 |
%}. |
|
19402 | 1712 |
SmallInteger maxBytes == 8 ifTrue:[ |
19349 | 1713 |
^ self signedInt64At:index |
1714 |
]. |
|
1715 |
^ self signedInt32At:index |
|
1716 |
||
1717 |
" |
|
1718 |
|b| |
|
1719 |
b := ByteArray new:8. |
|
1720 |
b nativeIntAt:1 put:SmallInteger maxVal. |
|
1721 |
b nativeIntAt:1 |
|
1722 |
" |
|
1723 |
! |
|
1724 |
||
1725 |
nativeIntAt:index put:value |
|
1726 |
"set the 4- or 8-bytes (depending on INT-/pointer size) starting at index from the signed Integer value. |
|
1727 |
The index is a smalltalk index (i.e. 1-based). |
|
1728 |
The value is stored in the machine's natural byte order." |
|
1729 |
||
1730 |
%{ /* NOCONTEXT */ |
|
1731 |
/* |
|
1732 |
* handle the most common cases fast ... |
|
1733 |
*/ |
|
1734 |
if (__isSmallInteger(index)) { |
|
1735 |
unsigned char *cp; |
|
1736 |
INT sz; |
|
1737 |
||
1738 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1739 |
if (cp) { |
|
1740 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1741 |
||
1742 |
if ((idx+(sizeof(INT)-1)) < sz) { |
|
1743 |
cp += idx; |
|
1744 |
/* |
|
1745 |
* aligned |
|
1746 |
*/ |
|
1747 |
if (((INT)cp & (sizeof(INT)-1)) == 0) { |
|
1748 |
INT __v; |
|
1749 |
||
1750 |
if (__isSmallInteger(value)) { |
|
1751 |
// how about a range check? |
|
1752 |
((INT *)cp)[0] = (INT)(__intVal(value)); |
|
1753 |
RETURN (value); |
|
1754 |
} |
|
1755 |
if ((__v = __signedLongIntVal(value)) != 0) { |
|
1756 |
// how about a range check? |
|
1757 |
((INT *)cp)[0] = (INT)(__v); |
|
1758 |
RETURN (value); |
|
1759 |
} |
|
1760 |
} |
|
1761 |
} |
|
1762 |
} |
|
1763 |
} |
|
1764 |
%}. |
|
19402 | 1765 |
SmallInteger maxBytes == 8 ifTrue:[ |
19349 | 1766 |
^ self signedInt64At:index put:value MSB:IsBigEndian |
1767 |
]. |
|
1768 |
^ self signedInt32At:index put:value MSB:IsBigEndian |
|
1769 |
||
1770 |
" |
|
1771 |
|b| |
|
1772 |
b := ByteArray new:8. |
|
1773 |
b nativeIntAt:1 put:SmallInteger maxVal. |
|
1774 |
(b nativeIntAt:1) |
|
1775 |
" |
|
1776 |
! |
|
1777 |
||
19402 | 1778 |
signedIntegerAt:index length:len bigEndian:bigEndian |
19197 | 1779 |
"return the n-byte signed integer starting at index. |
1780 |
With n=1, this returns the single signed byte's value, |
|
1781 |
n=2, a signed short, n=4 a signed int etc. |
|
1782 |
Useful to extract arbitrary long integers" |
|
1783 |
||
19402 | 1784 |
|val highByte |
1785 |
iIndex "{ Class:SmallInteger }" |
|
1786 |
last "{ Class:SmallInteger }"| |
|
1787 |
||
1788 |
iIndex := index. |
|
1789 |
last := iIndex + len - 1. |
|
19197 | 1790 |
|
1791 |
val := 0. |
|
1792 |
bigEndian ifTrue:[ |
|
19402 | 1793 |
highByte := self at:iIndex. |
1794 |
iIndex to:last do:[:i | |
|
19351 | 1795 |
val := (val<<8) + (self byteAt:i) |
19197 | 1796 |
] |
1797 |
] ifFalse:[ |
|
19402 | 1798 |
highByte := self at:last. |
1799 |
last to:iIndex by:-1 do:[:i | |
|
19351 | 1800 |
val := (val<<8) + (self byteAt:i) |
19197 | 1801 |
] |
1802 |
]. |
|
1803 |
(highByte bitTest:16r80) ifTrue:[ |
|
19402 | 1804 |
^ val - (1 bitShift:(len*8)) |
19197 | 1805 |
]. |
1806 |
^ val |
|
1807 |
||
1808 |
" |
|
1809 |
|b| |
|
1810 |
b := #[ 16r01 16rFF 16r00 16r04 16r05 ]. |
|
1811 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> 255 (00FF) '. |
|
1812 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> -256 (FF00) '. |
|
1813 |
||
1814 |
b := #[ 16r01 16r00 16rFF 16r04 16r05 ]. |
|
1815 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> -256 (FF00) '. |
|
1816 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> 255 (00FF) '. |
|
1817 |
||
1818 |
b := #[ 16r01 16r7F 16r00 16r04 16r05 ]. |
|
1819 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> 127 (007F) '. |
|
1820 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> 32512 (7F00) '. |
|
1821 |
" |
|
1822 |
||
1823 |
" |
|
1824 |
|b| |
|
1825 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ]. |
|
1826 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
1827 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
1828 |
||
1829 |
b := #[ 16r01 16r82 16r03 16r04 16r05 ]. |
|
1830 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
1831 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
1832 |
||
1833 |
b := #[ 16r01 16r82 16r03 16r04 16r85 ]. |
|
1834 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
1835 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
1836 |
" |
|
1837 |
! |
|
1838 |
||
19402 | 1839 |
unsignedIntegerAt:index length:len bigEndian:bigEndian |
16796 | 1840 |
"return the n-byte unsigned integer starting at index. |
1841 |
With n=1, this returns the single byte's value, |
|
1842 |
n=2, an unsigned short, n=4 an unsigned int etc. |
|
1843 |
Useful to extract arbitrary long integers" |
|
1844 |
||
19402 | 1845 |
|val |
1846 |
iIndex "{ Class:SmallInteger }" |
|
1847 |
last "{ Class:SmallInteger }"| |
|
1848 |
||
1849 |
iIndex := index. |
|
1850 |
last := iIndex + len - 1. |
|
16796 | 1851 |
|
1852 |
val := 0. |
|
18346 | 1853 |
bigEndian ifTrue:[ |
19402 | 1854 |
iIndex to:last do:[:i | |
19351 | 1855 |
val := (val<<8) + (self byteAt:i) |
1856 |
] |
|
18346 | 1857 |
] ifFalse:[ |
19402 | 1858 |
last to:iIndex by:-1 do:[:i | |
19351 | 1859 |
val := (val<<8) + (self byteAt:i) |
1860 |
] |
|
16796 | 1861 |
]. |
1862 |
^ val |
|
1863 |
||
1864 |
" |
|
1865 |
|b| |
|
1866 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ]. |
|
18346 | 1867 |
(b unsignedIntegerAt:2 length:4 bigEndian:false). |
1868 |
(b unsignedIntegerAt:2 length:4 bigEndian:true). |
|
16796 | 1869 |
" |
19301 | 1870 |
! |
1871 |
||
19402 | 1872 |
unsignedIntegerAt:index put:newValue length:len bigEndian:bigEndian |
19301 | 1873 |
"store the n-byte unsigned integer starting at index. |
1874 |
With n=1, this stores a single byte's value, |
|
1875 |
n=2, an unsigned short, n=4 an unsigned int etc. |
|
1876 |
Useful to replace arbitrary long integers" |
|
1877 |
||
19402 | 1878 |
|val |
1879 |
iIndex "{ Class:SmallInteger }" |
|
1880 |
last "{ Class:SmallInteger }"| |
|
1881 |
||
1882 |
iIndex := index. |
|
1883 |
last := iIndex + len - 1. |
|
19301 | 1884 |
|
1885 |
val := newValue. |
|
1886 |
bigEndian ifTrue:[ |
|
19402 | 1887 |
iIndex to:last do:[:i | |
19351 | 1888 |
self byteAt:i put:(val bitAnd:16rFF). |
19301 | 1889 |
val := val bitShift:-8. |
1890 |
] |
|
1891 |
] ifFalse:[ |
|
19402 | 1892 |
last to:iIndex by:-1 do:[:i | |
19351 | 1893 |
self byteAt:i put:(val bitAnd:16rFF). |
19301 | 1894 |
val := val bitShift:-8. |
1895 |
] |
|
1896 |
]. |
|
1897 |
||
1898 |
" |
|
1899 |
|b| |
|
1900 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ] copy. |
|
1901 |
(b unsignedIntegerAt:2 put:16r11223344 length:3 bigEndian:false). b. |
|
1902 |
(b unsignedIntegerAt:2 put:16r11223344 length:3 bigEndian:true). b. |
|
1903 |
" |
|
16796 | 1904 |
! ! |
1905 |
||
3459 | 1906 |
!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
|
1907 |
|
4422 | 1908 |
bcdByteAt:index |
13724 | 1909 |
"return the bcd-value for a byte at index in the range 0..99. |
1910 |
BCD treats nibbles (4-bit) as an encoded decimal number's digits |
|
1911 |
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)" |
|
4422 | 1912 |
|
4425 | 1913 |
^ (self byteAt:index) decodeFromBCD |
4422 | 1914 |
|
1915 |
" |
|
19352 | 1916 |
#[ 16r55 ] bcdByteAt:1 |
1917 |
#[ 16r99 ] bcdByteAt:1 |
|
1918 |
#[ 16rAA ] bcdByteAt:1 |
|
4422 | 1919 |
" |
13724 | 1920 |
|
1921 |
"Modified (comment): / 26-09-2011 / 11:57:33 / cg" |
|
4422 | 1922 |
! |
1923 |
||
1924 |
bcdByteAt:index put:aNumber |
|
13724 | 1925 |
"set the byte at index as bcd-value in the range 0..99. |
1926 |
BCD treats nibbles (4-bit) as an encoded decimal number's digits |
|
1927 |
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)" |
|
4422 | 1928 |
|
1929 |
(aNumber between:0 and:99) ifFalse:[ |
|
19368 | 1930 |
self error:'invalid value for BCD encoding' |
4422 | 1931 |
]. |
4425 | 1932 |
^ self byteAt:index put:aNumber encodeAsBCD |
4422 | 1933 |
|
1934 |
" |
|
13575 | 1935 |
(((ByteArray new:1) bcdByteAt:1 put:55; yourself) at:1) hexPrintString |
1936 |
(((ByteArray new:1) bcdByteAt:1 put:99; yourself) at:1) hexPrintString |
|
1937 |
(((ByteArray new:1) bcdByteAt:1 put:100; yourself) at:1) hexPrintString |
|
1938 |
(((ByteArray new:1) bcdByteAt:1 put:-1; yourself) at:1) hexPrintString |
|
4422 | 1939 |
" |
13724 | 1940 |
|
1941 |
"Modified (comment): / 26-09-2011 / 11:57:36 / cg" |
|
4422 | 1942 |
! |
1943 |
||
19351 | 1944 |
byteAt:byteIndex |
1945 |
"return the byte at byteIndex as an unsigned 8 bit value in the range 0..255. |
|
1946 |
The index is a smalltalk index (i.e. 1-based)." |
|
1947 |
||
1948 |
%{ |
|
1949 |
if (__isSmallInteger(byteIndex)) { |
|
1950 |
unsigned char *cp; |
|
1951 |
INT sz; |
|
1952 |
||
1953 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1954 |
if (cp) { |
|
1955 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
1956 |
||
1957 |
if (idx < sz) { |
|
19830 | 1958 |
unsigned char ch = cp[idx] & 0xFF; |
19351 | 1959 |
RETURN (__mkSmallInteger( ch )); |
1960 |
} |
|
1961 |
} |
|
1962 |
} |
|
1963 |
%}. |
|
1964 |
||
1965 |
^ self at:byteIndex |
|
3459 | 1966 |
|
1967 |
" |
|
1968 |
|b| |
|
19351 | 1969 |
b := ByteArray new:3. |
3459 | 1970 |
b at:1 put:16rFF. |
1971 |
b at:2 put:16r7F. |
|
19351 | 1972 |
b at:3 put:16r80. |
1973 |
b byteAt:1. |
|
1974 |
b byteAt:2. |
|
1975 |
b byteAt:3. |
|
1976 |
" |
|
1977 |
||
1978 |
"Modified: / 01-07-1996 / 21:13:53 / cg" |
|
1979 |
"Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
|
1980 |
! |
|
1981 |
||
1982 |
byteAt:byteIndex put:anInteger |
|
1983 |
"set the byte at byteIndex as an unsigned 8 bit value in the range 0..255. |
|
1984 |
The index is a smalltalk index (i.e. 1-based)." |
|
1985 |
||
1986 |
%{ |
|
1987 |
if (__isSmallInteger(byteIndex) && __isSmallInteger(anInteger)) { |
|
1988 |
unsigned char *cp; |
|
1989 |
INT sz; |
|
1990 |
INT val = __intVal(anInteger); |
|
1991 |
||
1992 |
if ( ((unsigned INT)val) <= 0xFF ) { |
|
1993 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1994 |
if (cp) { |
|
1995 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
1996 |
||
1997 |
if (idx < sz) { |
|
1998 |
cp[idx] = val & 0xFF; |
|
1999 |
RETURN (anInteger); |
|
2000 |
} |
|
2001 |
} |
|
2002 |
} |
|
2003 |
} |
|
2004 |
%}. |
|
2005 |
||
2006 |
^ self at:byteIndex put:anInteger |
|
2007 |
||
2008 |
" |
|
2009 |
|b| |
|
2010 |
b := ByteArray new:3. |
|
2011 |
b byteAt:1 put:16rFF. |
|
2012 |
b byteAt:2 put:16r7F. |
|
2013 |
b byteAt:3 put:16r80. |
|
2014 |
b signedByteAt:1. |
|
2015 |
b signedByteAt:2. |
|
2016 |
b signedByteAt:3. |
|
2017 |
" |
|
2018 |
! |
|
2019 |
||
2020 |
signedByteAt:byteIndex |
|
2021 |
"return the byte at byteIndex as a signed 8 bit value in the range -128..+127. |
|
2022 |
The index is a smalltalk index (i.e. 1-based). |
|
2023 |
This may be worth a primitive." |
|
2024 |
||
2025 |
%{ |
|
2026 |
/* |
|
2027 |
* handle the most common cases fast ... |
|
2028 |
*/ |
|
2029 |
if (__isSmallInteger(byteIndex)) { |
|
2030 |
unsigned char *cp; |
|
2031 |
INT sz; |
|
2032 |
||
2033 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2034 |
if (cp) { |
|
2035 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
2036 |
char ch; |
|
2037 |
||
2038 |
if (idx < sz) { |
|
2039 |
cp += idx; |
|
2040 |
ch = cp[0]; |
|
2041 |
# ifndef HAS_SIGNED_CHAR |
|
2042 |
if ( (unsigned int)ch >= 0x80 ) { |
|
2043 |
ch = ch - 0x100; |
|
2044 |
} |
|
2045 |
#endif |
|
2046 |
RETURN (__mkSmallInteger( ch )); |
|
2047 |
} |
|
2048 |
} |
|
2049 |
} |
|
2050 |
%}. |
|
2051 |
||
2052 |
^ (self byteAt:byteIndex) signExtendedByteValue |
|
2053 |
||
2054 |
" |
|
2055 |
|b| |
|
2056 |
b := ByteArray new:3. |
|
2057 |
b at:1 put:16rFF. |
|
2058 |
b at:2 put:16r7F. |
|
2059 |
b at:3 put:16r80. |
|
2060 |
b byteAt:1. |
|
2061 |
b byteAt:2. |
|
2062 |
b byteAt:3. |
|
3459 | 2063 |
" |
2064 |
||
13724 | 2065 |
"Modified: / 01-07-1996 / 21:13:53 / cg" |
2066 |
"Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
|
3459 | 2067 |
! |
2068 |
||
2069 |
signedByteAt:index put:aSignedByteValue |
|
13724 | 2070 |
"return the byte at index as a signed 8 bit value in the range -128..+127. |
3459 | 2071 |
The index is a smalltalk index (i.e. 1-based). |
2072 |
Return the signedByteValue argument. |
|
2073 |
This may be worth a primitive." |
|
2074 |
||
2075 |
|b "{ Class: SmallInteger }"| |
|
2076 |
||
2077 |
aSignedByteValue >= 0 ifTrue:[ |
|
19351 | 2078 |
b := aSignedByteValue |
3459 | 2079 |
] ifFalse:[ |
19351 | 2080 |
b := 16r100 + aSignedByteValue |
3459 | 2081 |
]. |
19351 | 2082 |
self byteAt:index put:b. |
3459 | 2083 |
^ aSignedByteValue |
2084 |
||
2085 |
" |
|
2086 |
|b| |
|
2087 |
b := ByteArray new:2. |
|
2088 |
b signedByteAt:1 put:-1. |
|
13575 | 2089 |
b at:1 |
3459 | 2090 |
" |
2091 |
||
13724 | 2092 |
"Modified: / 01-07-1996 / 21:12:37 / cg" |
2093 |
"Modified (comment): / 26-09-2011 / 11:57:18 / cg" |
|
3459 | 2094 |
! ! |
2095 |
||
2096 |
!UninterpretedBytes methodsFor:'accessing-floats & doubles'! |
|
2097 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2098 |
doubleAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2099 |
"return the 8-bytes starting at index as a Float. |
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 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
19415 | 2102 |
Notice also, that the bytes are expected to be in this machine's |
19629 | 2103 |
float representation and byte order - if the bytearray originated from another |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2104 |
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
|
2105 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2106 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2107 |
|
3433 | 2108 |
%{ |
2109 |
/* |
|
2110 |
* handle the most common cases fast ... |
|
2111 |
*/ |
|
2112 |
if (__isSmallInteger(index)) { |
|
19351 | 2113 |
unsigned char *cp; |
2114 |
INT sz; |
|
2115 |
||
2116 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2117 |
if (cp) { |
|
19415 | 2118 |
INT idx = __intVal(index) - 1; |
2119 |
||
2120 |
if ((idx >= 0) && ((idx+(sizeof(double)-1)) < sz)) { |
|
19351 | 2121 |
cp += idx; |
2122 |
/* |
|
2123 |
* aligned |
|
2124 |
*/ |
|
2125 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
2126 |
double dVal = ((double *)cp)[0]; |
|
2127 |
OBJ f; |
|
2128 |
||
2129 |
__qMKFLOAT(f, dVal); |
|
2130 |
RETURN (f); |
|
2131 |
} |
|
2132 |
} |
|
2133 |
} |
|
3433 | 2134 |
} |
2135 |
%}. |
|
2136 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2137 |
newFloat := Float basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2138 |
1 to:8 do:[:destIndex| |
19351 | 2139 |
newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex)) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2140 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2141 |
^ newFloat. |
3433 | 2142 |
|
2143 |
" |
|
2144 |
|b| |
|
2145 |
||
2146 |
b := ByteArray new:20. |
|
2147 |
b doubleAt:1 put:(Float pi). |
|
2148 |
Transcript showCR:b. |
|
2149 |
Transcript showCR:(b doubleAt:1) |
|
2150 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2151 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2152 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2153 |
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
|
2154 |
"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
|
2155 |
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
|
2156 |
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
|
2157 |
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
|
2158 |
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
|
2159 |
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
|
2160 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2161 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2162 |
|
18284 | 2163 |
msb == IsBigEndian ifTrue:[ |
19351 | 2164 |
^ 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
|
2165 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2166 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2167 |
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
|
2168 |
1 to:8 do:[:destIndex| |
19351 | 2169 |
newFloat basicAt:(9-destIndex) put:(self byteAt:(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
|
2170 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2171 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2172 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2173 |
"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
|
2174 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2175 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2176 |
doubleAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2177 |
"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
|
2178 |
starting at index. |
3433 | 2179 |
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
|
2180 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
19415 | 2181 |
Notice also, that the bytes are expected to be in this machine's |
19629 | 2182 |
float representation and byte order - if the bytearray originated from another |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2183 |
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
|
2184 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2185 |
|flt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2186 |
|
3433 | 2187 |
%{ |
2188 |
/* |
|
2189 |
* handle the most common cases fast ... |
|
2190 |
*/ |
|
16320 | 2191 |
if (__isSmallInteger(index)) { |
19351 | 2192 |
unsigned char *cp; |
2193 |
INT sz; |
|
2194 |
||
2195 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2196 |
if (cp) { |
|
19415 | 2197 |
INT idx = __intVal(index) - 1; |
2198 |
||
2199 |
if ((idx >= 0) && ((idx+(sizeof(double)-1)) < sz)) { |
|
19351 | 2200 |
cp += idx; |
2201 |
/* |
|
2202 |
* aligned |
|
2203 |
*/ |
|
2204 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
2205 |
if (__isFloat(aFloat)) { |
|
2206 |
((double *)cp)[0] = __floatVal(aFloat); |
|
2207 |
RETURN (aFloat); |
|
2208 |
} |
|
2209 |
if (__isShortFloat(aFloat)) { |
|
2210 |
((double *)cp)[0] = (double)(__shortFloatVal(aFloat)); |
|
2211 |
RETURN (aFloat); |
|
2212 |
} |
|
2213 |
if (__isSmallInteger(aFloat)) { |
|
2214 |
((double *)cp)[0] = (double)(__intVal(aFloat)); |
|
2215 |
RETURN (aFloat); |
|
2216 |
} |
|
2217 |
} |
|
2218 |
} |
|
2219 |
} |
|
3433 | 2220 |
} |
2221 |
%}. |
|
2222 |
||
16320 | 2223 |
flt := aFloat asFloat. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2224 |
1 to:8 do:[:srcIndex| |
19351 | 2225 |
self byteAt:(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
|
2226 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2227 |
^ aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2228 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2229 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2230 |
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
|
2231 |
"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
|
2232 |
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
|
2233 |
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
|
2234 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
19415 | 2235 |
Notice also, that the bytes are expected to be in this machine's |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2236 |
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
|
2237 |
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
|
2238 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2239 |
|flt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2240 |
|
18284 | 2241 |
msb == IsBigEndian ifTrue:[ |
19351 | 2242 |
^ 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
|
2243 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2244 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2245 |
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
|
2246 |
1 to:8 do:[:srcIndex| |
19351 | 2247 |
self byteAt:(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
|
2248 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2249 |
^ aFloat |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2250 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2251 |
"Created: / 15.5.1998 / 17:22:27 / cg" |
3447 | 2252 |
"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
|
2253 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2254 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2255 |
floatAt:index |
3434 | 2256 |
"return the 4-bytes starting at index as a ShortFloat. |
3433 | 2257 |
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
|
2258 |
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
|
2259 |
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
|
2260 |
a float object which keeps an 8-byte double internally. |
19415 | 2261 |
Notice also, that the bytes are expected to be in this machine's |
19629 | 2262 |
float representation and byte order - if the bytearray originated from another |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2263 |
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
|
2264 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2265 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2266 |
|
3434 | 2267 |
%{ |
2268 |
/* |
|
2269 |
* handle the most common cases fast ... |
|
2270 |
*/ |
|
2271 |
if (__isSmallInteger(index)) { |
|
19351 | 2272 |
unsigned char *cp; |
2273 |
INT sz; |
|
2274 |
||
2275 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2276 |
if (cp) { |
|
19415 | 2277 |
INT idx = __intVal(index) - 1; |
2278 |
||
2279 |
if ((idx >= 0) && ((idx+(sizeof(float)-1)) < sz)) { |
|
19351 | 2280 |
cp += idx; |
2281 |
/* |
|
2282 |
* aligned |
|
2283 |
*/ |
|
2284 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
2285 |
float fVal = ((float *)cp)[0]; |
|
2286 |
OBJ f; |
|
2287 |
||
2288 |
__qMKSFLOAT(f, fVal); |
|
2289 |
RETURN (f); |
|
2290 |
} |
|
2291 |
} |
|
2292 |
} |
|
3434 | 2293 |
} |
2294 |
%}. |
|
2295 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2296 |
newFloat := ShortFloat basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2297 |
1 to:4 do:[:destIndex| |
19351 | 2298 |
newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex)) |
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 |
^ newFloat. |
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 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2303 |
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
|
2304 |
"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
|
2305 |
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
|
2306 |
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
|
2307 |
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
|
2308 |
a float object which keeps an 8-byte double internally. |
19415 | 2309 |
Notice also, that the bytes are expected to be in this machine's |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2310 |
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
|
2311 |
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
|
2312 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2313 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2314 |
|
18284 | 2315 |
msb == IsBigEndian ifTrue:[ |
19351 | 2316 |
^ 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
|
2317 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2318 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2319 |
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
|
2320 |
1 to:4 do:[:destIndex| |
19351 | 2321 |
newFloat basicAt:(5-destIndex) put:(self byteAt:(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
|
2322 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2323 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2324 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2325 |
"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
|
2326 |
"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
|
2327 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2328 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2329 |
floatAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2330 |
"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
|
2331 |
starting at index. |
3433 | 2332 |
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
|
2333 |
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
|
2334 |
Notice also, that the bytes are expected to be in this machines |
19629 | 2335 |
float representation and byte order - if the bytearray originated from another |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2336 |
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
|
2337 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2338 |
|sflt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2339 |
|
3434 | 2340 |
%{ |
2341 |
/* |
|
2342 |
* handle the most common cases fast ... |
|
2343 |
*/ |
|
16320 | 2344 |
if (__isSmallInteger(index)) { |
19351 | 2345 |
unsigned char *cp; |
2346 |
INT sz; |
|
2347 |
||
2348 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2349 |
if (cp) { |
|
19415 | 2350 |
INT idx = __intVal(index) - 1; |
2351 |
||
2352 |
if ((idx >= 0) && ((idx+(sizeof(float)-1)) < sz)) { |
|
19351 | 2353 |
cp += idx; |
2354 |
/* |
|
2355 |
* aligned |
|
2356 |
*/ |
|
2357 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
2358 |
if (__isShortFloat(aFloat)) { |
|
2359 |
((float *)cp)[0] = __shortFloatVal(aFloat); |
|
2360 |
RETURN (self); |
|
2361 |
} |
|
2362 |
if (__isFloat(aFloat)) { |
|
2363 |
((float *)cp)[0] = (float)__floatVal(aFloat); |
|
2364 |
RETURN (self); |
|
2365 |
} |
|
2366 |
if (__isSmallInteger(aFloat)) { |
|
2367 |
((float *)cp)[0] = (float)__intVal(aFloat); |
|
2368 |
RETURN (self); |
|
2369 |
} |
|
2370 |
// bail out to smalltalk code |
|
2371 |
} |
|
2372 |
} |
|
2373 |
} |
|
3434 | 2374 |
} |
2375 |
%}. |
|
2376 |
||
16320 | 2377 |
sflt := aFloat asShortFloat. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2378 |
1 to:4 do:[:srcIndex| |
19351 | 2379 |
self byteAt: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
|
2380 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2381 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2382 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2383 |
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
|
2384 |
"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
|
2385 |
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
|
2386 |
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
|
2387 |
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
|
2388 |
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
|
2389 |
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
|
2390 |
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
|
2391 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2392 |
|sflt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2393 |
|
18284 | 2394 |
msb == IsBigEndian ifTrue:[ |
19351 | 2395 |
self floatAt:index put:aFloat. |
2396 |
^ self. |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2397 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2398 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2399 |
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
|
2400 |
1 to:4 do:[:srcIndex| |
19351 | 2401 |
self byteAt:(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
|
2402 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2403 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2404 |
"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
|
2405 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2406 |
|
3323 | 2407 |
ieeeDoubleAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2408 |
"retrieve the 8 bytes starting at index as a float. |
3433 | 2409 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2410 |
The 8 bytes are assumed to be in IEEE floating point single precision |
19629 | 2411 |
number format in the native byte order." |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2412 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2413 |
" |
19415 | 2414 |
currently, we assume that the machine's native number format is already |
3323 | 2415 |
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
|
2416 |
to an IBM 370 or old VAX etc. |
3323 | 2417 |
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
|
2418 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2419 |
" |
9258 | 2420 |
Float isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2421 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2422 |
^ self doubleAt:index |
3323 | 2423 |
|
2424 |
"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
|
2425 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2426 |
|
3323 | 2427 |
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
|
2428 |
"store the value of the argument, aFloat into the receiver |
3433 | 2429 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2430 |
starting at index. Storage is in IEEE floating point double precision format. |
19629 | 2431 |
(i.e. 8 bytes are stored in the native byte order)." |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2432 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2433 |
" |
19415 | 2434 |
currently, we assume that the machine's native number format is already |
3323 | 2435 |
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
|
2436 |
to an IBM 370 or old VAX etc. |
3323 | 2437 |
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
|
2438 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2439 |
" |
9258 | 2440 |
Float isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2441 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2442 |
^ self doubleAt:index put:aFloat |
3323 | 2443 |
|
2444 |
"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
|
2445 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2446 |
|
3323 | 2447 |
ieeeFloatAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2448 |
"retrieve the 4 bytes starting at index as a float. |
3433 | 2449 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2450 |
The 4 bytes are assumed to be in IEEE floating point single precision |
19629 | 2451 |
number format in the native byte order." |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2452 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2453 |
" |
19415 | 2454 |
currently, we assume that the machine's native number format is already |
3323 | 2455 |
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
|
2456 |
to an IBM 370 or old VAX etc. |
3323 | 2457 |
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
|
2458 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2459 |
" |
9258 | 2460 |
ShortFloat isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2461 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2462 |
^ self floatAt:index |
3323 | 2463 |
|
2464 |
"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
|
2465 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2466 |
|
3323 | 2467 |
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
|
2468 |
"store the value of the argument, aFloat into the receiver |
13575 | 2469 |
starting at index, which is a smalltalk index (i.e. 1-based). |
3433 | 2470 |
Storage is in IEEE floating point single precision format. |
19629 | 2471 |
(i.e. 4 bytes are stored in the native byte order). |
2472 |
Since ST/X floats are really doubles, |
|
2473 |
the low- order 4 bytes of the precision are lost." |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2474 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2475 |
" |
19415 | 2476 |
currently, we assume that the machine's native number format is already |
3323 | 2477 |
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
|
2478 |
to an IBM 370 or old VAX etc. |
3323 | 2479 |
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
|
2480 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2481 |
" |
9258 | 2482 |
ShortFloat isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2483 |
|
16320 | 2484 |
self floatAt:index put:aFloat |
3323 | 2485 |
|
2486 |
"Created: / 5.3.1998 / 10:51:11 / stefan" |
|
3459 | 2487 |
! ! |
2488 |
||
13724 | 2489 |
!UninterpretedBytes methodsFor:'accessing-longlongs (64bit)'! |
3459 | 2490 |
|
19349 | 2491 |
signedInt64At:index |
3459 | 2492 |
"return the 8-bytes starting at index as a signed Integer. |
2493 |
The index is a smalltalk index (i.e. 1-based). |
|
2494 |
The value is retrieved in the machines natural byte order. |
|
2495 |
This may be worth a primitive." |
|
2496 |
||
2497 |
|w| |
|
2498 |
||
19629 | 2499 |
w := self unsignedInt64At:index MSB:(UninterpretedBytes isBigEndian). |
3459 | 2500 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
19349 | 2501 |
^ w - (16r10000000000000000) |
3459 | 2502 |
]. |
2503 |
^ w |
|
2504 |
||
2505 |
" |
|
2506 |
|b| |
|
2507 |
b := ByteArray new:4. |
|
19349 | 2508 |
b unsignedInt64At:1 put:16rFFFFFFFFFFFFFFFF. |
2509 |
(b signedInt64At:1) |
|
3459 | 2510 |
" |
2511 |
||
2512 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
2513 |
"Created: / 5.3.1998 / 14:40:05 / stefan" |
|
2514 |
"Modified: / 5.3.1998 / 14:58:32 / stefan" |
|
2515 |
! |
|
2516 |
||
19349 | 2517 |
signedInt64At:index MSB:msb |
3459 | 2518 |
"return the 8-bytes starting at index as a signed Integer. |
2519 |
The index is a smalltalk index (i.e. 1-based). |
|
2520 |
The value is retrieved in the given byte order. |
|
2521 |
This may be worth a primitive." |
|
2522 |
||
2523 |
|w| |
|
2524 |
||
19349 | 2525 |
w := self unsignedInt64At:index MSB:msb. |
3459 | 2526 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
19349 | 2527 |
^ w - (16r10000000000000000) |
3459 | 2528 |
]. |
2529 |
^ w |
|
2530 |
||
2531 |
" |
|
2532 |
|b| |
|
2533 |
b := ByteArray new:4. |
|
2534 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
13575 | 2535 |
(b longLongAt:1 msb:true) |
3459 | 2536 |
" |
2537 |
||
2538 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
2539 |
"Created: / 5.3.1998 / 14:40:54 / stefan" |
|
2540 |
"Modified: / 9.5.1998 / 01:10:59 / cg" |
|
2541 |
! |
|
2542 |
||
19349 | 2543 |
signedInt64At:byteIndex put:anInteger |
2544 |
"store a signed longLong (64bit) integer. |
|
2545 |
The index is a smalltalk index (i.e. 1-based). |
|
2546 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
2547 |
||
19629 | 2548 |
^ self signedInt64At:byteIndex put:anInteger MSB:(UninterpretedBytes isBigEndian) |
19349 | 2549 |
! |
2550 |
||
2551 |
signedInt64At:byteIndex put:anInteger MSB:msb |
|
3459 | 2552 |
"store a signed longLong (64bit) integer. |
2553 |
The index is a smalltalk index (i.e. 1-based). |
|
2554 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
2555 |
||
7813 | 2556 |
|v| |
3459 | 2557 |
|
7813 | 2558 |
v := anInteger. |
2559 |
anInteger < 0 ifTrue:[ |
|
19349 | 2560 |
v := v + 16r10000000000000000 |
7813 | 2561 |
]. |
19349 | 2562 |
self unsignedInt64At:byteIndex put:v MSB:msb. |
2563 |
^ anInteger |
|
3459 | 2564 |
|
2565 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
2566 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
2567 |
! |
|
2568 |
||
19629 | 2569 |
signedInt64AtLSB:byteIndex |
2570 |
"return the 8-bytes starting at index as a signed 64bit Integer. |
|
2571 |
The index is a smalltalk index (i.e. 1-based). |
|
2572 |
The value is retrieved with least significant byte first" |
|
2573 |
||
2574 |
^ self signedInt64At:byteIndex MSB:false |
|
2575 |
! |
|
2576 |
||
2577 |
signedInt64AtLSB:byteIndex put:anInteger |
|
2578 |
"set the 8-bytes starting at index from the signed Integer anInteger. |
|
2579 |
The index is a smalltalk index (i.e. 1-based). |
|
2580 |
The integer is stored with least significant byte first." |
|
2581 |
||
2582 |
^ self signedInt64At:byteIndex put:anInteger MSB:false |
|
2583 |
! |
|
2584 |
||
2585 |
signedInt64AtMSB:byteIndex |
|
2586 |
"return the 8-bytes starting at index as a signed 64bit Integer. |
|
2587 |
The index is a smalltalk index (i.e. 1-based). |
|
2588 |
The value is retrieved with most significant byte first" |
|
2589 |
||
2590 |
^ self signedInt64At:byteIndex MSB:true |
|
2591 |
! |
|
2592 |
||
2593 |
signedInt64AtMSB:byteIndex put:anInteger |
|
2594 |
"set the 8-bytes starting at index from the signed Integer anInteger. |
|
2595 |
The index is a smalltalk index (i.e. 1-based). |
|
2596 |
The integer is stored with least significant byte first." |
|
2597 |
||
2598 |
^ self signedInt64At:byteIndex put:anInteger MSB:true |
|
2599 |
! |
|
2600 |
||
19349 | 2601 |
unsignedInt64At:byteIndex |
2602 |
"return the 8-bytes starting at index in the machine's native |
|
2603 |
byteorder as an unsigned integer. |
|
2604 |
The index is a smalltalk index (i.e. 1-based)" |
|
2605 |
||
19629 | 2606 |
^ self unsignedInt64At:byteIndex MSB:(UninterpretedBytes isBigEndian) |
19349 | 2607 |
|
2608 |
" |
|
2609 |
|b| |
|
2610 |
||
2611 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
2612 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
|
2613 |
" |
|
2614 |
||
2615 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
2616 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
2617 |
! |
|
2618 |
||
2619 |
unsignedInt64At:byteIndex MSB:msb |
|
2620 |
"return the 8-bytes starting at index as an unsigned integer. |
|
3459 | 2621 |
The index is a smalltalk index (i.e. 1-based). |
2622 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
2623 |
||
13575 | 2624 |
|l |
3459 | 2625 |
bIdx "{ Class: SmallInteger }" |
2626 |
delta "{ Class: SmallInteger }"| |
|
2627 |
||
2628 |
l := LargeInteger basicNew numberOfDigits:8. |
|
2629 |
msb ifTrue:[ |
|
19349 | 2630 |
bIdx := byteIndex + 7. |
2631 |
delta := -1 |
|
3459 | 2632 |
] ifFalse:[ |
19349 | 2633 |
bIdx := byteIndex. |
2634 |
delta := 1 |
|
3459 | 2635 |
]. |
2636 |
1 to:8 do:[:i | |
|
19351 | 2637 |
l digitAt:i put:(self byteAt:bIdx). |
19349 | 2638 |
bIdx := bIdx + delta |
3459 | 2639 |
]. |
2640 |
^ l compressed |
|
2641 |
||
2642 |
" |
|
2643 |
|b| |
|
2644 |
||
2645 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
13575 | 2646 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
3459 | 2647 |
" |
2648 |
||
2649 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
2650 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
2651 |
! |
|
2652 |
||
19349 | 2653 |
unsignedInt64At:byteIndex put:anInteger |
3459 | 2654 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
2655 |
The index is a smalltalk index (i.e. 1-based). |
|
2656 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
19349 | 2657 |
The value is stored in the machine's natural byteorder." |
2658 |
||
19629 | 2659 |
^ self unsignedInt64At:byteIndex put:anInteger MSB:(UninterpretedBytes isBigEndian) |
19349 | 2660 |
|
2661 |
" |
|
2662 |
|b| |
|
2663 |
b := ByteArray new:10. |
|
2664 |
b unsignedInt64At:1 put:16r0807060504030201 MSB:false. |
|
2665 |
b unsignedInt64At:1 put:16r0807060504030201 MSB:true. |
|
2666 |
b inspect |
|
2667 |
" |
|
2668 |
||
2669 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
3459 | 2670 |
! |
2671 |
||
19349 | 2672 |
unsignedInt64At:byteIndex put:anInteger MSB:msb |
3459 | 2673 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
2674 |
The index is a smalltalk index (i.e. 1-based). |
|
2675 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
2676 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
2677 |
||
2678 |
|bIdx "{ Class: SmallInteger }" |
|
2679 |
delta "{ Class: SmallInteger }"| |
|
2680 |
||
20595 | 2681 |
((anInteger < 0) |
2682 |
or:[anInteger class ~~ SmallInteger |
|
2683 |
and:[anInteger > 16rFFFFFFFFFFFFFFFF]]) ifTrue:[ |
|
19349 | 2684 |
^ self elementBoundsError:anInteger |
3459 | 2685 |
]. |
2686 |
||
2687 |
msb ifTrue:[ |
|
19349 | 2688 |
bIdx := byteIndex + 7. |
2689 |
delta := -1 |
|
3459 | 2690 |
] ifFalse:[ |
19349 | 2691 |
bIdx := byteIndex. |
2692 |
delta := 1 |
|
3459 | 2693 |
]. |
2694 |
1 to:8 do:[:i | |
|
19351 | 2695 |
self byteAt:bIdx put:(anInteger digitAt:i). |
19349 | 2696 |
bIdx := bIdx + delta. |
3459 | 2697 |
]. |
2698 |
^ anInteger |
|
2699 |
||
2700 |
" |
|
2701 |
|b| |
|
2702 |
b := ByteArray new:8. |
|
2703 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
2704 |
b inspect |
|
2705 |
" |
|
2706 |
||
2707 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
19629 | 2708 |
! |
2709 |
||
2710 |
unsignedInt64AtLSB:byteIndex |
|
2711 |
"return the 8-bytes starting at index as an unsigned 64bit Integer. |
|
2712 |
The index is a smalltalk index (i.e. 1-based). |
|
2713 |
The value is retrieved with most significant byte first" |
|
2714 |
||
2715 |
^ self unsignedInt64At:byteIndex MSB:false |
|
2716 |
! |
|
2717 |
||
2718 |
unsignedInt64AtLSB:byteIndex put:anInteger |
|
2719 |
"set the 8-bytes starting at index from the unsigned Integer anInteger. |
|
2720 |
The index is a smalltalk index (i.e. 1-based). |
|
2721 |
The integer is stored with least significant byte first." |
|
2722 |
||
2723 |
^ self unsignedInt64At:byteIndex put:anInteger MSB:false |
|
2724 |
! |
|
2725 |
||
2726 |
unsignedInt64AtMSB:byteIndex |
|
2727 |
"return the 8-bytes starting at index as an unsigned 64bit Integer. |
|
2728 |
The index is a smalltalk index (i.e. 1-based). |
|
2729 |
The value is retrieved with most significant byte first" |
|
2730 |
||
2731 |
^ self unsignedInt64At:byteIndex MSB:true |
|
2732 |
! |
|
2733 |
||
2734 |
unsignedInt64AtMSB:byteIndex put:anInteger |
|
2735 |
"set the 8-bytes starting at index from the unsigned Integer anInteger. |
|
2736 |
The index is a smalltalk index (i.e. 1-based). |
|
2737 |
The integer is stored with least significant byte first." |
|
2738 |
||
2739 |
^ self unsignedInt64At:byteIndex put:anInteger MSB:true |
|
3459 | 2740 |
! ! |
2741 |
||
13724 | 2742 |
!UninterpretedBytes methodsFor:'accessing-longs (32bit)'! |
3459 | 2743 |
|
19349 | 2744 |
signedInt32At:byteIndex |
2745 |
"return the 4-bytes starting at byteIndex as a signed Integer. |
|
3433 | 2746 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 2747 |
The value is retrieved in the machine's natural byte order, |
2748 |
therefore, this should only be used for byte-data which is |
|
2749 |
only used inside this machine. |
|
19415 | 2750 |
To setup binary data packets which are to be sent to other machines, |
2751 |
or stored into a file, always use the corresponding xxx:MSB: method |
|
2752 |
and specify a definite byteOrder." |
|
19349 | 2753 |
|
2754 |
|w| |
|
2755 |
||
2756 |
%{ |
|
2757 |
/* |
|
2758 |
* handle the most common cases fast ... |
|
2759 |
*/ |
|
2760 |
if (__isSmallInteger(byteIndex)) { |
|
2761 |
unsigned char *cp; |
|
2762 |
INT sz; |
|
2763 |
||
2764 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2765 |
if (cp) { |
|
19415 | 2766 |
INT idx = __intVal(byteIndex) - 1; |
2767 |
||
2768 |
if ((idx >= 0) && ((idx+(4-1)) < sz)) { |
|
2769 |
int iVal; |
|
2770 |
||
19349 | 2771 |
cp += idx; |
2772 |
#if defined(__i386__) |
|
2773 |
/* |
|
19415 | 2774 |
* aligned or not, we don't care (i386 can do both) |
19349 | 2775 |
*/ |
2776 |
{ |
|
19415 | 2777 |
iVal = ((int *)cp)[0]; |
19349 | 2778 |
RETURN (__MKINT(iVal)); |
2779 |
} |
|
2780 |
#else |
|
19415 | 2781 |
# if defined(__x86_64__) |
19349 | 2782 |
/* |
19415 | 2783 |
* aligned or not, we don't care (i386 can do both) |
2784 |
*/ |
|
2785 |
{ |
|
2786 |
iVal = ((int *)cp)[0]; |
|
2787 |
RETURN (__mkSmallInteger(iVal)); |
|
2788 |
} |
|
2789 |
# else |
|
2790 |
/* |
|
2791 |
* aligned ? |
|
19349 | 2792 |
*/ |
2793 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
19415 | 2794 |
iVal = ((int *)cp)[0]; |
2795 |
} else { |
|
2796 |
# ifdef __LSBFIRST__ |
|
2797 |
iVal = cp[0] & 0xFF; |
|
2798 |
iVal += (cp[1] & 0xFF)<<8; |
|
2799 |
iVal += (cp[2] & 0xFF)<<16; |
|
2800 |
iVal += (cp[3] & 0xFF)<<24; |
|
2801 |
# else |
|
2802 |
# ifdef __MSBFIRST__ |
|
2803 |
iVal = cp[0] & 0xFF; |
|
2804 |
iVal = (iVal<<8)+(cp[1] & 0xFF); |
|
2805 |
iVal = (iVal<<8)+(cp[2] & 0xFF); |
|
2806 |
iVal = (iVal<<8)+(cp[3] & 0xFF); |
|
2807 |
# else |
|
2808 |
{ |
|
2809 |
union { |
|
2810 |
int i; |
|
2811 |
char c[4]; |
|
2812 |
} u; |
|
2813 |
u.c[0] = cp[0]; |
|
2814 |
u.c[1] = cp[1]; |
|
2815 |
u.c[2] = cp[2]; |
|
2816 |
u.c[3] = cp[3]; |
|
2817 |
iVal = u.i; |
|
2818 |
} |
|
2819 |
# endif |
|
2820 |
# endif |
|
2821 |
||
2822 |
# if __POINTER_SIZE__ == 8 |
|
19349 | 2823 |
RETURN (__mkSmallInteger(iVal)); |
19415 | 2824 |
# else |
19349 | 2825 |
RETURN (__MKINT(iVal)); |
19415 | 2826 |
# endif |
2827 |
} |
|
19349 | 2828 |
# endif |
2829 |
#endif |
|
2830 |
} |
|
2831 |
} |
|
2832 |
} |
|
2833 |
%}. |
|
2834 |
||
19415 | 2835 |
^ self signedInt32At:byteIndex MSB:IsBigEndian. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2836 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2837 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2838 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2839 |
b := ByteArray new:4. |
19349 | 2840 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
2841 |
(b longAt:1) |
|
4515 | 2842 |
" |
19349 | 2843 |
|
2844 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
2845 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2846 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2847 |
|
19349 | 2848 |
signedInt32At:byteIndex MSB:msb |
2849 |
"return the 4-bytes starting at byteIndex as a (signed) Integer. |
|
2850 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
4515 | 2851 |
The value is retrieved MSB-first, if the msb-arg is true; |
2852 |
LSB-first otherwise." |
|
2853 |
||
13575 | 2854 |
|val |
4515 | 2855 |
ival "{ Class: SmallInteger }" |
2856 |
i "{ Class: SmallInteger }" |
|
19349 | 2857 |
bHH "{ Class: SmallInteger }" |
2858 |
bHL "{ Class: SmallInteger }" |
|
2859 |
bLH "{ Class: SmallInteger }" |
|
2860 |
bLL "{ Class: SmallInteger }"| |
|
4515 | 2861 |
|
2862 |
%{ |
|
2863 |
/* |
|
2864 |
* handle the most common cases fast ... |
|
2865 |
*/ |
|
19349 | 2866 |
if (__isSmallInteger(byteIndex)) { |
19047 | 2867 |
unsigned char *cp; |
2868 |
INT sz; |
|
2869 |
||
2870 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2871 |
if (cp) { |
|
19415 | 2872 |
INT idx = __intVal(byteIndex) - 1; |
19047 | 2873 |
int iVal; |
2874 |
||
19349 | 2875 |
cp += idx; |
19415 | 2876 |
if ((idx >= 0) && ((idx+(sizeof(int)-1)) < sz)) { |
19047 | 2877 |
|
2878 |
if (msb == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2879 |
#if defined(__MSBFIRST__) |
19047 | 2880 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
2881 |
/* |
|
2882 |
* aligned |
|
2883 |
*/ |
|
2884 |
iVal = ((int *)cp)[0]; |
|
2885 |
} else |
|
4515 | 2886 |
#endif |
19047 | 2887 |
{ |
2888 |
iVal = cp[0]; |
|
2889 |
iVal = (iVal << 8) | cp[1]; |
|
2890 |
iVal = (iVal << 8) | cp[2]; |
|
2891 |
iVal = (iVal << 8) | cp[3]; |
|
2892 |
} |
|
2893 |
} else { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2894 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
19047 | 2895 |
/* |
19349 | 2896 |
* aligned or not - we don't care |
19047 | 2897 |
* (i386 can fetch unaligned) |
2898 |
*/ |
|
2899 |
iVal = ((int *)cp)[0]; |
|
4515 | 2900 |
#else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2901 |
# if defined(__LSBFIRST__) |
19047 | 2902 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
2903 |
/* |
|
2904 |
* aligned |
|
2905 |
*/ |
|
2906 |
iVal = ((int *)cp)[0]; |
|
2907 |
} else |
|
4515 | 2908 |
# endif |
19047 | 2909 |
{ |
2910 |
iVal = cp[3]; |
|
2911 |
iVal = (iVal << 8) | cp[2]; |
|
2912 |
iVal = (iVal << 8) | cp[1]; |
|
2913 |
iVal = (iVal << 8) | cp[0]; |
|
2914 |
} |
|
4515 | 2915 |
#endif |
19047 | 2916 |
} |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2917 |
#if __POINTER_SIZE__ == 8 |
19047 | 2918 |
RETURN (__mkSmallInteger(iVal)); |
4515 | 2919 |
#else |
19047 | 2920 |
RETURN (__MKINT(iVal)); |
4515 | 2921 |
#endif |
19047 | 2922 |
} |
2923 |
} |
|
4515 | 2924 |
} |
2925 |
%}. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2926 |
|
19415 | 2927 |
val := self unsignedInt32At:byteIndex MSB:msb. |
4515 | 2928 |
(val > (16r7FFFFFFF)) ifTrue:[ |
19047 | 2929 |
^ val - (16r100000000) |
4515 | 2930 |
]. |
2931 |
^ val |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2932 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2933 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2934 |
|b| |
4515 | 2935 |
|
2936 |
b := ByteArray withAll:#(1 2 3 4). |
|
19349 | 2937 |
(b signedInt32At:1 MSB:true) printStringRadix:16. |
2938 |
(b signedInt32At: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
|
2939 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2940 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2941 |
|
19349 | 2942 |
signedInt32At:byteIndex put:anInteger |
2943 |
"set the 4-bytes starting at index from the signed Integer anInteger. |
|
3433 | 2944 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 2945 |
The integer is stored in the machine's natural byte order." |
2946 |
||
2947 |
^ self signedInt32At:byteIndex put:anInteger MSB:IsBigEndian |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2948 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2949 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2950 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2951 |
b := ByteArray new:4. |
19349 | 2952 |
b longAt:1 put:-1. |
2953 |
(b unsignedLongAt:1) printStringRadix:16 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2954 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2955 |
|
19349 | 2956 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
2957 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2958 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2959 |
|
19349 | 2960 |
signedInt32At:byteIndex put:anInteger MSB:msb |
2961 |
"set the 4-bytes starting at byteIndex from the signed Integer value. |
|
2962 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
2963 |
||
2964 |
This is the ST80 version of #signedDoubleWordAt:put:" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2965 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2966 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2967 |
|
19349 | 2968 |
%{ |
2969 |
/* |
|
2970 |
* handle the most common case fast ... |
|
2971 |
*/ |
|
2972 |
if (__isSmallInteger(byteIndex)) { |
|
2973 |
unsigned char *cp; |
|
2974 |
INT sz; |
|
2975 |
||
2976 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2977 |
if (cp) { |
|
19415 | 2978 |
INT idx = __intVal(byteIndex) - 1; |
2979 |
||
2980 |
if ((idx >= 0) && ((idx+3) < sz)) { |
|
19349 | 2981 |
cp += idx; |
2982 |
||
2983 |
if (__isSmallInteger(anInteger)) { |
|
2984 |
INT __v = __intVal(anInteger); |
|
2985 |
||
2986 |
# if __POINTER_SIZE__ == 8 |
|
2987 |
if ((__v < -0x80000000L) || (__v > 0x7FFFFFFF)) { |
|
2988 |
goto badArg; |
|
2989 |
} |
|
2990 |
# endif |
|
2991 |
if (((INT)cp & 3) == 0) { |
|
2992 |
/* |
|
2993 |
* aligned |
|
2994 |
*/ |
|
2995 |
if ( |
|
2996 |
# ifdef __LSBFIRST__ |
|
2997 |
(msb == false) |
|
2998 |
# else |
|
2999 |
# ifdef __MSBFIRST__ |
|
3000 |
(msb == true) |
|
3001 |
# else |
|
3002 |
(0) |
|
3003 |
# endif |
|
3004 |
# endif |
|
3005 |
) { |
|
3006 |
((int *)cp)[0] = (int)__v; |
|
3007 |
RETURN (anInteger); |
|
3008 |
} |
|
3009 |
} |
|
3010 |
if (msb == false) { |
|
3011 |
cp[0] = __v & 0xFF; |
|
3012 |
cp[1] = (__v>>8) & 0xFF; |
|
3013 |
cp[2] = (__v>>16) & 0xFF; |
|
3014 |
cp[3] = (__v>>24) & 0xFF; |
|
3015 |
} else { |
|
3016 |
cp[0] = (__v>>24) & 0xFF; |
|
3017 |
cp[1] = (__v>>16) & 0xFF; |
|
3018 |
cp[2] = (__v>>8) & 0xFF; |
|
3019 |
cp[3] = __v & 0xFF; |
|
3020 |
} |
|
3021 |
RETURN (anInteger); |
|
3022 |
} |
|
3023 |
} |
|
3024 |
} |
|
3025 |
} |
|
3026 |
badArg: ; |
|
3027 |
%}. |
|
3028 |
||
3029 |
anInteger >= 0 ifTrue:[ |
|
3030 |
v := anInteger |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3031 |
] ifFalse:[ |
19349 | 3032 |
v := anInteger + 16r100000000 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3033 |
]. |
19349 | 3034 |
self unsignedInt32At:byteIndex put:v MSB:msb. |
3035 |
^ anInteger |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3036 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3037 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3038 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3039 |
b := ByteArray new:4. |
19349 | 3040 |
b longAt:1 put:-1. |
3041 |
(b unsignedLongAt:1) printStringRadix:16 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3042 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3043 |
|
19349 | 3044 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
3045 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3046 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3047 |
|
19629 | 3048 |
signedInt32AtLSB:byteIndex |
3049 |
"return the 4-bytes starting at index as a signed 32bit Integer. |
|
3050 |
The index is a smalltalk index (i.e. 1-based). |
|
3051 |
The value is retrieved with least significant byte first" |
|
3052 |
||
3053 |
^ self signedInt32At:byteIndex MSB:false |
|
3054 |
! |
|
3055 |
||
3056 |
signedInt32AtLSB:byteIndex put:anInteger |
|
3057 |
"set the 4-bytes starting at index from the signed Integer anInteger. |
|
3058 |
The index is a smalltalk index (i.e. 1-based). |
|
3059 |
The integer is stored with least significant byte first." |
|
3060 |
||
3061 |
^ self signedInt32At:byteIndex put:anInteger MSB:false |
|
3062 |
! |
|
3063 |
||
3064 |
signedInt32AtMSB:byteIndex |
|
3065 |
"return the 4-bytes starting at index as a signed 32bit Integer. |
|
3066 |
The index is a smalltalk index (i.e. 1-based). |
|
3067 |
The value is retrieved with most significant byte first" |
|
3068 |
||
3069 |
^ self signedInt32At:byteIndex MSB:true |
|
3070 |
! |
|
3071 |
||
3072 |
signedInt32AtMSB:byteIndex put:anInteger |
|
3073 |
"set the 4-bytes starting at index from the signed Integer anInteger. |
|
3074 |
The index is a smalltalk index (i.e. 1-based). |
|
3075 |
The integer is stored with most significant byte first." |
|
3076 |
||
3077 |
^ self signedInt32At:byteIndex put:anInteger MSB:true |
|
3078 |
! |
|
3079 |
||
19349 | 3080 |
unsignedInt32At:byteIndex |
3323 | 3081 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
3433 | 3082 |
The index is a smalltalk index (i.e. 1-based). |
19415 | 3083 |
The value is retrieved in the machine's natural byte order." |
19349 | 3084 |
|
3085 |
^ self unsignedInt32At:byteIndex MSB:IsBigEndian |
|
3323 | 3086 |
|
3087 |
" |
|
3088 |
|b| |
|
3089 |
||
3090 |
b := ByteArray withAll:#(1 2 3 4). |
|
19349 | 3091 |
(b unsignedInt32At:1) printStringRadix:16 |
3323 | 3092 |
" |
3093 |
||
19349 | 3094 |
"Modified: / 5.3.1998 / 14:57:35 / stefan" |
3323 | 3095 |
! |
3096 |
||
19349 | 3097 |
unsignedInt32At:byteIndex MSB:msb |
3098 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 3099 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 3100 |
The value is retrieved MSB-first, if the msb-arg is true; |
3101 |
LSB-first otherwise." |
|
3102 |
||
3103 |
|val |
|
3104 |
ival "{ Class: SmallInteger }" |
|
3105 |
i "{ Class: SmallInteger }" |
|
3106 |
bHH "{ Class: SmallInteger }" |
|
3107 |
bHL "{ Class: SmallInteger }" |
|
3108 |
bLH "{ Class: SmallInteger }" |
|
3109 |
bLL "{ Class: SmallInteger }"| |
|
3110 |
||
3111 |
%{ |
|
3112 |
/* |
|
3113 |
* handle the most common cases fast ... |
|
3114 |
*/ |
|
3115 |
if (__isSmallInteger(byteIndex)) { |
|
3116 |
unsigned char *cp; |
|
3117 |
INT sz; |
|
3118 |
||
3119 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3120 |
if (cp) { |
|
19415 | 3121 |
INT idx = __intVal(byteIndex) - 1; |
19349 | 3122 |
unsigned int iVal; |
3123 |
||
19415 | 3124 |
if ((idx >= 0) && ((idx+(sizeof(int)-1)) < sz)) { |
19349 | 3125 |
cp += idx; |
3126 |
||
3127 |
if (msb == true) { |
|
3128 |
#if defined(__MSBFIRST__) |
|
3129 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
|
3130 |
/* |
|
3131 |
* aligned |
|
3132 |
*/ |
|
3133 |
iVal = ((unsigned int *)cp)[0]; |
|
3134 |
} else |
|
3135 |
#endif |
|
3136 |
{ |
|
3137 |
iVal = cp[0]; |
|
3138 |
iVal = (iVal << 8) | cp[1]; |
|
3139 |
iVal = (iVal << 8) | cp[2]; |
|
3140 |
iVal = (iVal << 8) | cp[3]; |
|
3141 |
} |
|
3142 |
} else { |
|
3143 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
|
3144 |
/* |
|
20816 | 3145 |
* aligned or not - we don't care |
19349 | 3146 |
* (i386 can fetch unaligned) |
3147 |
*/ |
|
3148 |
iVal = ((unsigned int *)cp)[0]; |
|
3149 |
#else |
|
3150 |
# if defined(__LSBFIRST__) |
|
3151 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
|
3152 |
/* |
|
3153 |
* aligned |
|
3154 |
*/ |
|
3155 |
iVal = ((unsigned int *)cp)[0]; |
|
3156 |
} else |
|
3157 |
# endif |
|
3158 |
{ |
|
3159 |
iVal = cp[3]; |
|
3160 |
iVal = (iVal << 8) | cp[2]; |
|
3161 |
iVal = (iVal << 8) | cp[1]; |
|
3162 |
iVal = (iVal << 8) | cp[0]; |
|
3163 |
} |
|
3164 |
#endif |
|
3165 |
} |
|
3166 |
#if __POINTER_SIZE__ == 8 |
|
3167 |
RETURN (__mkSmallInteger(iVal)); |
|
3168 |
#else |
|
3169 |
RETURN (__MKUINT(iVal)); |
|
3170 |
#endif |
|
3171 |
} |
|
3172 |
} |
|
3173 |
} |
|
3174 |
%}. |
|
3175 |
||
3176 |
"/ fallBack code - non ByteArray-like receiver |
|
3177 |
"/ or funny byteIndex |
|
3178 |
||
3179 |
i := byteIndex. |
|
3180 |
msb ifFalse:[ |
|
3181 |
bLL := self byteAt:i. |
|
3182 |
bLH := self byteAt:(i+1). |
|
3183 |
bHL := self byteAt:(i+2). |
|
3184 |
bHH := self byteAt:(i+3). |
|
3185 |
] ifTrue:[ |
|
3186 |
bHH := self byteAt:i. |
|
3187 |
bHL := self byteAt:(i+1). |
|
3188 |
bLH := self byteAt:(i+2). |
|
3189 |
bLL := self byteAt:(i+3). |
|
3190 |
]. |
|
3191 |
ival := (bHH bitShift:8) + bHL. |
|
3192 |
ival := (ival bitShift:8) + bLH. |
|
3193 |
val := (ival bitShift:8) + bLL. |
|
3194 |
^ val |
|
3323 | 3195 |
|
3196 |
" |
|
3197 |
|b| |
|
19349 | 3198 |
|
3199 |
b := ByteArray withAll:#(1 2 3 4). |
|
3200 |
(b unsignedInt32At:1 MSB:true) printStringRadix:16. |
|
3201 |
(b unsignedInt32At:1 MSB:false) printStringRadix:16 |
|
3323 | 3202 |
" |
3203 |
! |
|
3204 |
||
19349 | 3205 |
unsignedInt32At:byteIndex put:anInteger |
3206 |
"set the 4-bytes starting at index from the (unsigned) integer value. |
|
3433 | 3207 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 3208 |
The value must be in the range 0 to 16rFFFFFFFF. |
19349 | 3209 |
The value is stored in the machine's native byte order" |
3210 |
||
3211 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:IsBigEndian |
|
3323 | 3212 |
|
3213 |
" |
|
3214 |
|b| |
|
3215 |
b := ByteArray new:8. |
|
19349 | 3216 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
3217 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
3218 |
b inspect |
|
3323 | 3219 |
" |
3220 |
||
3221 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
19349 | 3222 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
3223 |
! |
|
3224 |
||
3225 |
unsignedInt32At:byteIndex put:anInteger MSB:msb |
|
19415 | 3226 |
"set the 4-bytes starting at byteIndex from the unsigned Integer value. |
3227 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3228 |
||
3229 |
This is the ST80 version of #doubleWordAt:put:" |
|
3230 |
||
3231 |
|v i b1 b2 b3 b4| |
|
3232 |
||
3233 |
%{ |
|
3234 |
/* |
|
3235 |
* handle the most common case fast ... |
|
3236 |
*/ |
|
3237 |
if (__isSmallInteger(byteIndex)) { |
|
3238 |
unsigned char *cp; |
|
3239 |
INT sz; |
|
3240 |
||
3241 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3242 |
if (cp) { |
|
3243 |
INT idx = __intVal(byteIndex) - 1; |
|
3244 |
||
3245 |
if ((idx >= 0) && ((idx+3) < sz)) { |
|
3246 |
cp += idx; |
|
3247 |
||
3248 |
if (__isSmallInteger(anInteger)) { |
|
3249 |
INT __v = __intVal(anInteger); |
|
3250 |
||
3251 |
# if __POINTER_SIZE__ == 8 |
|
3252 |
if ((__v < 0) || (__v > 0xFFFFFFFF)) { |
|
3253 |
goto badArg; |
|
3254 |
} |
|
3255 |
# endif |
|
3256 |
if (((INT)cp & 3) == 0) { |
|
3257 |
/* |
|
3258 |
* aligned |
|
3259 |
*/ |
|
3260 |
if ( |
|
3261 |
# ifdef __LSBFIRST__ |
|
3262 |
(msb == false) |
|
3263 |
# else |
|
3264 |
# ifdef __MSBFIRST__ |
|
3265 |
(msb == true) |
|
3266 |
# else |
|
3267 |
(0) |
|
3268 |
# endif |
|
3269 |
# endif |
|
3270 |
) { |
|
3271 |
((int *)cp)[0] = (int)__v; |
|
3272 |
RETURN (anInteger); |
|
3273 |
} |
|
3274 |
} |
|
3275 |
if (msb == false) { |
|
3276 |
cp[0] = __v & 0xFF; |
|
3277 |
cp[1] = (__v>>8) & 0xFF; |
|
3278 |
cp[2] = (__v>>16) & 0xFF; |
|
3279 |
cp[3] = (__v>>24) & 0xFF; |
|
3280 |
} else { |
|
3281 |
cp[0] = (__v>>24) & 0xFF; |
|
3282 |
cp[1] = (__v>>16) & 0xFF; |
|
3283 |
cp[2] = (__v>>8) & 0xFF; |
|
3284 |
cp[3] = __v & 0xFF; |
|
3285 |
} |
|
3286 |
RETURN (anInteger); |
|
3287 |
} |
|
3288 |
} |
|
3289 |
} |
|
3290 |
} |
|
3291 |
badArg: ; |
|
3292 |
%}. |
|
19349 | 3293 |
|
3294 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFF]) ifTrue:[ |
|
3295 |
^ self elementBoundsError:anInteger |
|
3296 |
]. |
|
3297 |
||
3298 |
i := byteIndex. |
|
3299 |
msb ifTrue:[ |
|
3300 |
b1 := (anInteger digitAt:4). |
|
3301 |
b2 := (anInteger digitAt:3). |
|
3302 |
b3 := (anInteger digitAt:2). |
|
3303 |
b4 := (anInteger digitAt:1). |
|
3304 |
] ifFalse:[ |
|
3305 |
b1 := (anInteger digitAt:1). |
|
3306 |
b2 := (anInteger digitAt:2). |
|
3307 |
b3 := (anInteger digitAt:3). |
|
3308 |
b4 := (anInteger digitAt:4). |
|
3309 |
]. |
|
3310 |
self byteAt:i put:b1. |
|
3311 |
self byteAt:(i+1) put:b2. |
|
3312 |
self byteAt:(i+2) put:b3. |
|
3313 |
self byteAt:(i+3) put:b3. |
|
3314 |
^ anInteger |
|
3459 | 3315 |
|
3316 |
" |
|
3317 |
|b| |
|
19415 | 3318 |
b := ByteArray new:4. |
3319 |
b signedInt32At:1 put:-1. |
|
3320 |
(b unsignedInt32At:1) printStringRadix:16 |
|
3321 |
" |
|
3322 |
" |
|
3323 |
|b| |
|
3324 |
b := ByteArray new:4. |
|
3325 |
b unsignedInt32At:1 put:16rFFFFFFFF. |
|
3326 |
(b signedInt32At:1) |
|
3327 |
" |
|
19629 | 3328 |
! |
3329 |
||
3330 |
unsignedInt32AtLSB:byteIndex |
|
3331 |
"return the 4-bytes starting at index as an unsigned 32bit Integer. |
|
3332 |
The index is a smalltalk index (i.e. 1-based). |
|
3333 |
The value is retrieved with least significant byte first" |
|
3334 |
||
3335 |
^ self unsignedInt32At:byteIndex MSB:false |
|
3336 |
! |
|
3337 |
||
3338 |
unsignedInt32AtLSB:byteIndex put:anInteger |
|
3339 |
"set the 4-bytes starting at index from the unsigned Integer anInteger. |
|
3340 |
The index is a smalltalk index (i.e. 1-based). |
|
3341 |
The integer is stored with least significant byte first." |
|
3342 |
||
3343 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:false |
|
3344 |
! |
|
3345 |
||
3346 |
unsignedInt32AtMSB:byteIndex |
|
3347 |
"return the 4-bytes starting at index as an unsigned 32bit Integer. |
|
3348 |
The index is a smalltalk index (i.e. 1-based). |
|
3349 |
The value is retrieved with most significant byte first" |
|
3350 |
||
3351 |
^ self unsignedInt32At:byteIndex MSB:true |
|
3352 |
! |
|
3353 |
||
3354 |
unsignedInt32AtMSB:byteIndex put:anInteger |
|
3355 |
"set the 4-bytes starting at index from the unsigned Integer anInteger. |
|
3356 |
The index is a smalltalk index (i.e. 1-based). |
|
3357 |
The integer is stored with most significant byte first." |
|
3358 |
||
3359 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:true |
|
19349 | 3360 |
! ! |
3361 |
||
20961 | 3362 |
!UninterpretedBytes methodsFor:'accessing-pointers'! |
3363 |
||
3364 |
pointerAt:byteIndex |
|
3365 |
"get a pointer starting at byteIndex as ExternalAddress. |
|
3366 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3367 |
Only aligned accesses are allowed. |
|
3368 |
The pointer is of native cpu's size (4 or 8 bytes)" |
|
3369 |
||
3370 |
%{ |
|
3371 |
if (__isSmallInteger(byteIndex)) { |
|
3372 |
unsigned char *cp; |
|
3373 |
INT sz; |
|
3374 |
||
3375 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3376 |
if (cp) { |
|
3377 |
INT idx = __smallIntegerVal(byteIndex) - 1; |
|
3378 |
char *pointer; |
|
3379 |
||
3380 |
if ((idx >= 0) && ((idx+(sizeof(pointer)-1)) < sz)) { |
|
3381 |
cp += idx; |
|
3382 |
/* |
|
3383 |
* aligned |
|
3384 |
*/ |
|
3385 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
3386 |
pointer = ((char **)cp)[0]; |
|
3387 |
RETURN (__MKEXTERNALADDRESS(pointer)); |
|
3388 |
} else { |
|
3389 |
#if 0 |
|
3390 |
printf("cp UNALIGNED (%"_lx_")\n", (INT)cp); |
|
3391 |
#endif |
|
3392 |
} |
|
3393 |
} else { |
|
3394 |
#if 0 |
|
3395 |
printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n", |
|
3396 |
idx, (int)(sizeof(pointer)-1), sz); |
|
3397 |
#endif |
|
3398 |
} |
|
3399 |
} else { |
|
3400 |
#if 0 |
|
3401 |
printf("cp is NULL\n"); |
|
3402 |
#endif |
|
3403 |
} |
|
3404 |
} else { |
|
3405 |
#if 0 |
|
3406 |
printf("bad index\n"); |
|
3407 |
#endif |
|
3408 |
} |
|
3409 |
bad:; |
|
3410 |
%}. |
|
3411 |
||
3412 |
self primitiveFailed. |
|
3413 |
||
3414 |
" |
|
3415 |
|b| |
|
3416 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
3417 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
3418 |
Transcript showCR:((b unsignedInt32At:1) printStringRadix:16). |
|
3419 |
Transcript showCR:((b pointerAt:1)). |
|
3420 |
||
3421 |
|b| |
|
3422 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
3423 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678abcdef). |
|
3424 |
Transcript showCR:((b unsignedInt64At:1) printStringRadix:16). |
|
3425 |
Transcript showCR:((b pointerAt:1)). |
|
3426 |
" |
|
3427 |
||
3428 |
"Modified (comment): / 14-11-2016 / 17:32:23 / cg" |
|
3429 |
! |
|
3430 |
||
3431 |
pointerAt:byteIndex put:value |
|
3432 |
"set the pointer starting at byteIndex from the integer or externalAddress value. |
|
3433 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3434 |
Only aligned accesses are allowed. |
|
3435 |
The pointer is of native cpu's size (4 or 8 bytes). |
|
3436 |
The value may be either an ExternalAddress, ExternalBytes or an Integer" |
|
3437 |
||
3438 |
%{ |
|
3439 |
OBJ *pointer; |
|
3440 |
||
3441 |
if (__isExternalAddressLike(value)) { |
|
3442 |
pointer = __externalAddressVal(value); |
|
3443 |
} else if (__isExternalBytesLike(value)) { |
|
3444 |
pointer = __externalBytesVal(value); |
|
3445 |
if (pointer == (OBJ *)0) |
|
3446 |
pointer = 0; |
|
3447 |
} else if (value == nil) { |
|
3448 |
pointer = 0; |
|
3449 |
} else if (__isSmallInteger(value)) { |
|
3450 |
pointer = (OBJ *)__intVal(value); |
|
3451 |
} else { |
|
3452 |
if ((pointer = (OBJ *)__unsignedLongIntVal(value)) == 0) { |
|
3453 |
goto bad; |
|
3454 |
} |
|
3455 |
} |
|
3456 |
||
3457 |
if (__isSmallInteger(byteIndex)) { |
|
3458 |
unsigned char *cp; |
|
3459 |
INT sz; |
|
3460 |
||
3461 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3462 |
if (cp) { |
|
3463 |
INT idx = __smallIntegerVal(byteIndex) - 1; |
|
3464 |
||
3465 |
if ((idx >= 0) && ((idx+(sizeof(pointer)-1)) < sz)) { |
|
3466 |
cp += idx; |
|
3467 |
/* |
|
3468 |
* aligned |
|
3469 |
*/ |
|
3470 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
3471 |
((char **)cp)[0] = (char *) pointer; |
|
3472 |
RETURN (value); |
|
3473 |
} |
|
3474 |
} |
|
3475 |
} |
|
3476 |
} |
|
3477 |
bad:; |
|
3478 |
%}. |
|
3479 |
||
3480 |
self primitiveFailed. |
|
3481 |
||
3482 |
" |
|
3483 |
|b| |
|
3484 |
b := ByteArray new:ExternalAddress pointerSize. |
|
3485 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
3486 |
(b unsignedLongAt:1) printStringRadix:16 |
|
3487 |
" |
|
3488 |
||
3489 |
"Created: / 05-03-1998 / 10:57:18 / stefan" |
|
3490 |
"Modified (comment): / 14-11-2016 / 17:28:27 / cg" |
|
3491 |
! |
|
3492 |
||
3493 |
pointerValueAt:byteIndex |
|
3494 |
"get a pointer value starting at byteIndex as unsigned integer. |
|
3495 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3496 |
Only aligned accesses are allowed. |
|
3497 |
The pointer is of native cpu's size (4 or 8 bytes). |
|
3498 |
This returns an int with sizeof the machines's native pointer (4 or 8 bytes)" |
|
3499 |
||
3500 |
%{ |
|
3501 |
if (__isSmallInteger(byteIndex)) { |
|
3502 |
unsigned char *cp; |
|
3503 |
INT sz; |
|
3504 |
||
3505 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3506 |
if (cp) { |
|
3507 |
INT idx = __smallIntegerVal(byteIndex) - 1; |
|
3508 |
char *pointer; |
|
3509 |
||
3510 |
if ((idx >= 0) && ((idx+(sizeof(pointer)-1)) < sz)) { |
|
3511 |
cp += idx; |
|
3512 |
/* |
|
3513 |
* aligned |
|
3514 |
*/ |
|
3515 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
3516 |
pointer = ((char **)cp)[0]; |
|
3517 |
RETURN (__MKUINT((INT)(pointer))); |
|
3518 |
} else { |
|
3519 |
// printf("cp UNALIGNED (%"_lx_")\n", (INT)cp); |
|
3520 |
} |
|
3521 |
} else { |
|
3522 |
// printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n", |
|
3523 |
// idx, (int)(sizeof(pointer)-1), sz); |
|
3524 |
} |
|
3525 |
} else { |
|
3526 |
// printf("cp is NULL\n"); |
|
3527 |
} |
|
3528 |
} else { |
|
3529 |
// printf("bad index\n"); |
|
3530 |
} |
|
3531 |
bad:; |
|
3532 |
%}. |
|
3533 |
||
3534 |
self primitiveFailed. |
|
3535 |
||
3536 |
" |
|
3537 |
|b| |
|
3538 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
3539 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
3540 |
Transcript showCR:((b unsignedLongAt:1) printStringRadix:16). |
|
3541 |
Transcript showCR:((b pointerAt:1)). |
|
3542 |
Transcript showCR:((b pointerValueAt:1)). |
|
3543 |
" |
|
3544 |
||
3545 |
"Modified (comment): / 14-11-2016 / 17:28:33 / cg" |
|
3546 |
! ! |
|
3547 |
||
19349 | 3548 |
!UninterpretedBytes methodsFor:'accessing-shorts (16bit)'! |
3549 |
||
3550 |
signedInt16At:byteIndex |
|
3459 | 3551 |
"return the 2-bytes starting at index as a signed Integer. |
3552 |
The index is a smalltalk index (i.e. 1-based). |
|
19415 | 3553 |
The value is retrieved in the machine's natural byte order." |
3459 | 3554 |
|
19349 | 3555 |
^ (self unsignedInt16At:byteIndex) signExtendedShortValue |
3323 | 3556 |
|
3557 |
" |
|
3558 |
|b| |
|
3459 | 3559 |
b := ByteArray new:2. |
3560 |
b wordAt:1 put:16rFFFF. |
|
13575 | 3561 |
b signedWordAt:1 |
3323 | 3562 |
" |
3563 |
||
3459 | 3564 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
3323 | 3565 |
! |
3566 |
||
19349 | 3567 |
signedInt16At:byteIndex MSB:msb |
3459 | 3568 |
"return the 2-bytes starting at index as a signed Integer. |
3433 | 3569 |
The index is a smalltalk index (i.e. 1-based). |
19366 | 3570 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
3571 |
LSB-first (i.e. low 8-bits at lower byte index) if it's false. |
|
3572 |
Notice: |
|
3573 |
the index is a byte index; thus, this allows for unaligned access to |
|
3574 |
words on any boundary." |
|
3575 |
||
3576 |
|b1 "{ Class: SmallInteger }" |
|
3577 |
b2 "{ Class: SmallInteger }"| |
|
3578 |
||
3579 |
%{ |
|
3580 |
/* |
|
3581 |
* handle the most common cases fast ... |
|
3582 |
*/ |
|
3583 |
if (__isSmallInteger(byteIndex)) { |
|
3584 |
unsigned char *cp; |
|
3585 |
INT sz; |
|
3586 |
||
3587 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3588 |
if (cp) { |
|
19415 | 3589 |
INT idx = __intVal(byteIndex) - 1; |
3590 |
||
3591 |
if ((idx >= 0) && ((idx+(2-1)) < sz)) { |
|
19366 | 3592 |
short sVal; |
3593 |
||
3594 |
cp += idx; |
|
3595 |
if (msb == false) { |
|
3596 |
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK)) |
|
3597 |
/* |
|
20816 | 3598 |
* aligned or not, we don't care (i386 can do both) |
19366 | 3599 |
*/ |
3600 |
sVal = ((short *)cp)[0]; |
|
3601 |
#else |
|
3602 |
sVal = (cp[0] & 0xFF) | ((cp[1] & 0xFF) << 8); |
|
3603 |
#endif |
|
3604 |
} else { |
|
3605 |
sVal = ((cp[0] & 0xFF) << 8) | (cp[1] & 0xFF); |
|
3606 |
} |
|
3607 |
RETURN (__mkSmallInteger(sVal)); |
|
3608 |
} |
|
3609 |
} |
|
3610 |
} |
|
3611 |
%}. |
|
3612 |
||
3613 |
b1 := self byteAt:byteIndex. |
|
3614 |
b2 := self byteAt:(byteIndex + 1). |
|
3615 |
msb ifTrue:[ |
|
3616 |
^ ((b1 bitShift:8) + b2) signExtendedShortValue |
|
3617 |
]. |
|
3618 |
^ ((b2 bitShift:8) + b1) signExtendedShortValue |
|
3459 | 3619 |
! |
3620 |
||
19349 | 3621 |
signedInt16At:index put:anInteger |
3459 | 3622 |
"set the 2-bytes starting at index from the signed Integer value. |
3623 |
The index is a smalltalk index (i.e. 1-based). |
|
3624 |
The stored value must be in the range -32768 .. +32676. |
|
19349 | 3625 |
The value is stored in the machine's natural byte order." |
3626 |
||
3627 |
^ self signedInt16At:index put:anInteger MSB:IsBigEndian |
|
3459 | 3628 |
|
3629 |
" |
|
3630 |
|b| |
|
19349 | 3631 |
b := ByteArray new:4. |
3632 |
b signedInt16At:1 put:-2. |
|
3633 |
b signedInt16At:3 put:-3. |
|
3323 | 3634 |
b inspect |
3635 |
" |
|
3636 |
||
19349 | 3637 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
3459 | 3638 |
! |
3639 |
||
19366 | 3640 |
signedInt16At:byteIndex put:anInteger MSB:msb |
3641 |
"set the 2-bytes starting at byteIndex from the signed integer value. |
|
3642 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
3459 | 3643 |
The stored value must be in the range -32768 .. +32676. |
3644 |
The value is stored MSB-first, if the msb-arg is true; |
|
19366 | 3645 |
LSB-first otherwise." |
3646 |
||
3647 |
%{ /* NOCONTEXT */ |
|
3648 |
/* |
|
3649 |
* handle the most common case fast ... |
|
3650 |
*/ |
|
3651 |
if (__isSmallInteger(byteIndex)) { |
|
3652 |
unsigned char *cp; |
|
3653 |
INT sz; |
|
3654 |
||
3655 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3656 |
if (cp) { |
|
19415 | 3657 |
INT idx = __intVal(byteIndex) - 1; |
3658 |
||
3659 |
if ((idx >= 0) && ((idx+1) < sz)) { |
|
19366 | 3660 |
cp += idx; |
3661 |
||
3662 |
if (__isSmallInteger(anInteger)) { |
|
3663 |
INT __v = __intVal(anInteger); |
|
3664 |
||
3665 |
if ((__v < -0x8000L) || (__v > 0x7FFF)) { |
|
3666 |
goto badArg; |
|
3667 |
} |
|
3668 |
if (msb == false) { |
|
3669 |
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK)) |
|
3670 |
((short *)cp)[0] = (short)__v; |
|
3671 |
#else |
|
3672 |
cp[0] = __v & 0xFF; |
|
3673 |
cp[1] = (__v >> 8) & 0xFF; |
|
3674 |
#endif |
|
3675 |
} else { |
|
3676 |
cp[0] = (__v >> 8) & 0xFF; |
|
3677 |
cp[1] = __v & 0xFF; |
|
3678 |
} |
|
3679 |
RETURN (anInteger); |
|
3680 |
} |
|
3681 |
} |
|
3682 |
} |
|
3683 |
} |
|
3684 |
badArg: ; |
|
3685 |
%}. |
|
19349 | 3686 |
anInteger >= 0 ifTrue:[ |
19366 | 3687 |
self unsignedInt16At:byteIndex put:anInteger MSB:msb. |
3459 | 3688 |
] ifFalse:[ |
19366 | 3689 |
self unsignedInt16At:byteIndex put:(16r10000 + anInteger) MSB:msb. |
3459 | 3690 |
]. |
19349 | 3691 |
^ anInteger |
3459 | 3692 |
|
3693 |
" |
|
3694 |
|b| |
|
3695 |
b := ByteArray new:4. |
|
19366 | 3696 |
b signedInt16At:1 put:-1. |
3697 |
b signedInt16At:3 put:-2. |
|
3459 | 3698 |
b inspect |
3699 |
" |
|
3700 |
||
3701 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
3323 | 3702 |
! |
3703 |
||
19629 | 3704 |
signedInt16AtLSB:byteIndex |
3705 |
"return the 2-bytes starting at index as a signed Integer. |
|
3706 |
The index is a smalltalk index (i.e. 1-based). |
|
3707 |
The value is retrieved with least significant byte first" |
|
3708 |
||
3709 |
^ self signedInt16At:byteIndex MSB:false |
|
3710 |
||
3711 |
" |
|
3712 |
|b| |
|
3713 |
b := ByteArray new:2. |
|
3714 |
b wordAt:1 put:16rFFFE. |
|
3715 |
b signedInt16AtLSB:1. |
|
3716 |
b signedInt16AtMSB:1. |
|
3717 |
" |
|
3718 |
||
3719 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
3720 |
! |
|
3721 |
||
3722 |
signedInt16AtLSB:index put:anInteger |
|
3723 |
"set the 2-bytes starting at index from the signed Integer value. |
|
3724 |
The index is a smalltalk index (i.e. 1-based). |
|
3725 |
The stored value must be in the range 0 .. 16rFFFF. |
|
3726 |
The value is stored with least significant byte first" |
|
3727 |
||
3728 |
^ self signedInt16At:index put:anInteger MSB:false |
|
3729 |
||
3730 |
" |
|
3731 |
|b| |
|
3732 |
b := ByteArray new:4. |
|
3733 |
b signedInt16At:1 put:16r0102. |
|
3734 |
b signedInt16At:3 put:16r0304. |
|
3735 |
b inspect |
|
3736 |
" |
|
3737 |
||
3738 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
3739 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3740 |
! |
|
3741 |
||
3742 |
signedInt16AtMSB:byteIndex |
|
3743 |
"return the 2-bytes starting at index as a signed Integer. |
|
3744 |
The index is a smalltalk index (i.e. 1-based). |
|
3745 |
The value is retrieved with most significant byte first" |
|
3746 |
||
3747 |
^ self signedInt16At:byteIndex MSB:true |
|
3748 |
||
3749 |
" |
|
3750 |
|b| |
|
3751 |
b := ByteArray new:2. |
|
3752 |
b wordAt:1 put:16rFFFE. |
|
3753 |
b signedInt16AtLSB:1. |
|
3754 |
b signedInt16AtMSB:1. |
|
3755 |
" |
|
3756 |
||
3757 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
3758 |
! |
|
3759 |
||
3760 |
signedInt16AtMSB:index put:anInteger |
|
3761 |
"set the 2-bytes starting at index from the signed Integer value. |
|
3762 |
The index is a smalltalk index (i.e. 1-based). |
|
3763 |
The stored value must be in the range 0 .. 16rFFFF. |
|
3764 |
The value is stored with most significant byte first" |
|
3765 |
||
3766 |
^ self signedInt16At:index put:anInteger MSB:true |
|
3767 |
||
3768 |
" |
|
3769 |
|b| |
|
3770 |
b := ByteArray new:4. |
|
3771 |
b signedInt16At:1 put:16r0102. |
|
3772 |
b signedInt16At:3 put:16r0304. |
|
3773 |
b inspect |
|
3774 |
" |
|
3775 |
||
3776 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
3777 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3778 |
! |
|
3779 |
||
19349 | 3780 |
unsignedInt16At:index |
3323 | 3781 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 3782 |
The index is a smalltalk index (i.e. 1-based). |
19415 | 3783 |
The value is retrieved in the machine's natural byte order" |
19349 | 3784 |
|
3785 |
^ self unsignedInt16At:index MSB:IsBigEndian |
|
3323 | 3786 |
! |
3787 |
||
19366 | 3788 |
unsignedInt16At:byteIndex MSB:msb |
3323 | 3789 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 3790 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 3791 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
19366 | 3792 |
LSB-first (i.e. low 8-bits at lower byte index) if it's false. |
19349 | 3793 |
Notice: |
3794 |
the index is a byte index; thus, this allows for unaligned access to |
|
3795 |
words on any boundary." |
|
3323 | 3796 |
|
13575 | 3797 |
|b1 "{ Class: SmallInteger }" |
3323 | 3798 |
b2 "{ Class: SmallInteger }"| |
3799 |
||
19366 | 3800 |
%{ |
3801 |
/* |
|
3802 |
* handle the most common cases fast ... |
|
3803 |
*/ |
|
3804 |
if (__isSmallInteger(byteIndex)) { |
|
3805 |
unsigned char *cp; |
|
3806 |
INT sz; |
|
3807 |
||
3808 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3809 |
if (cp) { |
|
19415 | 3810 |
INT idx = __intVal(byteIndex) - 1; |
3811 |
||
3812 |
if ((idx >= 0) && ((idx+(2-1)) < sz)) { |
|
19366 | 3813 |
int iVal; |
19506 | 3814 |
|
19366 | 3815 |
cp += idx; |
3816 |
if (msb == false) { |
|
3817 |
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK)) |
|
3818 |
/* |
|
20816 | 3819 |
* aligned or not, we don't care (i386 can do both) |
19366 | 3820 |
*/ |
3821 |
iVal = ((unsigned short *)cp)[0]; |
|
3822 |
#else |
|
3823 |
iVal = (cp[0] & 0xFF) | ((cp[1] & 0xFF) << 8); |
|
3824 |
#endif |
|
3825 |
} else { |
|
3826 |
iVal = ((cp[0] & 0xFF) << 8) | (cp[1] & 0xFF); |
|
3827 |
} |
|
3828 |
RETURN (__mkSmallInteger(iVal)); |
|
3829 |
} |
|
3830 |
} |
|
3831 |
} |
|
3832 |
%}. |
|
3833 |
||
3834 |
b1 := self byteAt:byteIndex. |
|
3835 |
b2 := self byteAt:(byteIndex + 1). |
|
3323 | 3836 |
msb ifTrue:[ |
19046 | 3837 |
^ (b1 bitShift:8) + b2 |
3323 | 3838 |
]. |
3839 |
^ (b2 bitShift:8) + b1 |
|
19415 | 3840 |
|
3841 |
" |
|
3842 |
#[ 16rFF 16r00 ] unsignedInt16At:1 MSB:true |
|
3843 |
#[ 16rFF 16r00 ] unsignedInt16At:1 MSB:false |
|
3844 |
||
3845 |
#[ 16rFF 16r00 ] unsignedInt16At:2 MSB:true |
|
3846 |
#[ 16rFF 16r00 ] unsignedInt16At:2 MSB:false |
|
3847 |
" |
|
3323 | 3848 |
! |
3849 |
||
19349 | 3850 |
unsignedInt16At:index put:anInteger |
3323 | 3851 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 3852 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 3853 |
The stored value must be in the range 0 .. 16rFFFF. |
19415 | 3854 |
The value is stored in the machine's natural byteorder." |
3323 | 3855 |
|
19349 | 3856 |
^ self unsignedInt16At:index put:anInteger MSB:IsBigEndian |
3323 | 3857 |
|
3858 |
" |
|
3859 |
|b| |
|
3860 |
b := ByteArray new:4. |
|
19349 | 3861 |
b unsignedInt16At:1 put:16r0102. |
3862 |
b unsignedInt16At:3 put:16r0304. |
|
13575 | 3863 |
b inspect |
3323 | 3864 |
" |
3865 |
||
3866 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
3867 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3868 |
! |
|
3869 |
||
19366 | 3870 |
unsignedInt16At:byteIndex put:anInteger MSB:msb |
3323 | 3871 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 3872 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 3873 |
The stored value must be in the range 0 .. 16rFFFF. |
3323 | 3874 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
3875 |
lower index) if msb is false, MSB-first otherwise" |
|
3876 |
||
3877 |
|b1 b2 |
|
3878 |
iVal "{ Class: SmallInteger }"| |
|
3879 |
||
19366 | 3880 |
%{ /* NOCONTEXT */ |
3881 |
/* |
|
3882 |
* handle the most common case fast ... |
|
3883 |
*/ |
|
3884 |
if (__isSmallInteger(byteIndex)) { |
|
3885 |
unsigned char *cp; |
|
3886 |
INT sz; |
|
3887 |
||
3888 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
19404 | 3889 |
// printf("cp=%"_lx_"\n", (INT)cp); |
19366 | 3890 |
if (cp) { |
19415 | 3891 |
INT idx = __intVal(byteIndex) - 1; |
3892 |
||
3893 |
if ((idx >= 0) && ((idx+1) < sz)) { |
|
19366 | 3894 |
cp += idx; |
3895 |
||
3896 |
if (__isSmallInteger(anInteger)) { |
|
3897 |
INT __v = __intVal(anInteger); |
|
3898 |
||
3899 |
if (((unsigned INT)__v) > 0xFFFF) { |
|
3900 |
goto badArg; |
|
3901 |
} |
|
3902 |
if (msb == false) { |
|
3903 |
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK)) |
|
3904 |
((unsigned short *)cp)[0] = (unsigned short)__v; |
|
3905 |
#else |
|
3906 |
cp[0] = __v & 0xFF; |
|
3907 |
cp[1] = (__v >> 8) & 0xFF; |
|
3908 |
#endif |
|
3909 |
} else { |
|
3910 |
cp[0] = (__v >> 8) & 0xFF; |
|
3911 |
cp[1] = __v & 0xFF; |
|
3912 |
} |
|
3913 |
RETURN (anInteger); |
|
3914 |
} |
|
3915 |
} |
|
3916 |
} |
|
3917 |
} |
|
3918 |
badArg: ; |
|
3919 |
%}. |
|
19349 | 3920 |
iVal := anInteger. |
3323 | 3921 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
19046 | 3922 |
^ self elementBoundsError:iVal |
3323 | 3923 |
]. |
3924 |
msb ifTrue:[ |
|
19046 | 3925 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
3926 |
b2 := (iVal bitAnd:16rFF). |
|
3323 | 3927 |
] ifFalse:[ |
19046 | 3928 |
b1 := (iVal bitAnd:16rFF). |
3929 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
|
3323 | 3930 |
]. |
19366 | 3931 |
self byteAt:byteIndex put:b1. |
3932 |
self byteAt:byteIndex+1 put:b2. |
|
19349 | 3933 |
^ anInteger |
3323 | 3934 |
|
3935 |
" |
|
3936 |
|b| |
|
3937 |
b := ByteArray new:8. |
|
19366 | 3938 |
b unsignedInt16At:1 put:16r0102 MSB:false. |
3939 |
b unsignedInt16At:3 put:16r0304 MSB:false. |
|
3940 |
b unsignedInt16At:5 put:16r0102 MSB:true. |
|
3941 |
b unsignedInt16At:7 put:16r0304 MSB:true. |
|
13575 | 3942 |
b inspect |
3323 | 3943 |
" |
3944 |
||
3945 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
3946 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
19629 | 3947 |
! |
3948 |
||
3949 |
unsignedInt16AtLSB:byteIndex |
|
3950 |
"return the 2-bytes starting at index as an unsigned Integer. |
|
3951 |
The index is a smalltalk index (i.e. 1-based). |
|
3952 |
The value is retrieved with least significant byte first" |
|
3953 |
||
3954 |
^ self unsignedInt16At:byteIndex MSB:false |
|
3955 |
||
3956 |
" |
|
3957 |
|b| |
|
3958 |
b := ByteArray new:2. |
|
3959 |
b wordAt:1 put:16rFFFE. |
|
3960 |
b unsignedInt16AtLSB:1. |
|
3961 |
b unsignedInt16AtMSB:1. |
|
3962 |
" |
|
3963 |
||
3964 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
3965 |
! |
|
3966 |
||
3967 |
unsignedInt16AtLSB:index put:anInteger |
|
3968 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
3969 |
The index is a smalltalk index (i.e. 1-based). |
|
3970 |
The stored value must be in the range 0 .. 16rFFFF. |
|
3971 |
The value is stored with least significant byte first" |
|
3972 |
||
3973 |
^ self unsignedInt16At:index put:anInteger MSB:false |
|
3974 |
||
3975 |
" |
|
3976 |
|b| |
|
3977 |
b := ByteArray new:4. |
|
3978 |
b unsignedInt16At:1 put:16r0102. |
|
3979 |
b unsignedInt16At:3 put:16r0304. |
|
3980 |
b inspect |
|
3981 |
" |
|
3982 |
||
3983 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
3984 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3985 |
! |
|
3986 |
||
3987 |
unsignedInt16AtMSB:byteIndex |
|
3988 |
"return the 2-bytes starting at index as an unsigned Integer. |
|
3989 |
The index is a smalltalk index (i.e. 1-based). |
|
3990 |
The value is retrieved with most significant byte first" |
|
3991 |
||
3992 |
^ self unsignedInt16At:byteIndex MSB:true |
|
3993 |
||
3994 |
" |
|
3995 |
|b| |
|
3996 |
b := ByteArray new:2. |
|
3997 |
b wordAt:1 put:16rFFFF. |
|
3998 |
b signedWordAt:1 |
|
3999 |
" |
|
4000 |
||
4001 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
4002 |
! |
|
4003 |
||
4004 |
unsignedInt16AtMSB:index put:anInteger |
|
4005 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
4006 |
The index is a smalltalk index (i.e. 1-based). |
|
4007 |
The stored value must be in the range 0 .. 16rFFFF. |
|
4008 |
The value is stored with most significant byte first" |
|
4009 |
||
4010 |
^ self unsignedInt16At:index put:anInteger MSB:true |
|
4011 |
||
4012 |
" |
|
4013 |
|b| |
|
4014 |
b := ByteArray new:4. |
|
4015 |
b unsignedInt16At:1 put:16r0102. |
|
4016 |
b unsignedInt16At:3 put:16r0304. |
|
4017 |
b inspect |
|
4018 |
" |
|
4019 |
||
4020 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
4021 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3459 | 4022 |
! ! |
4023 |
||
4024 |
!UninterpretedBytes methodsFor:'accessing-strings'! |
|
4025 |
||
4026 |
stringAt:index |
|
4027 |
"return a string starting at index up to the 0-byte. |
|
4028 |
The index is a smalltalk index (i.e. 1-based)." |
|
4029 |
||
4030 |
|stream i "{ Class: SmallInteger }" c| |
|
4031 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4032 |
stream := WriteStream on:(String new:40). |
3459 | 4033 |
i := index. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4034 |
[(c := self byteAt:i) ~~ 0] whileTrue:[ |
19368 | 4035 |
stream nextPut:(Character value:c). |
4036 |
i := i + 1. |
|
3459 | 4037 |
]. |
4038 |
^ stream contents |
|
4039 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4040 |
" |
13575 | 4041 |
#[71 72 73 74 75 76 77 0] stringAt:1 |
4042 |
#[71 72 73 74 75 76 77 0] stringAt:2 |
|
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4043 |
'1234567890' stringAt:2 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4044 |
" |
3459 | 4045 |
! |
4046 |
||
4047 |
stringAt:index put:aString |
|
19196 | 4048 |
"copy aString to the receiver, starting at index up to |
7815 | 4049 |
(and including) the 0-byte (which is always written). |
3459 | 4050 |
The index is a smalltalk index (i.e. 1-based)." |
4051 |
||
4052 |
|i "{ Class: SmallInteger }"| |
|
4053 |
||
4054 |
i := index. |
|
4055 |
aString do:[:aChar | |
|
19196 | 4056 |
self byteAt:i put:aChar codePoint. |
4057 |
i := i + 1. |
|
3459 | 4058 |
]. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4059 |
self byteAt:i put:0. |
3459 | 4060 |
^ aString |
4061 |
||
4062 |
" |
|
4063 |
|bytes| |
|
4064 |
||
4065 |
bytes := ExternalBytes new:10. |
|
4066 |
bytes stringAt:1 put:'hello'. |
|
4067 |
1 to:bytes size do:[:i | |
|
19196 | 4068 |
Transcript showCR:(bytes at:i) |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4069 |
]. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4070 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4071 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4072 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4073 |
(String new:20) stringAt:1 put:'hello'; stringAt:6 put:' world'; yourself |
3459 | 4074 |
" |
4075 |
||
4076 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
|
4077 |
! |
|
4078 |
||
7812 | 4079 |
stringAt:index put:aString size:maxSize |
19196 | 4080 |
"copy aString to the receiver, starting at index up to either maxSize characters, |
7812 | 4081 |
or (and including) the 0-byte, whichever is encountered first. |
7815 | 4082 |
The final 0-byte is only written, if the string is shorter than maxSize. |
7812 | 4083 |
The index is a smalltalk index (i.e. 1-based)." |
4084 |
||
4085 |
|remaining "{ Class: SmallInteger }" |
|
4086 |
i "{ Class: SmallInteger }"| |
|
4087 |
||
4088 |
remaining := maxSize. |
|
7816 | 4089 |
remaining <= 0 ifTrue:[^ aString]. |
7812 | 4090 |
|
4091 |
i := index. |
|
4092 |
aString do:[:aChar | |
|
19196 | 4093 |
self byteAt:i put:aChar codePoint. |
4094 |
i := i + 1. |
|
4095 |
remaining := remaining - 1. |
|
4096 |
remaining <= 0 ifTrue:[^ aString]. |
|
7812 | 4097 |
]. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4098 |
self byteAt:i put:0. |
7812 | 4099 |
^ aString |
4100 |
||
4101 |
" |
|
4102 |
|bytes| |
|
4103 |
||
4104 |
bytes := ExternalBytes new:10. |
|
4105 |
bytes stringAt:1 put:'hello' size:3. |
|
4106 |
1 to:bytes size do:[:i | |
|
19196 | 4107 |
Transcript showCR:(bytes at:i) |
7812 | 4108 |
] |
4109 |
" |
|
4110 |
" |
|
4111 |
|bytes| |
|
4112 |
||
4113 |
bytes := ByteArray new:10 withAll:16rFF. |
|
4114 |
bytes stringAt:1 put:'he' size:3. |
|
4115 |
1 to:bytes size do:[:i | |
|
19196 | 4116 |
Transcript showCR:(bytes at:i) |
7812 | 4117 |
] |
4118 |
" |
|
4119 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4120 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4121 |
(String new:20) stringAt:1 put:'hello' size:3 ; stringAt:4 put:' world' size:4; yourself |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4122 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4123 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4124 |
|
7812 | 4125 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
4126 |
! |
|
4127 |
||
3459 | 4128 |
stringAt:index size:maxSize |
4129 |
"return a string starting at index up to maxSize, or a 0-byte. |
|
4130 |
The index is a smalltalk index (i.e. 1-based)." |
|
4131 |
||
13575 | 4132 |
|stream c |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4133 |
max "{ Class: SmallInteger }" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4134 |
start "{ Class: SmallInteger }"| |
3459 | 4135 |
|
4136 |
stream := WriteStream on:(String new:maxSize). |
|
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4137 |
start := index. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4138 |
max := start + maxSize - 1. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4139 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4140 |
start to:max do:[:eachIndex| |
19368 | 4141 |
c := self byteAt:eachIndex. |
4142 |
c == 0 ifTrue:[ |
|
4143 |
^ stream contents |
|
4144 |
]. |
|
4145 |
stream nextPut:(Character value:c). |
|
3459 | 4146 |
]. |
4147 |
^ stream contents |
|
4148 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4149 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4150 |
#[71 72 73 74 75 76 77] stringAt:1 size:7 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4151 |
#[71 72 73 74 75 76 77] stringAt:2 size:6 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4152 |
'1234567890' stringAt:2 size:6 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
4153 |
" |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4154 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4155 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4156 |
zeroByteStringAt:index maximumSize:count |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4157 |
"extract a zeroByte-delimited string, given initial index and |
3433 | 4158 |
maximum number of characters (bytes). |
4159 |
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
|
4160 |
|
19415 | 4161 |
|bytes endIndex idx| |
4162 |
||
4163 |
endIndex := self indexOf:0 startingAt:index. |
|
4164 |
endIndex == 0 ifTrue:[ |
|
4165 |
endIndex := self size + 1 |
|
4166 |
]. |
|
4167 |
endIndex := (endIndex min: (index + count)) - 1. |
|
4168 |
bytes := self copyFrom:index to:endIndex. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4169 |
^ bytes asString |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4170 |
|
19415 | 4171 |
" |
4172 |
#[ 1 2 3 4 5 6 7 8 ] zeroByteStringAt:2 maximumSize:10 |
|
4173 |
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:10 |
|
4174 |
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:3 |
|
4175 |
#[ 1 2 3 4 5 0 6 7 8 ] zeroByteStringAt:2 maximumSize:4 |
|
4176 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4177 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
4178 |
|
12951 | 4179 |
!UninterpretedBytes methodsFor:'converting'! |
4180 |
||
4181 |
asExternalBytes |
|
4182 |
|sz bytes| |
|
4183 |
||
14142 | 4184 |
sz := self byteSize. |
12951 | 4185 |
bytes := ExternalBytes unprotectedNew:sz. |
4186 |
bytes replaceBytesFrom:1 to:sz with:self startingAt:1. |
|
4187 |
^ bytes |
|
4188 |
||
4189 |
" |
|
4190 |
#[1 2 3 4 5 6 7] asExternalBytes |
|
4191 |
'Hello World' asExternalBytes |
|
14142 | 4192 |
'Hello World' asUnicodeString asExternalBytes |
12951 | 4193 |
" |
14132 | 4194 |
! |
4195 |
||
14155 | 4196 |
asExternalBytesUnprotected |
4197 |
"Like asExternalBytes, but does not register the bytes so |
|
15836 | 4198 |
bytes are GARBAGE-COLLECTED." |
14155 | 4199 |
|
4200 |
|bytes sz| |
|
4201 |
||
4202 |
sz := self byteSize. |
|
15836 | 4203 |
bytes := ExternalBytes unprotectedNew:sz. |
14155 | 4204 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
4205 |
^ bytes |
|
4206 |
||
4207 |
" |
|
4208 |
|x| |
|
4209 |
x := 'fooBar' asExternalBytesUnprotected. |
|
4210 |
ObjectMemory garbageCollect |
|
4211 |
" |
|
4212 |
||
4213 |
"Created: / 05-06-2012 / 14:11:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15836 | 4214 |
"Modified: / 30-11-2013 / 11:42:21 / cg" |
14155 | 4215 |
! |
4216 |
||
18600 | 4217 |
asSingleByteString |
4218 |
"return the receiver converted to a 'normal' string. |
|
4219 |
Raises an error if unrepresentable characters are encountered. |
|
4220 |
See also: asSingleByteStringIfPossible and asSingleByteStringReplaceInvalidWith:" |
|
4221 |
||
4222 |
^ String fromString:self |
|
4223 |
||
4224 |
" |
|
4225 |
#[60 61 62 63] asSingleByteString |
|
18616 | 4226 |
#[60 61 62 63] asExternalBytes asSingleByteString |
18969 | 4227 |
#[67 68 69 70] asIntegerArray asSingleByteString |
18600 | 4228 |
(Unicode16String with:(Character value:16rFF)) asSingleByteString |
4229 |
(Unicode16String with:(Character value:16rFFFF)) asSingleByteString |
|
4230 |
" |
|
4231 |
! |
|
4232 |
||
18969 | 4233 |
asSingleByteStringIfPossible |
4234 |
"if possible, return the receiver converted to a 'normal' string. |
|
4235 |
It is only possible, if there are no characters with codePoints above 255 in the receiver. |
|
4236 |
If not possible, the (wideString) receiver is returned." |
|
4237 |
||
4238 |
self containsNon8BitElements ifTrue:[^ self asString]. |
|
4239 |
^ self asSingleByteString. |
|
4240 |
||
4241 |
" |
|
4242 |
#[67 68 69 70] asSingleByteStringIfPossible |
|
4243 |
#[67 68 69 70] asIntegerArray asSingleByteStringIfPossible |
|
4244 |
'hello' asUnicodeString asSingleByteStringIfPossible |
|
4245 |
" |
|
4246 |
! |
|
4247 |
||
14132 | 4248 |
asUUID |
4249 |
^ UUID fromBytes:self |
|
12951 | 4250 |
! ! |
4251 |
||
18616 | 4252 |
!UninterpretedBytes methodsFor:'encoding & decoding'! |
4253 |
||
4254 |
utf8Decoded |
|
4255 |
"Interpreting myself as an UTF-8 representation, decode and return the decoded string." |
|
4256 |
||
4257 |
^ CharacterArray decodeFromUTF8:self. |
|
4258 |
||
4259 |
" |
|
4260 |
#[16rC8 16rA0] utf8Decoded |
|
4261 |
#[16rC8 16rA0] asString utf8Decoded |
|
4262 |
#[16rC8 16rA0] asExternalBytes utf8Decoded |
|
4263 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
4264 |
||
4265 |
(Character value:16r800) utf8Encoded |
|
4266 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
4267 |
" |
|
4268 |
||
4269 |
"test: |
|
4270 |
||
4271 |
|utf8Encoding original readBack| |
|
4272 |
||
4273 |
1 to:16rFFFF do:[:ascii | |
|
19368 | 4274 |
original := (Character value:ascii) asString. |
4275 |
utf8Encoding := original utf8Encoded. |
|
4276 |
readBack := utf8Encoding utf8Decoded. |
|
4277 |
readBack = original ifFalse:[ |
|
4278 |
self halt |
|
4279 |
] |
|
18616 | 4280 |
] |
4281 |
" |
|
4282 |
! |
|
4283 |
||
4284 |
utf8DecodedWithTwoByteCharactersReplacedBy:replacementCharacter |
|
4285 |
"Interpreting myself as an UTF-8 representation, decode and return |
|
4286 |
the decoded string. Suppress all 2-byte (above 16rFF) characters, |
|
4287 |
and replace them with replacementCharacter" |
|
4288 |
||
4289 |
|in out c| |
|
4290 |
||
4291 |
self containsNon7BitAscii ifFalse:[ |
|
19368 | 4292 |
^ self asSingleByteString |
18616 | 4293 |
]. |
4294 |
||
4295 |
out := WriteStream on:(String uninitializedNew:self size * 3 // 2). |
|
4296 |
in := self readStream. |
|
4297 |
[in atEnd] whileFalse:[ |
|
19368 | 4298 |
c := Character utf8DecodeFrom:in. |
4299 |
c codePoint > 16rFF ifTrue:[ |
|
4300 |
c := replacementCharacter |
|
4301 |
]. |
|
4302 |
out nextPut:c. |
|
18616 | 4303 |
]. |
4304 |
^ out contents |
|
4305 |
||
4306 |
" |
|
4307 |
(Character value:16r220) utf8Encoded |
|
19368 | 4308 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
18616 | 4309 |
|
4310 |
(Character value:16r220) utf8Encoded asExternalBytes copyButLast |
|
19368 | 4311 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
18616 | 4312 |
" |
4313 |
! ! |
|
4314 |
||
4782 | 4315 |
!UninterpretedBytes methodsFor:'filling & replacing'! |
4316 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4317 |
replaceBytesFrom:start to:stop with:aCollection startingAt:repStart |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4318 |
"replace elements from another collection, which must be a ByteArray- |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4319 |
like collection. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4320 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4321 |
Notice: This operation modifies the receiver, NOT a copy; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4322 |
therefore the change may affect all others referencing the receiver." |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4323 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4324 |
%{ /* NOCONTEXT */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4325 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4326 |
int nIndex, repNIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4327 |
int startIndex, stopIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4328 |
REGISTER unsigned char *src; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4329 |
REGISTER int repStartIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4330 |
int repStopIndex, count; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4331 |
REGISTER unsigned char *dst; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4332 |
OBJ cls; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4333 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4334 |
#ifndef NO_PRIM_BYTEARR |
14082 | 4335 |
if ((__isBytes(aCollection) || __isExternalBytesLike(aCollection)) |
14142 | 4336 |
&& (__isBytes(self) || __isWords(self)) |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4337 |
&& __bothSmallInteger(start, stop) |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4338 |
&& __isSmallInteger(repStart)) { |
19368 | 4339 |
startIndex = __intVal(start) - 1; |
4340 |
if (startIndex >= 0) { |
|
4341 |
dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex; |
|
4342 |
nIndex = __byteArraySize(self); |
|
4343 |
||
4344 |
if ((cls = __qClass(self)) != @global(ByteArray)) { |
|
4345 |
int nInst; |
|
4346 |
||
4347 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
4348 |
dst += nInst; |
|
4349 |
nIndex -= nInst; |
|
4350 |
} |
|
4351 |
||
4352 |
stopIndex = __intVal(stop) - 1; |
|
4353 |
count = stopIndex - startIndex + 1; |
|
4354 |
if (count == 0) { |
|
4355 |
RETURN ( self ); |
|
4356 |
} |
|
4357 |
||
4358 |
if ((count > 0) && (stopIndex < nIndex)) { |
|
4359 |
repStartIndex = __intVal(repStart) - 1; |
|
4360 |
if (repStartIndex >= 0) { |
|
4361 |
if (__isExternalBytesLike(aCollection)) { |
|
4362 |
OBJ sz; |
|
4363 |
||
4364 |
src = __externalAddressVal(aCollection); |
|
4365 |
if (src == 0) goto fallBack; |
|
4366 |
||
4367 |
sz = __externalBytesSize(aCollection); |
|
4368 |
if (__isSmallInteger(sz)) { |
|
4369 |
repNIndex = __smallIntegerVal(sz); |
|
4370 |
} else { |
|
4371 |
repNIndex = repStopIndex+1; /* always enough */ |
|
4372 |
} |
|
4373 |
src = src + repStartIndex; |
|
4374 |
} else { |
|
4375 |
if (__isStringLike(aCollection)) { |
|
4376 |
repNIndex = __stringSize(aCollection); |
|
4377 |
} else { |
|
4378 |
repNIndex = __qSize(aCollection) - OHDR_SIZE; |
|
4379 |
} |
|
4380 |
src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex; |
|
4381 |
if ((cls = __qClass(aCollection)) != @global(ByteArray)) { |
|
4382 |
int nInst; |
|
4383 |
||
4384 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
4385 |
src += nInst; |
|
4386 |
repNIndex -= nInst; |
|
4387 |
} |
|
4388 |
} |
|
4389 |
repStopIndex = repStartIndex + (stopIndex - startIndex); |
|
4390 |
if (repStopIndex < repNIndex) { |
|
4391 |
if (aCollection == self) { |
|
4392 |
/* take care of overlapping copy */ |
|
4393 |
if (src < dst) { |
|
4394 |
/* must do a reverse copy */ |
|
4395 |
src += count; |
|
4396 |
dst += count; |
|
4397 |
while (count-- > 0) { |
|
4398 |
*--dst = *--src; |
|
4399 |
} |
|
4400 |
RETURN ( self ); |
|
4401 |
} |
|
4402 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4403 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4404 |
# ifdef bcopy4 |
19368 | 4405 |
if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) { |
4406 |
int nW; |
|
4407 |
||
4408 |
/* copy unaligned part */ |
|
4409 |
while (count && ((unsigned INT)src & 3)) { |
|
4410 |
*dst++ = *src++; |
|
4411 |
count--; |
|
4412 |
} |
|
4413 |
||
4414 |
if (count > 0) { |
|
4415 |
/* copy aligned part */ |
|
4416 |
nW = count >> 2; |
|
4417 |
bcopy4(src, dst, nW); |
|
4418 |
if ((count = count & 3) != 0) { |
|
4419 |
/* copy any remaining part */ |
|
4420 |
src += (nW<<2); |
|
4421 |
dst += (nW<<2); |
|
4422 |
while (count--) { |
|
4423 |
*dst++ = *src++; |
|
4424 |
} |
|
4425 |
} |
|
4426 |
} |
|
4427 |
RETURN ( self ); |
|
4428 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4429 |
# else |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4430 |
# if __POINTER_SIZE__ == 8 |
19368 | 4431 |
if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) { |
4432 |
/* copy unaligned part */ |
|
4433 |
while (count && ((unsigned INT)src & 7)) { |
|
4434 |
*dst++ = *src++; |
|
4435 |
count--; |
|
4436 |
} |
|
4437 |
||
4438 |
/* copy aligned part */ |
|
4439 |
while (count >= 8) { |
|
4440 |
((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0]; |
|
4441 |
dst += 8; |
|
4442 |
src += 8; |
|
4443 |
count -= 8; |
|
4444 |
} |
|
4445 |
while (count--) { |
|
4446 |
*dst++ = *src++; |
|
4447 |
} |
|
4448 |
RETURN ( self ); |
|
4449 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4450 |
# endif /* 64bit */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4451 |
# endif /* bcopy4 */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4452 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4453 |
# ifdef FAST_MEMCPY |
19368 | 4454 |
bcopy(src, dst, count); |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4455 |
# else |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4456 |
# ifdef __UNROLL_LOOPS__ |
19368 | 4457 |
while (count >= 8) { |
4458 |
dst[0] = src[0]; dst[1] = src[1]; |
|
4459 |
dst[2] = src[2]; dst[3] = src[3]; |
|
4460 |
dst[4] = src[4]; dst[5] = src[5]; |
|
4461 |
dst[6] = src[6]; dst[7] = src[7]; |
|
4462 |
dst += 8; src += 8; |
|
4463 |
count -= 8; |
|
4464 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4465 |
# endif /* __UNROLL_LOOPS__ */ |
19368 | 4466 |
while (count-- > 0) { |
4467 |
*dst++ = *src++; |
|
4468 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4469 |
# endif |
19368 | 4470 |
RETURN ( self ); |
4471 |
} |
|
4472 |
} |
|
4473 |
} |
|
4474 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4475 |
} |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4476 |
fallBack: ; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4477 |
#endif |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4478 |
%}. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4479 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4480 |
fall back in case of non-ByteArray argument, |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4481 |
or for the error report if any index is invalid |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4482 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4483 |
self slowReplaceBytesFrom:start to:stop with:aCollection startingAt:repStart |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4484 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4485 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4486 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4487 |
copy |
4488 |
replaceFrom:1 to:8 |
|
4489 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4490 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4491 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4492 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4493 |
copy |
4494 |
replaceFrom:3 to:10 |
|
4495 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4496 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4497 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4498 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4499 |
copy |
4500 |
replaceFrom:3 to:4 |
|
4501 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4502 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4503 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4504 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4505 |
copy |
4506 |
replaceFrom:0 to:9 |
|
4507 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4508 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4509 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4510 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
19368 | 4511 |
copy |
4512 |
replaceFrom:1 to:10 |
|
4513 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
4514 |
startingAt:0 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4515 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4516 |
! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4517 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4518 |
replaceBytesFrom:startIndex with:replacementCollection startingAt:repStartIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4519 |
"replace elements from another collection, which must be |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4520 |
byte-array-like. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4521 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4522 |
Notice: This operation modifies the receiver, NOT a copy; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4523 |
therefore the change may affect all others referencing the receiver." |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4524 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4525 |
^ self |
19368 | 4526 |
replaceBytesFrom:startIndex |
4527 |
to:(startIndex + replacementCollection size - repStartIndex) |
|
4528 |
with:replacementCollection |
|
4529 |
startingAt:repStartIndex |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4530 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4531 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4532 |
args: startIndex : <integer> |
19368 | 4533 |
replacementCollection : <collection of <bytes> > |
4534 |
repStartIndex : <integer> |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4535 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4536 |
returns: self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4537 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4538 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4539 |
"Created: / 27.7.1998 / 16:56:46 / cg" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4540 |
"Modified: / 27.7.1998 / 16:58:38 / cg" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4541 |
! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4542 |
|
13902 | 4543 |
replaceBytesWith:replacementCollection |
4544 |
"replace elements from another collection, which must be byte-array-like. |
|
4545 |
Replace stops at whichever collection is smaller. |
|
4546 |
||
4547 |
Notice: This operation modifies the receiver, NOT a copy; |
|
4548 |
therefore the change may affect all others referencing the receiver." |
|
4549 |
||
4550 |
^ self |
|
19368 | 4551 |
replaceBytesFrom:1 |
4552 |
to:(replacementCollection size min:self size) |
|
4553 |
with:replacementCollection |
|
4554 |
startingAt:1 |
|
13902 | 4555 |
|
4556 |
" |
|
15004 | 4557 |
(ByteArray new:10) replaceBytesWith:'hello' |
4558 |
(ByteArray new:10) replaceBytesWith:'hello world bla bla bla' |
|
13902 | 4559 |
" |
4560 |
||
4561 |
"Created: / 09-01-2012 / 16:18:10 / cg" |
|
4562 |
! |
|
4563 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4564 |
replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4565 |
"replace elements in the receiver between index start and stop, |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4566 |
with elements taken from replacementCollection starting at repStart. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4567 |
Return the receiver. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4568 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4569 |
Notice: This operation modifies the receiver, NOT a copy; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4570 |
therefore the change may affect all others referencing the receiver." |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4571 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
4572 |
self class isBytes ifTrue:[ |
19368 | 4573 |
((aCollection class == self class) |
4574 |
or:[aCollection isByteCollection]) ifTrue:[ |
|
4575 |
^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex |
|
4576 |
]. |
|
7252
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
4577 |
]. |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4578 |
^ super replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4579 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4580 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4581 |
args: startIndex : <integer> |
19368 | 4582 |
stopIndex : <integer> |
4583 |
replacementCollection : <collection of <bytes> > |
|
4584 |
repStartIndex : <integer> |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4585 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4586 |
returns: self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4587 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4588 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
4589 |
"Modified: / 08-05-2012 / 13:23:27 / cg" |
4782 | 4590 |
! ! |
4591 |
||
12757 | 4592 |
!UninterpretedBytes methodsFor:'hashing'! |
4593 |
||
4594 |
computeXorHashFrom:startIndex to:endIndex |
|
20372 | 4595 |
"compute and answer the 32bit SmallInteger-Hash of the bytes |
12757 | 4596 |
from startIndex to endIndex. |
4597 |
If endindex = 0 or endIndex > size, hash up the size. |
|
4598 |
||
4599 |
NOTE: startIndex and endIndex are only hints about what should be hashed. |
|
19368 | 4600 |
In fact, more bytes could be involved in hashing. |
20372 | 4601 |
SO ARRAYS MUST BE EQUAL TO HASH TO THE SAME VALUE. |
4602 |
||
4603 |
Also NOTE: |
|
4604 |
used to return a 32bit hash on 32bit machines and a 64bit integer on 64bit cpus. |
|
4605 |
changed to return the same for all (in case hash values are used for other purposes)." |
|
12757 | 4606 |
|
4607 |
|w| |
|
4608 |
||
4609 |
%{ |
|
4610 |
if (__bothSmallInteger(startIndex, endIndex)) { |
|
19368 | 4611 |
unsigned char *cp; |
4612 |
INT sz; |
|
4613 |
||
4614 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
4615 |
if (cp) { |
|
4616 |
INT sidx = ((unsigned INT)__smallIntegerVal(startIndex)) - 1; |
|
4617 |
INT eidx = ((unsigned INT)__smallIntegerVal(endIndex)) - 1; |
|
20372 | 4618 |
// # define H_INT INT |
4619 |
// # define _MAX_H_INT _MAX_INT; |
|
4620 |
# define H_INT int |
|
4621 |
# define _MAX_H_INT 0x3FFFFFFF |
|
4622 |
||
19368 | 4623 |
unsigned char *ep; |
20372 | 4624 |
unsigned H_INT hash = 0, hash2 = 0, carry; |
19368 | 4625 |
int i; |
4626 |
||
4627 |
if (eidx < 0 || eidx >= sz) eidx = sz - 1; |
|
4628 |
if (sidx > eidx) sidx = eidx; |
|
4629 |
if (sidx < 0) { |
|
4630 |
RETURN(__mkSmallInteger(0)); |
|
4631 |
} |
|
4632 |
||
4633 |
ep = cp + eidx; |
|
4634 |
cp += sidx; |
|
12757 | 4635 |
|
4636 |
#if 0 |
|
19368 | 4637 |
/* |
4638 |
* On LSB-First (little endian) cpus, |
|
4639 |
* this code does not produce the same result |
|
4640 |
* if the same bytes are at different positions |
|
4641 |
*/ |
|
4642 |
||
20372 | 4643 |
if ((H_INT)cp & (sizeof(H_INT)-1)) { |
19368 | 4644 |
/* not aligned */ |
4645 |
||
4646 |
for (i=0; cp <= ep; cp++) { |
|
4647 |
hash2 = (hash2 << 8) | *cp; |
|
20372 | 4648 |
if (++i == sizeof(H_INT)) { |
19368 | 4649 |
hash ^= hash2; |
4650 |
i = hash2 = 0; |
|
4651 |
} |
|
4652 |
} |
|
4653 |
} else { |
|
4654 |
/* aligned */ |
|
20372 | 4655 |
for (; cp+sizeof(H_INT) <= ep; cp += sizeof(H_INT)) { |
4656 |
hash ^= *(unsigned H_INT *)cp; |
|
19368 | 4657 |
} |
4658 |
for (; cp <= ep; cp++) { |
|
4659 |
hash2 = (hash2 << 8) | *cp; |
|
4660 |
} |
|
4661 |
} |
|
12757 | 4662 |
#else |
20372 | 4663 |
for (i=0; cp <= ep-sizeof(H_INT); cp += sizeof(H_INT)) { |
19368 | 4664 |
hash2 = cp[0]; |
4665 |
hash2 = (hash2 << 8) | cp[1]; |
|
4666 |
hash2 = (hash2 << 8) | cp[2]; |
|
4667 |
hash2 = (hash2 << 8) | cp[3]; |
|
20373 | 4668 |
# if 0 |
20372 | 4669 |
if (sizeof(H_INT) == 8) { |
4670 |
hash2 = (hash2 << 8) | cp[4]; |
|
4671 |
hash2 = (hash2 << 8) | cp[5]; |
|
4672 |
hash2 = (hash2 << 8) | cp[6]; |
|
4673 |
hash2 = (hash2 << 8) | cp[7]; |
|
4674 |
} |
|
20373 | 4675 |
# endif |
19368 | 4676 |
/* |
4677 |
* multiply by large prime to scramble bits and |
|
4678 |
* to avoid a 0 result from |
|
4679 |
* #[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8. |
|
4680 |
*/ |
|
4681 |
hash ^= (hash * 31415821) ^ hash2; |
|
4682 |
} |
|
4683 |
for (hash2 = 0; cp <= ep; cp++) { |
|
4684 |
hash2 = (hash2 << 8) | *cp; |
|
4685 |
} |
|
12757 | 4686 |
#endif |
19368 | 4687 |
hash ^= (hash * 31415821) ^ hash2; |
4688 |
||
4689 |
/* |
|
20372 | 4690 |
* fold the high bits not fitting into a H_INT |
19368 | 4691 |
*/ |
20372 | 4692 |
carry = hash & ~_MAX_H_INT; |
19368 | 4693 |
if (carry) { |
20372 | 4694 |
hash = (hash & _MAX_H_INT) ^ (carry >> 8); |
19368 | 4695 |
} |
4696 |
||
4697 |
RETURN(__mkSmallInteger(hash)); |
|
4698 |
} |
|
12757 | 4699 |
} |
4700 |
%}. |
|
4701 |
||
4702 |
^ self primitiveFailed |
|
4703 |
||
4704 |
" |
|
4705 |
#[1 2 3 4] computeXorHashFrom:1 to:4. |
|
4706 |
#[1 2 3 4] computeXorHashFrom:1 to:32. |
|
4707 |
#[1 2 3 4] computeXorHashFrom:1 to:0. |
|
4708 |
#[1 2 3 4 5] computeXorHashFrom:1 to:4. |
|
4709 |
#[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8. |
|
20372 | 4710 |
#[1 2 3 4 5 6 7 8] computeXorHashFrom:2 to:8. |
12757 | 4711 |
#[2 3 4 5 6 7 8] computeXorHashFrom:1 to:7. |
19554 | 4712 |
#[2 3 4 5 6 7 8] computeXorHashFrom:1 to:8. |
4713 |
" |
|
4714 |
! |
|
4715 |
||
4716 |
hash |
|
4717 |
|sz| |
|
4718 |
||
4719 |
sz := self size. |
|
4720 |
sz <= 32 ifTrue:[ |
|
4721 |
^ self computeXorHashFrom:1 to:sz. |
|
4722 |
]. |
|
4723 |
^ (sz bitXor:(self computeXorHashFrom:1 to:16)) bitXor:(self computeXorHashFrom:sz-16 to:sz) |
|
4724 |
||
4725 |
" |
|
4726 |
#[1 2 3 4] hash |
|
4727 |
#[1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 |
|
4728 |
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 ] hash |
|
4729 |
#[1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 |
|
4730 |
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1] hash |
|
12757 | 4731 |
" |
4732 |
! ! |
|
4733 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4734 |
!UninterpretedBytes methodsFor:'image manipulation support'! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4735 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4736 |
copyReverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4737 |
"create a copy of myself with elements reversed in order" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4738 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4739 |
^ self copy reverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4740 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4741 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4742 |
#[1 2 3 4 5] copyReverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4743 |
#[1 2 3 4] copyReverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4744 |
" |
19415 | 4745 |
! |
4746 |
||
4747 |
swapBytes |
|
4748 |
"swap bytes (of int16s) inplace - |
|
4749 |
Expects that the receiver has an even number of bytes; |
|
4750 |
if not, only the pairs excluding the last byte are swapped" |
|
4751 |
||
4752 |
|b1 lastIndex "{ Class: SmallInteger }"| |
|
4753 |
||
4754 |
lastIndex := self size-1. |
|
4755 |
1 to:lastIndex by:2 do:[:idx | |
|
4756 |
b1 := self byteAt:idx. |
|
4757 |
self byteAt:idx put:(self byteAt:idx+1). |
|
4758 |
self byteAt:idx+1 put:b1. |
|
4759 |
]. |
|
4760 |
||
4761 |
" |
|
4762 |
#[1 2 3 4 5] swapBytes |
|
4763 |
#[1 2 3 4] swapBytes |
|
4764 |
" |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4765 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4766 |
|
20961 | 4767 |
!UninterpretedBytes methodsFor:'inspecting'! |
4768 |
||
4769 |
inspector2Tabs |
|
4770 |
^ super inspector2Tabs , #( inspector2TabForHexDump ) |
|
4771 |
||
4772 |
"Created: / 27-02-2012 / 21:51:36 / cg" |
|
4773 |
"Modified: / 13-02-2015 / 21:03:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4774 |
! ! |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
4775 |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4776 |
!UninterpretedBytes methodsFor:'misc'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4777 |
|
13575 | 4778 |
swapLongAt:byteIndex |
3433 | 4779 |
"swap the byteOrder of a long. |
4780 |
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
|
4781 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4782 |
|t| |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4783 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4784 |
t := self byteAt:byteIndex. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4785 |
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
|
4786 |
self byteAt:(byteIndex + 3) put:t. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4787 |
t := self byteAt:(byteIndex + 1). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4788 |
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
|
4789 |
self byteAt:(byteIndex + 2) put:t |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4790 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4791 |
"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
|
4792 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4793 |
|
18664 | 4794 |
!UninterpretedBytes methodsFor:'printing & storing'! |
4795 |
||
4796 |
hexPrintOn:aStream |
|
4797 |
"print as hex string, eg: 'FF0243'. |
|
4798 |
This string can be used in #fromHexString: to recreate the byteArray" |
|
4799 |
||
4800 |
self hexPrintOn:aStream withSeparator:nil |
|
4801 |
||
4802 |
" |
|
4803 |
#[1 2 3 4 10 17] hexPrintOn:Transcript |
|
4804 |
" |
|
4805 |
||
4806 |
" |
|
4807 |
|s| |
|
4808 |
s := String streamContents:[:s | #[1 2 3 4 10 17] hexPrintOn:s]. |
|
4809 |
ByteArray fromHexString:s |
|
4810 |
" |
|
4811 |
! |
|
4812 |
||
4813 |
hexPrintOn:aStream withSeparator:aSeparatorStringOrCharacterOrNil |
|
4814 |
"print as hex string with separators, eg: 'FF:02:43'" |
|
4815 |
||
4816 |
|first| |
|
4817 |
||
4818 |
first := true. |
|
4819 |
1 to:self size do:[:idx | |
|
19368 | 4820 |
aSeparatorStringOrCharacterOrNil notNil ifTrue:[ |
4821 |
first ifFalse:[ |
|
4822 |
aSeparatorStringOrCharacterOrNil printOn:aStream |
|
4823 |
] ifTrue:[ |
|
4824 |
first := false. |
|
4825 |
]. |
|
4826 |
]. |
|
4827 |
(self byteAt:idx) printOn:aStream base:16 size:2 fill:$0. |
|
18664 | 4828 |
]. |
4829 |
||
4830 |
" |
|
4831 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:$: |
|
4832 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:(Character space) |
|
4833 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:'-' |
|
4834 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:nil |
|
20177 | 4835 |
'hello' hexPrintOn:Transcript withSeparator:'.' |
18664 | 4836 |
" |
4837 |
! |
|
4838 |
||
4839 |
hexPrintString |
|
4840 |
"print as hex string, eg: 'FF0243'. |
|
4841 |
This string can be used in #fromHexString: to recreate the byteArray" |
|
4842 |
||
4843 |
^ self hexPrintStringWithSeparator:nil |
|
4844 |
||
4845 |
" |
|
4846 |
#[1 2 3 4 10 17] hexPrintString |
|
4847 |
ByteArray fromHexString:#[1 2 3 4 10 17] hexPrintString |
|
20176 | 4848 |
'hello' hexPrintString |
18664 | 4849 |
" |
4850 |
||
4851 |
"Modified: / 03-07-2010 / 01:59:19 / cg" |
|
4852 |
! |
|
4853 |
||
4854 |
hexPrintStringWithSeparator:aSeparatorStringOrCharacterOrNil |
|
4855 |
"print as hex string, eg: 'FF:02:43'." |
|
4856 |
||
4857 |
^ String |
|
19368 | 4858 |
streamContents:[:s | |
4859 |
self hexPrintOn:s withSeparator:aSeparatorStringOrCharacterOrNil. |
|
4860 |
] |
|
18664 | 4861 |
|
4862 |
" |
|
4863 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:$: |
|
4864 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:Character space |
|
4865 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:' - ' |
|
4866 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:nil |
|
20176 | 4867 |
'hello' hexPrintStringWithSeparator:'.' |
18664 | 4868 |
" |
4869 |
! ! |
|
4870 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4871 |
!UninterpretedBytes methodsFor:'private'! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4872 |
|
18969 | 4873 |
slowReplaceBytesFrom:startArg to:stopArg with:sourceBytes startingAt:sourceIndex |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4874 |
"fallback if primitive code fails" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4875 |
|
18969 | 4876 |
|srcIdx "{ Class:SmallInteger }" |
4877 |
start "{ Class:SmallInteger }" |
|
4878 |
stop "{ Class:SmallInteger }"| |
|
4879 |
||
4880 |
start := startArg. |
|
4881 |
stop := stopArg. |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4882 |
srcIdx := sourceIndex. |
18969 | 4883 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4884 |
start to:stop do:[:dstIdx | |
18969 | 4885 |
self at:dstIdx put:(sourceBytes at:srcIdx). |
4886 |
srcIdx := srcIdx + 1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4887 |
]. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4888 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4889 |
|
3323 | 4890 |
!UninterpretedBytes methodsFor:'queries'! |
4891 |
||
18616 | 4892 |
containsNon7BitAscii |
18969 | 4893 |
"return true, if the underlying collection contains elements longer than 7 bits |
18616 | 4894 |
(i.e. if it is non-ascii)" |
4895 |
||
4896 |
|sz "{ Class:SmallInteger }"| |
|
4897 |
||
4898 |
sz := self size. |
|
4899 |
1 to:sz do:[:idx| |
|
18969 | 4900 |
(self at:idx) > 16r7F ifTrue:[ |
4901 |
^ true. |
|
4902 |
]. |
|
4903 |
]. |
|
4904 |
^ false. |
|
4905 |
! |
|
4906 |
||
4907 |
containsNon8BitElements |
|
4908 |
"return true, if the underlying structure contains elements larger than a single byte" |
|
4909 |
||
4910 |
|sz "{ Class:SmallInteger }"| |
|
4911 |
||
4912 |
sz := self size. |
|
4913 |
1 to:sz do:[:idx| |
|
4914 |
(self at:idx) > 16rFF ifTrue:[ |
|
4915 |
^ true. |
|
4916 |
]. |
|
18616 | 4917 |
]. |
4918 |
^ false. |
|
4919 |
! |
|
4920 |
||
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4921 |
defaultElement |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4922 |
^ 0 |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4923 |
! |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4924 |
|
18616 | 4925 |
referencesAny:aCollection |
4926 |
"redefined to speed up searching when many of my instances are present" |
|
4927 |
||
4928 |
%{ /* NOCONTEXT */ |
|
4929 |
if (__mkSmallInteger(0) == __ClassInstPtr(__qClass(self))->c_ninstvars) { |
|
19368 | 4930 |
/* I am only bytes */ |
4931 |
RETURN(false) |
|
18616 | 4932 |
} |
4933 |
%}. |
|
4934 |
^ super referencesAny:aCollection |
|
4935 |
||
4936 |
" |
|
19368 | 4937 |
'abc' referencesAny:#() |
18616 | 4938 |
" |
4939 |
! |
|
4940 |
||
3323 | 4941 |
sizeInBytes |
4942 |
"return the number of 8-bit bytes in the receiver. |
|
4943 |
This is needed since subclasse may redefine #size (TwoByteString)" |
|
4944 |
||
4945 |
^ super size |
|
4946 |
||
4947 |
"Created: / 5.3.1998 / 10:41:13 / stefan" |
|
4948 |
! ! |
|
4949 |
||
8986 | 4950 |
!UninterpretedBytes methodsFor:'testing'! |
4951 |
||
4952 |
isByteCollection |
|
4953 |
"return true, if the receiver has access methods for bytes; |
|
4954 |
true is returned here - the method is redefined from Object." |
|
4955 |
||
4956 |
^ true |
|
9005 | 4957 |
! |
4958 |
||
4959 |
isNonByteCollection |
|
4960 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
4961 |
false is returned here - the method is redefined from Collection." |
|
4962 |
||
4963 |
^ false |
|
8986 | 4964 |
! ! |
4965 |
||
11009
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4966 |
!UninterpretedBytes methodsFor:'visiting'! |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4967 |
|
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4968 |
acceptVisitor:aVisitor with:aParameter |
16719 | 4969 |
"dispatch for visitor pattern; send #visitByteArray:with: to aVisitor." |
11009
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4970 |
|
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4971 |
^ aVisitor visitByteArray:self with:aParameter |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4972 |
! ! |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4973 |
|
695 | 4974 |
!UninterpretedBytes class methodsFor:'documentation'! |
4975 |
||
4976 |
version |
|
18600 | 4977 |
^ '$Header$' |
12253
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
4978 |
! |
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
4979 |
|
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
4980 |
version_CVS |
18600 | 4981 |
^ '$Header$' |
695 | 4982 |
! ! |
15087 | 4983 |
|
18284 | 4984 |
|
4985 |
UninterpretedBytes initialize! |