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