author | Claus Gittinger <cg@exept.de> |
Sun, 13 Mar 2016 02:12:33 +0100 | |
changeset 19352 | 3c5b0c74be2e |
parent 19351 | 07dede3d264c |
child 19354 | ec77be1507a3 |
child 19366 | 82606b52b3a0 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
300 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
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 |
1266 | 17 |
instanceVariableNames:'' |
3323 | 18 |
classVariableNames:'IsBigEndian' |
1266 | 19 |
poolDictionaries:'' |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
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)) { \ |
|
13575 | 38 |
if (__isByteArrayLike(o)) { \ |
39 |
*(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \ |
|
40 |
*(pSize) = __byteArraySize(o); \ |
|
15004 | 41 |
} else if (__qIsExternalBytesLike(o)) { \ |
13575 | 42 |
OBJ __sz__ = __externalBytesSize(o); \ |
43 |
if (__isSmallInteger(__sz__)) { \ |
|
44 |
*(pSize) = __intVal(__sz__); \ |
|
45 |
*(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \ |
|
46 |
} else { \ |
|
15004 | 47 |
*(pSize) = 0; \ |
13575 | 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 { \ |
15004 | 56 |
*(pSize) = 0; \ |
13575 | 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 |
|
300 | 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 | |
18346 | 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:[ |
|
18346 | 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 | |
13575 | 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:[ |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
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:[ |
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
231 |
"/ take 4 characters ... |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
232 |
"/ allow a line break before each group of 4 |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
233 |
sixBits := (aString at:index) codePoint. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
234 |
[sixBits < 32] whileTrue:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
235 |
index := index + 1. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
236 |
sixBits := (aString at:index) codePoint. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
237 |
]. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
238 |
sixBits := sixBits bitAnd:16r3F. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
239 |
n := sixBits. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
240 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
241 |
"/ self assert:(aString at:index+1) codePoint >= 32. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
242 |
sixBits := (aString at:index+1) codePoint bitAnd:16r3F. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
243 |
n := (n bitShift:6) + sixBits. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
244 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
245 |
"/ self assert:(aString at:index+2) codePoint >= 32. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
246 |
sixBits := (aString at:index+2) codePoint bitAnd:16r3F. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
247 |
n := (n bitShift:6) + sixBits. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
248 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
249 |
"/ self assert:(aString at:index+3) codePoint >= 32. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
250 |
sixBits := (aString at:index+3) codePoint bitAnd:16r3F. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
251 |
n := (n bitShift:6) + sixBits. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
252 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
253 |
index := index + 4. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
254 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
255 |
"/ now have 24 bits in n |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
256 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
257 |
bytes at:dstIndex put:(n bitShift:-16). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
258 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
259 |
dstIndex < stop ifTrue:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
260 |
bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
261 |
dstIndex+2 <= stop ifTrue:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
262 |
bytes at:dstIndex+2 put:(n bitAnd:16rFF). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
263 |
] |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
264 |
]. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
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 | |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
284 |
|orig copy| |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
285 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
286 |
0 to:255 do:[:fill | |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
287 |
orig := ByteArray new:l withAll:fill. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
288 |
copy := ByteArray fromPackedString:(orig asPackedString). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
289 |
self assert:(orig = copy). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
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)) { |
|
18346 | 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) |
18346 | 366 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
18284 | 367 |
#else |
368 |
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES) |
|
18346 | 369 |
/* |
370 |
* knowing that nil is 0 |
|
371 |
*/ |
|
372 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
18284 | 373 |
# else |
18346 | 374 |
op = __InstPtr(newobj)->i_instvars; |
375 |
while (nInstVars--) |
|
376 |
*op++ = nil; |
|
18284 | 377 |
# endif |
378 |
#endif |
|
18346 | 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. |
|
410 |
Abstract subclasses must redefine again." |
|
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 |
4308 | 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 { |
|
4308 | 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). |
|
19352 | 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 |
||
842 |
^ (self unsignedInt16At:index MSB:IsBigEndian) signExtendedShortValue |
|
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 |
||
863 |
^ (self unsignedInt16At:index MSB:msb) signExtendedShortValue |
|
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). |
|
1000 |
The value is retrieved in the machines natural byte order. |
|
1001 |
This may be worth a primitive." |
|
1002 |
||
1003 |
^ self longAt:index |
|
1004 |
||
1005 |
" |
|
1006 |
|b| |
|
1007 |
b := ByteArray new:4. |
|
1008 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
1009 |
b signedLongAt:1 |
|
1010 |
" |
|
1011 |
||
1012 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
1013 |
! |
|
1014 |
||
1015 |
signedLongAt:index put:newValue |
|
1016 |
"store a 4-bytes value starting at index. |
|
1017 |
The index is a smalltalk index (i.e. 1-based). |
|
1018 |
The value is in the machines natural byte order." |
|
1019 |
||
1020 |
^ self longAt:index put:newValue |
|
1021 |
||
1022 |
" |
|
1023 |
|b| |
|
1024 |
b := ByteArray new:4. |
|
1025 |
b signedLongAt:1 put:-1. |
|
1026 |
b unsignedLongAt:1 |
|
1027 |
" |
|
1028 |
||
1029 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
19349 | 1030 |
! |
1031 |
||
1032 |
signedWordAt:index |
|
1033 |
"return the 2-bytes starting at index as a signed Integer. |
|
1034 |
The index is a smalltalk index (i.e. 1-based). |
|
1035 |
The value is retrieved in the machines natural byte order. |
|
1036 |
This may be worth a primitive." |
|
1037 |
||
1038 |
^ (self unsignedInt16At:index MSB:IsBigEndian) signExtendedShortValue |
|
1039 |
||
1040 |
" |
|
1041 |
|b| |
|
1042 |
b := ByteArray new:2. |
|
1043 |
b wordAt:1 put:16rFFFF. |
|
1044 |
b signedWordAt:1 |
|
1045 |
" |
|
1046 |
||
1047 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
1048 |
! |
|
1049 |
||
1050 |
signedWordAt:index MSB:msb |
|
1051 |
"return the 2-bytes starting at index as a signed Integer. |
|
1052 |
The index is a smalltalk index (i.e. 1-based). |
|
1053 |
The value is retrieved MSB-first if the msb-arg is true, |
|
1054 |
LSB-first otherwise. |
|
1055 |
This may be worth a primitive." |
|
1056 |
||
1057 |
^ (self unsignedInt16At:index MSB:msb) signExtendedShortValue |
|
1058 |
||
1059 |
" |
|
1060 |
|b| |
|
1061 |
b := ByteArray new:2. |
|
1062 |
b wordAt:1 put:16r0080. |
|
1063 |
b signedWordAt:1 MSB:true. |
|
1064 |
b signedWordAt:1 MSB:false. |
|
1065 |
" |
|
1066 |
||
1067 |
"Modified: 1.7.1996 / 21:15:57 / cg" |
|
1068 |
! |
|
1069 |
||
1070 |
signedWordAt:byteIndex put:anInteger |
|
1071 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1072 |
The index is a smalltalk index (i.e. 1-based). |
|
1073 |
The stored value must be in the range -32768 .. +32676. |
|
1074 |
The value is stored in the machine's natural byteorder." |
|
1075 |
||
1076 |
^ self signedInt16At:byteIndex put:anInteger MSB:IsBigEndian |
|
1077 |
||
1078 |
" |
|
1079 |
|b| |
|
1080 |
b := ByteArray new:6. |
|
1081 |
b shortAt:1 put:-1. |
|
1082 |
b shortAt:3 put:-2. |
|
1083 |
b shortAt:5 put:0. |
|
1084 |
b inspect |
|
1085 |
" |
|
1086 |
||
1087 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1088 |
"Modified: / 5.3.1998 / 11:01:30 / stefan" |
|
1089 |
! |
|
1090 |
||
1091 |
signedWordAt:byteIndex put:anInteger MSB:msb |
|
1092 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1093 |
The index is a smalltalk index (i.e. 1-based). |
|
1094 |
The stored value must be in the range -32768 .. +32676. |
|
1095 |
The value is stored MSB-first, if the msb-arg is true; |
|
1096 |
LSB-first otherwise." |
|
1097 |
||
1098 |
^ self int16At:byteIndex put:anInteger MSB:msb |
|
1099 |
||
1100 |
" |
|
1101 |
|b| |
|
1102 |
b := ByteArray new:4. |
|
1103 |
b signedWordAt:1 put:-1. |
|
1104 |
b signedWordAt:3 put:-2. |
|
1105 |
b inspect |
|
1106 |
" |
|
1107 |
||
1108 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
1109 |
! |
|
1110 |
||
1111 |
unsignedLongAt:index |
|
1112 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1113 |
The index is a smalltalk index (i.e. 1-based). |
|
1114 |
The value is retrieved in the machine's natural byte order. |
|
1115 |
Subclasses may redefine this for better performance. |
|
1116 |
Same as doubleWordAt: for protocol completeness" |
|
1117 |
||
1118 |
^ self unsignedInt32At:index MSB:IsBigEndian |
|
1119 |
||
1120 |
" |
|
1121 |
|b| |
|
1122 |
||
1123 |
b := ByteArray withAll:#(1 2 3 4). |
|
1124 |
(b unsignedLongAt:1) printStringRadix:16 |
|
1125 |
" |
|
1126 |
||
1127 |
"Created: / 5.3.1998 / 11:56:53 / stefan" |
|
1128 |
"Modified: / 5.3.1998 / 14:58:48 / stefan" |
|
1129 |
! |
|
1130 |
||
1131 |
unsignedLongAt:index bigEndian:msb |
|
1132 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1133 |
The index is a smalltalk index (i.e. 1-based). |
|
1134 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
1135 |
LSB-first otherwise. |
|
1136 |
Subclasses may redefine this for better performance. |
|
1137 |
Same as doubleWordAt:MSB: for protocol completeness" |
|
1138 |
||
1139 |
^ self unsignedInt32At:index MSB:msb |
|
1140 |
||
1141 |
" |
|
1142 |
|b| |
|
1143 |
||
1144 |
b := ByteArray withAll:#(1 2 3 4). |
|
1145 |
(b unsignedLongAt:1 bigEndian:true) printStringRadix:16. |
|
1146 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1147 |
" |
|
1148 |
||
1149 |
"Modified: / 21.1.1998 / 17:42:30 / cg" |
|
1150 |
"Created: / 5.3.1998 / 11:46:05 / stefan" |
|
1151 |
! |
|
1152 |
||
1153 |
unsignedLongAt:index put:value |
|
1154 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1155 |
The index is a smalltalk index (i.e. 1-based). |
|
1156 |
The value should be in the range 0 to 16rFFFFFFFF |
|
1157 |
(for negative values, the stored value is not defined). |
|
1158 |
The value is stored in the machines natural byte order. |
|
1159 |
Subclasses may redefine this for better performance. |
|
1160 |
Same as doubleWordAt:put: for protocol completeness" |
|
1161 |
||
1162 |
^ self unsignedInt32At:index put:value MSB:IsBigEndian |
|
1163 |
||
1164 |
" |
|
1165 |
|b| |
|
1166 |
b := ByteArray new:4. |
|
1167 |
b unsignedLongAt:1 put:16r04030201. |
|
1168 |
b inspect |
|
1169 |
" |
|
1170 |
||
1171 |
"Created: / 5.3.1998 / 11:57:44 / stefan" |
|
1172 |
"Modified: / 5.3.1998 / 14:58:59 / stefan" |
|
1173 |
! |
|
1174 |
||
1175 |
unsignedLongAt:index put:aNumber bigEndian:msb |
|
1176 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1177 |
The index is a smalltalk index (i.e. 1-based). |
|
1178 |
The value must be in the range 0 to 16rFFFFFFFF. |
|
1179 |
The value is stored MSB-first if msb is true; LSB-first otherwise. |
|
1180 |
Subclasses may redefine this for better performance. |
|
1181 |
Same as doubleWordAt:put:MSB: for protocol completeness" |
|
1182 |
||
1183 |
^ self unsignedInt32At:index put:aNumber MSB:msb |
|
1184 |
||
1185 |
" |
|
1186 |
|b| |
|
1187 |
b := ByteArray new:8. |
|
1188 |
b unsignedLongAt:1 put:16r04030201 bigEndian:true. |
|
1189 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1190 |
" |
|
1191 |
||
1192 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
1193 |
"Created: / 5.3.1998 / 11:43:53 / stefan" |
|
1194 |
"Modified: / 5.3.1998 / 11:47:30 / stefan" |
|
1195 |
! |
|
1196 |
||
1197 |
unsignedLongLongAt:index bigEndian:msb |
|
1198 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
1199 |
The index is a smalltalk index (i.e. 1-based). |
|
1200 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
1201 |
||
1202 |
^ self unsignedInt64At:index MSB:msb |
|
1203 |
||
1204 |
" |
|
1205 |
|b| |
|
1206 |
||
1207 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
1208 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
|
1209 |
" |
|
1210 |
||
1211 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
1212 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
1213 |
! |
|
1214 |
||
1215 |
unsignedLongLongAt:index put:anInteger |
|
1216 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1217 |
The index is a smalltalk index (i.e. 1-based). |
|
1218 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1219 |
The value is stored in natural byte order." |
|
1220 |
||
1221 |
^ self unsignedInt64At:index put:anInteger MSB:IsBigEndian |
|
1222 |
||
1223 |
"Created: / 5.3.1998 / 14:44:00 / stefan" |
|
1224 |
"Modified: / 5.3.1998 / 15:02:32 / stefan" |
|
1225 |
! |
|
1226 |
||
1227 |
unsignedLongLongAt:index put:anInteger bigEndian:msb |
|
1228 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1229 |
The index is a smalltalk index (i.e. 1-based). |
|
1230 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1231 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
1232 |
||
1233 |
^ self unsignedInt64At:index put:anInteger MSB:msb |
|
1234 |
||
1235 |
" |
|
1236 |
|b| |
|
1237 |
b := ByteArray new:8. |
|
1238 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
1239 |
b inspect |
|
1240 |
" |
|
1241 |
||
1242 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
1243 |
! |
|
1244 |
||
1245 |
unsignedShortAt:index |
|
1246 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1247 |
The index is a smalltalk index (i.e. 1-based). |
|
1248 |
The value is retrieved in the machines natural byte order |
|
1249 |
Subclasses may redefine this for better performance. |
|
1250 |
This is the ST80 equivalent of #wordAt:" |
|
1251 |
||
1252 |
||
1253 |
^ self unsignedInt16At:index MSB:IsBigEndian |
|
1254 |
||
1255 |
"Created: / 5.3.1998 / 11:38:25 / stefan" |
|
1256 |
"Modified: / 5.3.1998 / 14:59:25 / stefan" |
|
1257 |
! |
|
1258 |
||
1259 |
unsignedShortAt:index bigEndian:msb |
|
1260 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1261 |
The index is a smalltalk index (i.e. 1-based). |
|
1262 |
The value is retrieved MSB-first (high 8 bits at lower index) if msb is true; |
|
1263 |
LSB-first (i.e. low 8-bits at lower byte index) if its false)" |
|
1264 |
||
1265 |
^ self unsignedInt16At:index MSB:msb |
|
1266 |
||
1267 |
"Modified: / 21.1.1998 / 17:46:07 / cg" |
|
1268 |
"Created: / 5.3.1998 / 11:49:29 / stefan" |
|
1269 |
! |
|
1270 |
||
1271 |
unsignedShortAt:index put:value |
|
1272 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1273 |
The index is a smalltalk index (i.e. 1-based). |
|
1274 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1275 |
The value is stored in the machines natural byteorder." |
|
1276 |
||
1277 |
^ self unsignedInt16At:index put:value |
|
1278 |
||
1279 |
" |
|
1280 |
|b| |
|
1281 |
b := ByteArray new:4. |
|
1282 |
b unsignedShortAt:1 put:16r0102. |
|
1283 |
b unsignedShortAt:3 put:16r0304. |
|
1284 |
b inspect |
|
1285 |
" |
|
1286 |
||
1287 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
1288 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
1289 |
! |
|
1290 |
||
1291 |
unsignedShortAt:index put:value bigEndian:msb |
|
1292 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1293 |
The index is a smalltalk index (i.e. 1-based). |
|
1294 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1295 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
|
1296 |
lower index) if msb is false, MSB-first otherwise" |
|
1297 |
||
1298 |
^ self unsignedInt16At:index put:value MSB:msb |
|
1299 |
||
1300 |
" |
|
1301 |
|b| |
|
1302 |
b := ByteArray new:8. |
|
1303 |
b unsignedShortAt:1 put:16r0102 bigEndian:false. |
|
1304 |
b unsignedShortAt:3 put:16r0304 bigEndian:false. |
|
1305 |
b unsignedShortAt:5 put:16r0102 bigEndian:true. |
|
1306 |
b unsignedShortAt:7 put:16r0304 bigEndian:true. |
|
1307 |
b inspect |
|
1308 |
" |
|
1309 |
||
1310 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
1311 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
1312 |
! |
|
1313 |
||
1314 |
wordAt:index |
|
1315 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1316 |
The index is a smalltalk index (i.e. 1-based). |
|
1317 |
The value is retrieved in the machines natural byte order |
|
1318 |
Subclasses may redefine this for better performance." |
|
1319 |
||
1320 |
^ self unsignedInt16At:index MSB:IsBigEndian |
|
1321 |
||
1322 |
"Modified: / 5.3.1998 / 14:59:51 / stefan" |
|
1323 |
! |
|
1324 |
||
1325 |
wordAt:index MSB:msb |
|
1326 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
1327 |
The index is a smalltalk index (i.e. 1-based). |
|
1328 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
|
1329 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
|
1330 |
Notice: |
|
1331 |
the index is a byte index; thus, this allows for unaligned access to |
|
1332 |
words on any boundary. |
|
1333 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)" |
|
1334 |
||
1335 |
^ self unsignedInt16At:index MSB:msb |
|
1336 |
! |
|
1337 |
||
1338 |
wordAt:index put:value |
|
1339 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1340 |
The index is a smalltalk index (i.e. 1-based). |
|
1341 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1342 |
The value is stored in the machines natural byteorder. |
|
1343 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
|
1344 |
||
1345 |
^ self unsignedInt16At:index put:value MSB:IsBigEndian |
|
1346 |
||
1347 |
" |
|
1348 |
|b| |
|
1349 |
b := ByteArray new:4. |
|
1350 |
b wordAt:1 put:16r0102. |
|
1351 |
b wordAt:3 put:16r0304. |
|
1352 |
b inspect |
|
1353 |
" |
|
1354 |
||
1355 |
"Modified: / 5.3.1998 / 15:00:03 / stefan" |
|
1356 |
! |
|
1357 |
||
1358 |
wordAt:index put:value MSB:msb |
|
1359 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
1360 |
The index is a smalltalk index (i.e. 1-based). |
|
1361 |
The stored value must be in the range 0 .. 16rFFFF. |
|
1362 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
|
1363 |
lower index) if msb is false, MSB-first otherwise. |
|
1364 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
|
1365 |
||
1366 |
^ self unsignedInt16At:index put:value MSB:msb |
|
1367 |
||
1368 |
" |
|
1369 |
b := ByteArray new:8. |
|
1370 |
b wordAt:1 put:16r0102 MSB:false. |
|
1371 |
b wordAt:3 put:16r0304 MSB:false. |
|
1372 |
b wordAt:5 put:16r0102 MSB:true. |
|
1373 |
b wordAt:7 put:16r0304 MSB:true. |
|
1374 |
b inspect |
|
1375 |
" |
|
1376 |
||
1377 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
1378 |
! |
|
1379 |
||
1380 |
wordAtWordIndex:int16Index |
|
1381 |
"return the unsigned short (uint16) at index, anInteger. |
|
1382 |
Fetching in the machines natural byte order. |
|
1383 |
Indices are 1-based and scaled as appropriate to allow |
|
1384 |
accessing the memory as an array of word entries. |
|
1385 |
(i.e. indices are 1, 2, ...)" |
|
1386 |
||
1387 |
^ self unsignedInt16At:int16Index MSB:IsBigEndian |
|
1388 |
||
1389 |
"Created: / 21.1.1998 / 17:48:26 / cg" |
|
1390 |
"Modified: / 5.3.1998 / 15:00:16 / stefan" |
|
1391 |
! |
|
1392 |
||
1393 |
wordAtWordIndex:int16Index MSB:msb |
|
1394 |
"return the unsigned short (uint16) at index, anInteger. |
|
1395 |
Fetching is MSB if msb is true, LSB otherwise. |
|
1396 |
Indices are 1-based and scaled as appropriate to allow |
|
1397 |
accessing the memory as an array of word entries. |
|
1398 |
(i.e. indices are 1, 2, ...)" |
|
1399 |
||
1400 |
^ self unsignedInt16At:((int16Index - 1) * 2 + 1) MSB:msb |
|
1401 |
||
1402 |
"Created: / 21.1.1998 / 17:48:30 / cg" |
|
1403 |
! |
|
1404 |
||
1405 |
wordAtWordIndex:int16Index put:anInteger |
|
1406 |
"set the unsigned short (uint16) at index, anInteger. |
|
1407 |
Storing in the machine's natural byte order. |
|
1408 |
Indices are 1-based and scaled as appropriate to allow |
|
1409 |
accessing the memory as an array of word entries. |
|
1410 |
(i.e. indices are 1, 2, ...)" |
|
1411 |
||
1412 |
^ self unsignedInt16At:int16Index put:anInteger MSB:IsBigEndian |
|
1413 |
||
1414 |
"Created: / 21.1.1998 / 17:48:34 / cg" |
|
1415 |
"Modified: / 5.3.1998 / 15:00:27 / stefan" |
|
1416 |
! |
|
1417 |
||
1418 |
wordAtWordIndex:int16Index put:anInteger MSB:msb |
|
1419 |
"set the short at index, anInteger. |
|
1420 |
Storing is MSB if msb is true, LSB otherwise. |
|
1421 |
Indices are 1-based and scaled as appropriate to allow |
|
1422 |
accessing the memory as an array of word entries. |
|
1423 |
(i.e. indices are 1, 2, ...)" |
|
1424 |
||
1425 |
^ self unsignedInt16At:((int16Index - 1) * 2 + 1) put:anInteger MSB:msb |
|
1426 |
||
1427 |
"Created: / 21.1.1998 / 17:48:38 / cg" |
|
1428 |
! ! |
|
1429 |
||
1430 |
!UninterpretedBytes methodsFor:'Compatibility-Squeak'! |
|
1431 |
||
1432 |
copyFromByteArray:aByteArray |
|
1433 |
"copy as much as possible from aByteArray" |
|
1434 |
||
1435 |
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
|
1436 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
1437 |
|
9185 | 1438 |
!UninterpretedBytes methodsFor:'Compatibility-V''Age'! |
1439 |
||
1440 |
uint32At:zeroBasedIndex |
|
1441 |
"return the 4-bytes starting at index as (unsigned) Integer. |
|
1442 |
The index is a C index (i.e. 0-based). |
|
19301 | 1443 |
The value is retrieved in the machine's natural byte order. |
9185 | 1444 |
Similar to unsignedLongAt:, except for the index base" |
1445 |
||
1446 |
^ self unsignedLongAt:zeroBasedIndex+1 |
|
1447 |
||
1448 |
" |
|
1449 |
|b| |
|
1450 |
||
1451 |
b := ByteArray withAll:#(0 0 0 0). |
|
1452 |
b uint32At:0 put:16r12345678. |
|
1453 |
b uint32At:0. |
|
1454 |
b |
|
1455 |
" |
|
1456 |
! |
|
1457 |
||
1458 |
uint32At:zeroBasedIndex put:anInteger |
|
1459 |
"set the 4-bytes starting at index to the value given by (unsigned) Integer. |
|
1460 |
The index is a C index (i.e. 0-based). |
|
1461 |
The value is stored in the machines natural byte order. |
|
1462 |
Similar to unsignedLongAt:put:, except for the index base" |
|
1463 |
||
1464 |
^ self unsignedLongAt:zeroBasedIndex+1 put:anInteger |
|
1465 |
||
1466 |
" |
|
1467 |
|b| |
|
1468 |
||
1469 |
b := ByteArray withAll:#(0 0 0 0). |
|
1470 |
b uint32At:0 put:16r12345678. |
|
1471 |
b |
|
1472 |
" |
|
1473 |
! ! |
|
1474 |
||
16796 | 1475 |
!UninterpretedBytes methodsFor:'accessing-arbitrary-long ints'! |
1476 |
||
19349 | 1477 |
nativeIntAt:index |
1478 |
"return the 4- or 8-bytes (depending on the native integer/pointer size) |
|
1479 |
starting at index as a signed Integer. |
|
1480 |
The index is a smalltalk index (i.e. 1-based). |
|
1481 |
The value is retrieved in the machines natural byte order, |
|
1482 |
therefore, this should only be used for byte-data which is |
|
1483 |
only used inside this machine." |
|
1484 |
||
1485 |
|w| |
|
1486 |
||
1487 |
%{ |
|
1488 |
/* |
|
1489 |
* handle the most common cases fast ... |
|
1490 |
*/ |
|
1491 |
if (__isSmallInteger(index)) { |
|
1492 |
unsigned char *cp; |
|
1493 |
INT sz; |
|
1494 |
||
1495 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1496 |
if (cp) { |
|
1497 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1498 |
||
1499 |
if ((idx+(sizeof(INT)-1)) < sz) { |
|
1500 |
cp += idx; |
|
1501 |
#if defined(__i386__) |
|
1502 |
/* |
|
1503 |
* aligned or not, we dont care (i386 can do both) |
|
1504 |
*/ |
|
1505 |
{ |
|
1506 |
INT iVal = ((INT *)cp)[0]; |
|
1507 |
||
1508 |
RETURN (__MKINT(iVal)); |
|
1509 |
} |
|
1510 |
#else |
|
1511 |
/* |
|
1512 |
* aligned |
|
1513 |
*/ |
|
1514 |
if (((INT)cp & (sizeof(INT)-1)) == 0) { |
|
1515 |
INT iVal = ((INT *)cp)[0]; |
|
1516 |
||
1517 |
RETURN (__MKINT(iVal)); |
|
1518 |
} |
|
1519 |
#endif |
|
1520 |
} |
|
1521 |
} |
|
1522 |
} |
|
1523 |
%}. |
|
1524 |
ExternalAddress pointerSize == 8 ifTrue:[ |
|
1525 |
^ self signedInt64At:index |
|
1526 |
]. |
|
1527 |
^ self signedInt32At:index |
|
1528 |
||
1529 |
" |
|
1530 |
|b| |
|
1531 |
b := ByteArray new:8. |
|
1532 |
b nativeIntAt:1 put:SmallInteger maxVal. |
|
1533 |
b nativeIntAt:1 |
|
1534 |
" |
|
1535 |
! |
|
1536 |
||
1537 |
nativeIntAt:index put:value |
|
1538 |
"set the 4- or 8-bytes (depending on INT-/pointer size) starting at index from the signed Integer value. |
|
1539 |
The index is a smalltalk index (i.e. 1-based). |
|
1540 |
The value is stored in the machine's natural byte order." |
|
1541 |
||
1542 |
%{ /* NOCONTEXT */ |
|
1543 |
/* |
|
1544 |
* handle the most common cases fast ... |
|
1545 |
*/ |
|
1546 |
if (__isSmallInteger(index)) { |
|
1547 |
unsigned char *cp; |
|
1548 |
INT sz; |
|
1549 |
||
1550 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1551 |
if (cp) { |
|
1552 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1553 |
||
1554 |
if ((idx+(sizeof(INT)-1)) < sz) { |
|
1555 |
cp += idx; |
|
1556 |
/* |
|
1557 |
* aligned |
|
1558 |
*/ |
|
1559 |
if (((INT)cp & (sizeof(INT)-1)) == 0) { |
|
1560 |
INT __v; |
|
1561 |
||
1562 |
if (__isSmallInteger(value)) { |
|
1563 |
// how about a range check? |
|
1564 |
((INT *)cp)[0] = (INT)(__intVal(value)); |
|
1565 |
RETURN (value); |
|
1566 |
} |
|
1567 |
if ((__v = __signedLongIntVal(value)) != 0) { |
|
1568 |
// how about a range check? |
|
1569 |
((INT *)cp)[0] = (INT)(__v); |
|
1570 |
RETURN (value); |
|
1571 |
} |
|
1572 |
} |
|
1573 |
} |
|
1574 |
} |
|
1575 |
} |
|
1576 |
%}. |
|
1577 |
ExternalAddress pointerSize == 8 ifTrue:[ |
|
1578 |
^ self signedInt64At:index put:value MSB:IsBigEndian |
|
1579 |
]. |
|
1580 |
^ self signedInt32At:index put:value MSB:IsBigEndian |
|
1581 |
||
1582 |
" |
|
1583 |
|b| |
|
1584 |
b := ByteArray new:8. |
|
1585 |
b nativeIntAt:1 put:SmallInteger maxVal. |
|
1586 |
(b nativeIntAt:1) |
|
1587 |
" |
|
1588 |
! |
|
1589 |
||
19197 | 1590 |
signedIntegerAt:index length:n bigEndian:bigEndian |
1591 |
"return the n-byte signed integer starting at index. |
|
1592 |
With n=1, this returns the single signed byte's value, |
|
1593 |
n=2, a signed short, n=4 a signed int etc. |
|
1594 |
Useful to extract arbitrary long integers" |
|
1595 |
||
1596 |
|val highByte| |
|
1597 |
||
1598 |
val := 0. |
|
1599 |
bigEndian ifTrue:[ |
|
1600 |
highByte := (self at:index). |
|
1601 |
index to:index+n-1 do:[:i | |
|
19351 | 1602 |
val := (val<<8) + (self byteAt:i) |
19197 | 1603 |
] |
1604 |
] ifFalse:[ |
|
1605 |
highByte := (self at:index+n-1). |
|
1606 |
index+n-1 to:index by:-1 do:[:i | |
|
19351 | 1607 |
val := (val<<8) + (self byteAt:i) |
19197 | 1608 |
] |
1609 |
]. |
|
1610 |
(highByte bitTest:16r80) ifTrue:[ |
|
1611 |
^ val - (1 bitShift:(n*8)) |
|
1612 |
]. |
|
1613 |
^ val |
|
1614 |
||
1615 |
" |
|
1616 |
|b| |
|
1617 |
b := #[ 16r01 16rFF 16r00 16r04 16r05 ]. |
|
1618 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> 255 (00FF) '. |
|
1619 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> -256 (FF00) '. |
|
1620 |
||
1621 |
b := #[ 16r01 16r00 16rFF 16r04 16r05 ]. |
|
1622 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> -256 (FF00) '. |
|
1623 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> 255 (00FF) '. |
|
1624 |
||
1625 |
b := #[ 16r01 16r7F 16r00 16r04 16r05 ]. |
|
1626 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> 127 (007F) '. |
|
1627 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> 32512 (7F00) '. |
|
1628 |
" |
|
1629 |
||
1630 |
" |
|
1631 |
|b| |
|
1632 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ]. |
|
1633 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
1634 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
1635 |
||
1636 |
b := #[ 16r01 16r82 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 16r85 ]. |
|
1641 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
1642 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
1643 |
" |
|
1644 |
! |
|
1645 |
||
16796 | 1646 |
unsignedIntegerAt:index length:n bigEndian:bigEndian |
1647 |
"return the n-byte unsigned integer starting at index. |
|
1648 |
With n=1, this returns the single byte's value, |
|
1649 |
n=2, an unsigned short, n=4 an unsigned int etc. |
|
1650 |
Useful to extract arbitrary long integers" |
|
1651 |
||
1652 |
|val| |
|
1653 |
||
1654 |
val := 0. |
|
18346 | 1655 |
bigEndian ifTrue:[ |
19351 | 1656 |
index to:index+n-1 do:[:i | |
1657 |
val := (val<<8) + (self byteAt:i) |
|
1658 |
] |
|
18346 | 1659 |
] ifFalse:[ |
19351 | 1660 |
index+n-1 to:index by:-1 do:[:i | |
1661 |
val := (val<<8) + (self byteAt:i) |
|
1662 |
] |
|
16796 | 1663 |
]. |
1664 |
^ val |
|
1665 |
||
1666 |
" |
|
1667 |
|b| |
|
1668 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ]. |
|
18346 | 1669 |
(b unsignedIntegerAt:2 length:4 bigEndian:false). |
1670 |
(b unsignedIntegerAt:2 length:4 bigEndian:true). |
|
16796 | 1671 |
" |
19301 | 1672 |
! |
1673 |
||
1674 |
unsignedIntegerAt:index put:newValue length:n bigEndian:bigEndian |
|
1675 |
"store the n-byte unsigned integer starting at index. |
|
1676 |
With n=1, this stores a single byte's value, |
|
1677 |
n=2, an unsigned short, n=4 an unsigned int etc. |
|
1678 |
Useful to replace arbitrary long integers" |
|
1679 |
||
1680 |
|val| |
|
1681 |
||
1682 |
val := newValue. |
|
1683 |
bigEndian ifTrue:[ |
|
1684 |
index to:index+n-1 do:[:i | |
|
19351 | 1685 |
self byteAt:i put:(val bitAnd:16rFF). |
19301 | 1686 |
val := val bitShift:-8. |
1687 |
] |
|
1688 |
] ifFalse:[ |
|
1689 |
index+n-1 to:index by:-1 do:[:i | |
|
19351 | 1690 |
self byteAt:i put:(val bitAnd:16rFF). |
19301 | 1691 |
val := val bitShift:-8. |
1692 |
] |
|
1693 |
]. |
|
1694 |
||
1695 |
" |
|
1696 |
|b| |
|
1697 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ] copy. |
|
1698 |
(b unsignedIntegerAt:2 put:16r11223344 length:3 bigEndian:false). b. |
|
1699 |
(b unsignedIntegerAt:2 put:16r11223344 length:3 bigEndian:true). b. |
|
1700 |
" |
|
16796 | 1701 |
! ! |
1702 |
||
3459 | 1703 |
!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
|
1704 |
|
4422 | 1705 |
bcdByteAt:index |
13724 | 1706 |
"return the bcd-value for a byte at index in the range 0..99. |
1707 |
BCD treats nibbles (4-bit) as an encoded decimal number's digits |
|
1708 |
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)" |
|
4422 | 1709 |
|
4425 | 1710 |
^ (self byteAt:index) decodeFromBCD |
4422 | 1711 |
|
1712 |
" |
|
19352 | 1713 |
#[ 16r55 ] bcdByteAt:1 |
1714 |
#[ 16r99 ] bcdByteAt:1 |
|
1715 |
#[ 16rAA ] bcdByteAt:1 |
|
4422 | 1716 |
" |
13724 | 1717 |
|
1718 |
"Modified (comment): / 26-09-2011 / 11:57:33 / cg" |
|
4422 | 1719 |
! |
1720 |
||
1721 |
bcdByteAt:index put:aNumber |
|
13724 | 1722 |
"set the byte at index as bcd-value in the range 0..99. |
1723 |
BCD treats nibbles (4-bit) as an encoded decimal number's digits |
|
1724 |
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)" |
|
4422 | 1725 |
|
1726 |
(aNumber between:0 and:99) ifFalse:[ |
|
15004 | 1727 |
self error:'invalid value for BCD encoding' |
4422 | 1728 |
]. |
4425 | 1729 |
^ self byteAt:index put:aNumber encodeAsBCD |
4422 | 1730 |
|
1731 |
" |
|
13575 | 1732 |
(((ByteArray new:1) bcdByteAt:1 put:55; yourself) at:1) hexPrintString |
1733 |
(((ByteArray new:1) bcdByteAt:1 put:99; yourself) at:1) hexPrintString |
|
1734 |
(((ByteArray new:1) bcdByteAt:1 put:100; yourself) at:1) hexPrintString |
|
1735 |
(((ByteArray new:1) bcdByteAt:1 put:-1; yourself) at:1) hexPrintString |
|
4422 | 1736 |
" |
13724 | 1737 |
|
1738 |
"Modified (comment): / 26-09-2011 / 11:57:36 / cg" |
|
4422 | 1739 |
! |
1740 |
||
19351 | 1741 |
byteAt:byteIndex |
1742 |
"return the byte at byteIndex as an unsigned 8 bit value in the range 0..255. |
|
1743 |
The index is a smalltalk index (i.e. 1-based)." |
|
1744 |
||
1745 |
%{ |
|
1746 |
if (__isSmallInteger(byteIndex)) { |
|
1747 |
unsigned char *cp; |
|
1748 |
INT sz; |
|
1749 |
||
1750 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1751 |
if (cp) { |
|
1752 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
1753 |
char ch; |
|
1754 |
||
1755 |
if (idx < sz) { |
|
1756 |
ch = cp[idx] & 0xFF; |
|
1757 |
RETURN (__mkSmallInteger( ch )); |
|
1758 |
} |
|
1759 |
} |
|
1760 |
} |
|
1761 |
%}. |
|
1762 |
||
1763 |
^ self at:byteIndex |
|
3459 | 1764 |
|
1765 |
" |
|
1766 |
|b| |
|
19351 | 1767 |
b := ByteArray new:3. |
3459 | 1768 |
b at:1 put:16rFF. |
1769 |
b at:2 put:16r7F. |
|
19351 | 1770 |
b at:3 put:16r80. |
1771 |
b byteAt:1. |
|
1772 |
b byteAt:2. |
|
1773 |
b byteAt:3. |
|
1774 |
" |
|
1775 |
||
1776 |
"Modified: / 01-07-1996 / 21:13:53 / cg" |
|
1777 |
"Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
|
1778 |
! |
|
1779 |
||
1780 |
byteAt:byteIndex put:anInteger |
|
1781 |
"set the byte at byteIndex as an unsigned 8 bit value in the range 0..255. |
|
1782 |
The index is a smalltalk index (i.e. 1-based)." |
|
1783 |
||
1784 |
%{ |
|
1785 |
if (__isSmallInteger(byteIndex) && __isSmallInteger(anInteger)) { |
|
1786 |
unsigned char *cp; |
|
1787 |
INT sz; |
|
1788 |
INT val = __intVal(anInteger); |
|
1789 |
||
1790 |
if ( ((unsigned INT)val) <= 0xFF ) { |
|
1791 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1792 |
if (cp) { |
|
1793 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
1794 |
||
1795 |
if (idx < sz) { |
|
1796 |
cp[idx] = val & 0xFF; |
|
1797 |
RETURN (anInteger); |
|
1798 |
} |
|
1799 |
} |
|
1800 |
} |
|
1801 |
} |
|
1802 |
%}. |
|
1803 |
||
1804 |
^ self at:byteIndex put:anInteger |
|
1805 |
||
1806 |
" |
|
1807 |
|b| |
|
1808 |
b := ByteArray new:3. |
|
1809 |
b byteAt:1 put:16rFF. |
|
1810 |
b byteAt:2 put:16r7F. |
|
1811 |
b byteAt:3 put:16r80. |
|
1812 |
b signedByteAt:1. |
|
1813 |
b signedByteAt:2. |
|
1814 |
b signedByteAt:3. |
|
1815 |
" |
|
1816 |
! |
|
1817 |
||
1818 |
signedByteAt:byteIndex |
|
1819 |
"return the byte at byteIndex as a signed 8 bit value in the range -128..+127. |
|
1820 |
The index is a smalltalk index (i.e. 1-based). |
|
1821 |
This may be worth a primitive." |
|
1822 |
||
1823 |
%{ |
|
1824 |
/* |
|
1825 |
* handle the most common cases fast ... |
|
1826 |
*/ |
|
1827 |
if (__isSmallInteger(byteIndex)) { |
|
1828 |
unsigned char *cp; |
|
1829 |
INT sz; |
|
1830 |
||
1831 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1832 |
if (cp) { |
|
1833 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
1834 |
char ch; |
|
1835 |
||
1836 |
if (idx < sz) { |
|
1837 |
cp += idx; |
|
1838 |
ch = cp[0]; |
|
1839 |
# ifndef HAS_SIGNED_CHAR |
|
1840 |
if ( (unsigned int)ch >= 0x80 ) { |
|
1841 |
ch = ch - 0x100; |
|
1842 |
} |
|
1843 |
#endif |
|
1844 |
RETURN (__mkSmallInteger( ch )); |
|
1845 |
} |
|
1846 |
} |
|
1847 |
} |
|
1848 |
%}. |
|
1849 |
||
1850 |
^ (self byteAt:byteIndex) signExtendedByteValue |
|
1851 |
||
1852 |
" |
|
1853 |
|b| |
|
1854 |
b := ByteArray new:3. |
|
1855 |
b at:1 put:16rFF. |
|
1856 |
b at:2 put:16r7F. |
|
1857 |
b at:3 put:16r80. |
|
1858 |
b byteAt:1. |
|
1859 |
b byteAt:2. |
|
1860 |
b byteAt:3. |
|
3459 | 1861 |
" |
1862 |
||
13724 | 1863 |
"Modified: / 01-07-1996 / 21:13:53 / cg" |
1864 |
"Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
|
3459 | 1865 |
! |
1866 |
||
1867 |
signedByteAt:index put:aSignedByteValue |
|
13724 | 1868 |
"return the byte at index as a signed 8 bit value in the range -128..+127. |
3459 | 1869 |
The index is a smalltalk index (i.e. 1-based). |
1870 |
Return the signedByteValue argument. |
|
1871 |
This may be worth a primitive." |
|
1872 |
||
1873 |
|b "{ Class: SmallInteger }"| |
|
1874 |
||
1875 |
aSignedByteValue >= 0 ifTrue:[ |
|
19351 | 1876 |
b := aSignedByteValue |
3459 | 1877 |
] ifFalse:[ |
19351 | 1878 |
b := 16r100 + aSignedByteValue |
3459 | 1879 |
]. |
19351 | 1880 |
self byteAt:index put:b. |
3459 | 1881 |
^ aSignedByteValue |
1882 |
||
1883 |
" |
|
1884 |
|b| |
|
1885 |
b := ByteArray new:2. |
|
1886 |
b signedByteAt:1 put:-1. |
|
13575 | 1887 |
b at:1 |
3459 | 1888 |
" |
1889 |
||
13724 | 1890 |
"Modified: / 01-07-1996 / 21:12:37 / cg" |
1891 |
"Modified (comment): / 26-09-2011 / 11:57:18 / cg" |
|
3459 | 1892 |
! ! |
1893 |
||
1894 |
!UninterpretedBytes methodsFor:'accessing-floats & doubles'! |
|
1895 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1896 |
doubleAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1897 |
"return the 8-bytes starting at index as a Float. |
3433 | 1898 |
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
|
1899 |
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
|
1900 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1901 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1902 |
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
|
1903 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1904 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1905 |
|
3433 | 1906 |
%{ |
1907 |
/* |
|
1908 |
* handle the most common cases fast ... |
|
1909 |
*/ |
|
1910 |
if (__isSmallInteger(index)) { |
|
19351 | 1911 |
unsigned char *cp; |
1912 |
INT sz; |
|
1913 |
||
1914 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1915 |
if (cp) { |
|
1916 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1917 |
||
1918 |
if ((idx+(sizeof(double)-1)) < sz) { |
|
1919 |
cp += idx; |
|
1920 |
/* |
|
1921 |
* aligned |
|
1922 |
*/ |
|
1923 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
1924 |
double dVal = ((double *)cp)[0]; |
|
1925 |
OBJ f; |
|
1926 |
||
1927 |
__qMKFLOAT(f, dVal); |
|
1928 |
RETURN (f); |
|
1929 |
} |
|
1930 |
} |
|
1931 |
} |
|
3433 | 1932 |
} |
1933 |
%}. |
|
1934 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1935 |
newFloat := Float basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1936 |
1 to:8 do:[:destIndex| |
19351 | 1937 |
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
|
1938 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1939 |
^ newFloat. |
3433 | 1940 |
|
1941 |
" |
|
1942 |
|b| |
|
1943 |
||
1944 |
b := ByteArray new:20. |
|
1945 |
b doubleAt:1 put:(Float pi). |
|
1946 |
Transcript showCR:b. |
|
1947 |
Transcript showCR:(b doubleAt:1) |
|
1948 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1949 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1950 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1951 |
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
|
1952 |
"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
|
1953 |
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
|
1954 |
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
|
1955 |
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
|
1956 |
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
|
1957 |
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
|
1958 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1959 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1960 |
|
18284 | 1961 |
msb == IsBigEndian ifTrue:[ |
19351 | 1962 |
^ 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
|
1963 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1964 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1965 |
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
|
1966 |
1 to:8 do:[:destIndex| |
19351 | 1967 |
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
|
1968 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1969 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1970 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1971 |
"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
|
1972 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1973 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1974 |
doubleAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1975 |
"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
|
1976 |
starting at index. |
3433 | 1977 |
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
|
1978 |
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
|
1979 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1980 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1981 |
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
|
1982 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1983 |
|flt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1984 |
|
3433 | 1985 |
%{ |
1986 |
/* |
|
1987 |
* handle the most common cases fast ... |
|
1988 |
*/ |
|
16320 | 1989 |
if (__isSmallInteger(index)) { |
19351 | 1990 |
unsigned char *cp; |
1991 |
INT sz; |
|
1992 |
||
1993 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1994 |
if (cp) { |
|
1995 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1996 |
||
1997 |
if ((idx+(sizeof(double)-1)) < sz) { |
|
1998 |
cp += idx; |
|
1999 |
/* |
|
2000 |
* aligned |
|
2001 |
*/ |
|
2002 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
2003 |
if (__isFloat(aFloat)) { |
|
2004 |
((double *)cp)[0] = __floatVal(aFloat); |
|
2005 |
RETURN (aFloat); |
|
2006 |
} |
|
2007 |
if (__isShortFloat(aFloat)) { |
|
2008 |
((double *)cp)[0] = (double)(__shortFloatVal(aFloat)); |
|
2009 |
RETURN (aFloat); |
|
2010 |
} |
|
2011 |
if (__isSmallInteger(aFloat)) { |
|
2012 |
((double *)cp)[0] = (double)(__intVal(aFloat)); |
|
2013 |
RETURN (aFloat); |
|
2014 |
} |
|
2015 |
} |
|
2016 |
} |
|
2017 |
} |
|
3433 | 2018 |
} |
2019 |
%}. |
|
2020 |
||
16320 | 2021 |
flt := aFloat asFloat. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2022 |
1 to:8 do:[:srcIndex| |
19351 | 2023 |
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
|
2024 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2025 |
^ aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2026 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2027 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2028 |
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
|
2029 |
"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
|
2030 |
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
|
2031 |
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
|
2032 |
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
|
2033 |
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
|
2034 |
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
|
2035 |
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
|
2036 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2037 |
|flt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2038 |
|
18284 | 2039 |
msb == IsBigEndian ifTrue:[ |
19351 | 2040 |
^ 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
|
2041 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2042 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2043 |
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
|
2044 |
1 to:8 do:[:srcIndex| |
19351 | 2045 |
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
|
2046 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2047 |
^ aFloat |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2048 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2049 |
"Created: / 15.5.1998 / 17:22:27 / cg" |
3447 | 2050 |
"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
|
2051 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2052 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2053 |
floatAt:index |
3434 | 2054 |
"return the 4-bytes starting at index as a ShortFloat. |
3433 | 2055 |
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
|
2056 |
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
|
2057 |
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
|
2058 |
a float object which keeps an 8-byte double internally. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2059 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2060 |
float representation and order - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2061 |
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
|
2062 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2063 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2064 |
|
3434 | 2065 |
%{ |
2066 |
/* |
|
2067 |
* handle the most common cases fast ... |
|
2068 |
*/ |
|
2069 |
if (__isSmallInteger(index)) { |
|
19351 | 2070 |
unsigned char *cp; |
2071 |
INT sz; |
|
2072 |
||
2073 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2074 |
if (cp) { |
|
2075 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
2076 |
||
2077 |
if ((idx+(sizeof(float)-1)) < sz) { |
|
2078 |
cp += idx; |
|
2079 |
/* |
|
2080 |
* aligned |
|
2081 |
*/ |
|
2082 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
2083 |
float fVal = ((float *)cp)[0]; |
|
2084 |
OBJ f; |
|
2085 |
||
2086 |
__qMKSFLOAT(f, fVal); |
|
2087 |
RETURN (f); |
|
2088 |
} |
|
2089 |
} |
|
2090 |
} |
|
3434 | 2091 |
} |
2092 |
%}. |
|
2093 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2094 |
newFloat := ShortFloat basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2095 |
1 to:4 do:[:destIndex| |
19351 | 2096 |
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
|
2097 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2098 |
^ newFloat. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2099 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2100 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2101 |
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
|
2102 |
"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
|
2103 |
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
|
2104 |
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
|
2105 |
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
|
2106 |
a float object which keeps an 8-byte double internally. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2107 |
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
|
2108 |
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
|
2109 |
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
|
2110 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2111 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2112 |
|
18284 | 2113 |
msb == IsBigEndian ifTrue:[ |
19351 | 2114 |
^ 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
|
2115 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2116 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2117 |
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
|
2118 |
1 to:4 do:[:destIndex| |
19351 | 2119 |
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
|
2120 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2121 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2122 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2123 |
"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
|
2124 |
"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
|
2125 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2126 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2127 |
floatAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2128 |
"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
|
2129 |
starting at index. |
3433 | 2130 |
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
|
2131 |
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
|
2132 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2133 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2134 |
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
|
2135 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2136 |
|sflt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2137 |
|
3434 | 2138 |
%{ |
2139 |
/* |
|
2140 |
* handle the most common cases fast ... |
|
2141 |
*/ |
|
16320 | 2142 |
if (__isSmallInteger(index)) { |
19351 | 2143 |
unsigned char *cp; |
2144 |
INT sz; |
|
2145 |
||
2146 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2147 |
if (cp) { |
|
2148 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
2149 |
||
2150 |
if ((idx+(sizeof(float)-1)) < sz) { |
|
2151 |
cp += idx; |
|
2152 |
/* |
|
2153 |
* aligned |
|
2154 |
*/ |
|
2155 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
2156 |
if (__isShortFloat(aFloat)) { |
|
2157 |
((float *)cp)[0] = __shortFloatVal(aFloat); |
|
2158 |
RETURN (self); |
|
2159 |
} |
|
2160 |
if (__isFloat(aFloat)) { |
|
2161 |
((float *)cp)[0] = (float)__floatVal(aFloat); |
|
2162 |
RETURN (self); |
|
2163 |
} |
|
2164 |
if (__isSmallInteger(aFloat)) { |
|
2165 |
((float *)cp)[0] = (float)__intVal(aFloat); |
|
2166 |
RETURN (self); |
|
2167 |
} |
|
2168 |
// bail out to smalltalk code |
|
2169 |
} |
|
2170 |
} |
|
2171 |
} |
|
3434 | 2172 |
} |
2173 |
%}. |
|
2174 |
||
16320 | 2175 |
sflt := aFloat asShortFloat. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2176 |
1 to:4 do:[:srcIndex| |
19351 | 2177 |
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
|
2178 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2179 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2180 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2181 |
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
|
2182 |
"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
|
2183 |
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
|
2184 |
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
|
2185 |
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
|
2186 |
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
|
2187 |
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
|
2188 |
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
|
2189 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2190 |
|sflt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2191 |
|
18284 | 2192 |
msb == IsBigEndian ifTrue:[ |
19351 | 2193 |
self floatAt:index put:aFloat. |
2194 |
^ self. |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2195 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2196 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2197 |
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
|
2198 |
1 to:4 do:[:srcIndex| |
19351 | 2199 |
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
|
2200 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2201 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2202 |
"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
|
2203 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
2204 |
|
3323 | 2205 |
ieeeDoubleAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2206 |
"retrieve the 8 bytes starting at index as a float. |
3433 | 2207 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2208 |
The 8 bytes are assumed to be in IEEE floating point single precision |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2209 |
number format." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2210 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2211 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2212 |
currently, we assume that the machines native number format is already |
3323 | 2213 |
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
|
2214 |
to an IBM 370 or old VAX etc. |
3323 | 2215 |
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
|
2216 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2217 |
" |
9258 | 2218 |
Float isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2219 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2220 |
^ self doubleAt:index |
3323 | 2221 |
|
2222 |
"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
|
2223 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2224 |
|
3323 | 2225 |
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
|
2226 |
"store the value of the argument, aFloat into the receiver |
3433 | 2227 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2228 |
starting at index. Storage is in IEEE floating point double precision format. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2229 |
(i.e. 8 bytes are stored)." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2230 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2231 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2232 |
currently, we assume that the machines native number format is already |
3323 | 2233 |
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
|
2234 |
to an IBM 370 or old VAX etc. |
3323 | 2235 |
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
|
2236 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2237 |
" |
9258 | 2238 |
Float isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2239 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2240 |
^ self doubleAt:index put:aFloat |
3323 | 2241 |
|
2242 |
"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
|
2243 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2244 |
|
3323 | 2245 |
ieeeFloatAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2246 |
"retrieve the 4 bytes starting at index as a float. |
3433 | 2247 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2248 |
The 4 bytes are assumed to be in IEEE floating point single precision |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2249 |
number format." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2250 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2251 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2252 |
currently, we assume that the machines native number format is already |
3323 | 2253 |
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
|
2254 |
to an IBM 370 or old VAX etc. |
3323 | 2255 |
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
|
2256 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2257 |
" |
9258 | 2258 |
ShortFloat isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2259 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2260 |
^ self floatAt:index |
3323 | 2261 |
|
2262 |
"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
|
2263 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2264 |
|
3323 | 2265 |
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
|
2266 |
"store the value of the argument, aFloat into the receiver |
13575 | 2267 |
starting at index, which is a smalltalk index (i.e. 1-based). |
3433 | 2268 |
Storage is in IEEE floating point single precision format. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2269 |
(i.e. 4 bytes are stored). Since ST/X floats are really doubles, the low- |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2270 |
order 4 bytes of the precision is lost." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2271 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2272 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2273 |
currently, we assume that the machines native number format is already |
3323 | 2274 |
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
|
2275 |
to an IBM 370 or old VAX etc. |
3323 | 2276 |
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
|
2277 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2278 |
" |
9258 | 2279 |
ShortFloat isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 2280 |
|
16320 | 2281 |
self floatAt:index put:aFloat |
3323 | 2282 |
|
2283 |
"Created: / 5.3.1998 / 10:51:11 / stefan" |
|
3459 | 2284 |
! ! |
2285 |
||
13724 | 2286 |
!UninterpretedBytes methodsFor:'accessing-longlongs (64bit)'! |
3459 | 2287 |
|
19349 | 2288 |
signedInt64At:index |
3459 | 2289 |
"return the 8-bytes starting at index as a signed Integer. |
2290 |
The index is a smalltalk index (i.e. 1-based). |
|
2291 |
The value is retrieved in the machines natural byte order. |
|
2292 |
This may be worth a primitive." |
|
2293 |
||
2294 |
|w| |
|
2295 |
||
19349 | 2296 |
w := self unsignedInt64At:index bigEndian:IsBigEndian. |
3459 | 2297 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
19349 | 2298 |
^ w - (16r10000000000000000) |
3459 | 2299 |
]. |
2300 |
^ w |
|
2301 |
||
2302 |
" |
|
2303 |
|b| |
|
2304 |
b := ByteArray new:4. |
|
19349 | 2305 |
b unsignedInt64At:1 put:16rFFFFFFFFFFFFFFFF. |
2306 |
(b signedInt64At:1) |
|
3459 | 2307 |
" |
2308 |
||
2309 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
2310 |
"Created: / 5.3.1998 / 14:40:05 / stefan" |
|
2311 |
"Modified: / 5.3.1998 / 14:58:32 / stefan" |
|
2312 |
! |
|
2313 |
||
19349 | 2314 |
signedInt64At:index MSB:msb |
3459 | 2315 |
"return the 8-bytes starting at index as a signed Integer. |
2316 |
The index is a smalltalk index (i.e. 1-based). |
|
2317 |
The value is retrieved in the given byte order. |
|
2318 |
This may be worth a primitive." |
|
2319 |
||
2320 |
|w| |
|
2321 |
||
19349 | 2322 |
w := self unsignedInt64At:index MSB:msb. |
3459 | 2323 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
19349 | 2324 |
^ w - (16r10000000000000000) |
3459 | 2325 |
]. |
2326 |
^ w |
|
2327 |
||
2328 |
" |
|
2329 |
|b| |
|
2330 |
b := ByteArray new:4. |
|
2331 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
13575 | 2332 |
(b longLongAt:1 msb:true) |
3459 | 2333 |
" |
2334 |
||
2335 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
2336 |
"Created: / 5.3.1998 / 14:40:54 / stefan" |
|
2337 |
"Modified: / 9.5.1998 / 01:10:59 / cg" |
|
2338 |
! |
|
2339 |
||
19349 | 2340 |
signedInt64At:byteIndex put:anInteger |
2341 |
"store a signed longLong (64bit) integer. |
|
2342 |
The index is a smalltalk index (i.e. 1-based). |
|
2343 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
2344 |
||
2345 |
^ self signedInt64At:byteIndex put:anInteger MSB:IsBigEndian |
|
2346 |
! |
|
2347 |
||
2348 |
signedInt64At:byteIndex put:anInteger MSB:msb |
|
3459 | 2349 |
"store a signed longLong (64bit) integer. |
2350 |
The index is a smalltalk index (i.e. 1-based). |
|
2351 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
2352 |
||
7813 | 2353 |
|v| |
3459 | 2354 |
|
7813 | 2355 |
v := anInteger. |
2356 |
anInteger < 0 ifTrue:[ |
|
19349 | 2357 |
v := v + 16r10000000000000000 |
7813 | 2358 |
]. |
19349 | 2359 |
self unsignedInt64At:byteIndex put:v MSB:msb. |
2360 |
^ anInteger |
|
3459 | 2361 |
|
2362 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
2363 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
2364 |
! |
|
2365 |
||
19349 | 2366 |
unsignedInt64At:byteIndex |
2367 |
"return the 8-bytes starting at index in the machine's native |
|
2368 |
byteorder as an unsigned integer. |
|
2369 |
The index is a smalltalk index (i.e. 1-based)" |
|
2370 |
||
2371 |
^ self unsignedInt64At:byteIndex MSB:IsBigEndian |
|
2372 |
||
2373 |
" |
|
2374 |
|b| |
|
2375 |
||
2376 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
2377 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
|
2378 |
" |
|
2379 |
||
2380 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
2381 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
2382 |
! |
|
2383 |
||
2384 |
unsignedInt64At:byteIndex MSB:msb |
|
2385 |
"return the 8-bytes starting at index as an unsigned integer. |
|
3459 | 2386 |
The index is a smalltalk index (i.e. 1-based). |
2387 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
2388 |
||
13575 | 2389 |
|l |
3459 | 2390 |
bIdx "{ Class: SmallInteger }" |
2391 |
delta "{ Class: SmallInteger }"| |
|
2392 |
||
2393 |
l := LargeInteger basicNew numberOfDigits:8. |
|
2394 |
msb ifTrue:[ |
|
19349 | 2395 |
bIdx := byteIndex + 7. |
2396 |
delta := -1 |
|
3459 | 2397 |
] ifFalse:[ |
19349 | 2398 |
bIdx := byteIndex. |
2399 |
delta := 1 |
|
3459 | 2400 |
]. |
2401 |
1 to:8 do:[:i | |
|
19351 | 2402 |
l digitAt:i put:(self byteAt:bIdx). |
19349 | 2403 |
bIdx := bIdx + delta |
3459 | 2404 |
]. |
2405 |
^ l compressed |
|
2406 |
||
2407 |
" |
|
2408 |
|b| |
|
2409 |
||
2410 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
13575 | 2411 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
3459 | 2412 |
" |
2413 |
||
2414 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
2415 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
2416 |
! |
|
2417 |
||
19349 | 2418 |
unsignedInt64At:byteIndex put:anInteger |
3459 | 2419 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
2420 |
The index is a smalltalk index (i.e. 1-based). |
|
2421 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
19349 | 2422 |
The value is stored in the machine's natural byteorder." |
2423 |
||
2424 |
^ self unsignedInt64At:byteIndex put:anInteger MSB:IsBigEndian |
|
2425 |
||
2426 |
" |
|
2427 |
|b| |
|
2428 |
b := ByteArray new:10. |
|
2429 |
b unsignedInt64At:1 put:16r0807060504030201 MSB:false. |
|
2430 |
b unsignedInt64At:1 put:16r0807060504030201 MSB:true. |
|
2431 |
b inspect |
|
2432 |
" |
|
2433 |
||
2434 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
3459 | 2435 |
! |
2436 |
||
19349 | 2437 |
unsignedInt64At:byteIndex put:anInteger MSB:msb |
3459 | 2438 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
2439 |
The index is a smalltalk index (i.e. 1-based). |
|
2440 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
2441 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
2442 |
||
2443 |
|bIdx "{ Class: SmallInteger }" |
|
2444 |
delta "{ Class: SmallInteger }"| |
|
2445 |
||
2446 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[ |
|
19349 | 2447 |
^ self elementBoundsError:anInteger |
3459 | 2448 |
]. |
2449 |
||
2450 |
msb ifTrue:[ |
|
19349 | 2451 |
bIdx := byteIndex + 7. |
2452 |
delta := -1 |
|
3459 | 2453 |
] ifFalse:[ |
19349 | 2454 |
bIdx := byteIndex. |
2455 |
delta := 1 |
|
3459 | 2456 |
]. |
2457 |
1 to:8 do:[:i | |
|
19351 | 2458 |
self byteAt:bIdx put:(anInteger digitAt:i). |
19349 | 2459 |
bIdx := bIdx + delta. |
3459 | 2460 |
]. |
2461 |
^ anInteger |
|
2462 |
||
2463 |
" |
|
2464 |
|b| |
|
2465 |
b := ByteArray new:8. |
|
2466 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
2467 |
b inspect |
|
2468 |
" |
|
2469 |
||
2470 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
2471 |
! ! |
|
2472 |
||
13724 | 2473 |
!UninterpretedBytes methodsFor:'accessing-longs (32bit)'! |
3459 | 2474 |
|
11850 | 2475 |
pointerAt:index |
2476 |
"get a pointer starting at index as ExternalAddress. |
|
13575 | 2477 |
The index is a smalltalk index (i.e. 1-based). |
11850 | 2478 |
Only aligned accesses are allowed." |
2479 |
||
2480 |
%{ |
|
2481 |
if (__isSmallInteger(index)) { |
|
13575 | 2482 |
unsigned char *cp; |
15004 | 2483 |
INT sz; |
13575 | 2484 |
|
2485 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2486 |
if (cp) { |
|
2487 |
unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1; |
|
13576 | 2488 |
char *pointer; |
13575 | 2489 |
|
2490 |
if ((idx+(sizeof(pointer)-1)) < sz) { |
|
2491 |
cp += idx; |
|
2492 |
/* |
|
2493 |
* aligned |
|
2494 |
*/ |
|
2495 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
2496 |
pointer = ((char **)cp)[0]; |
|
2497 |
RETURN (__MKEXTERNALADDRESS(pointer)); |
|
15004 | 2498 |
} else { |
2499 |
#if 0 |
|
2500 |
printf("cp UNALIGNED (%"_lx_")\n", (INT)cp); |
|
2501 |
#endif |
|
13575 | 2502 |
} |
15004 | 2503 |
} else { |
2504 |
#if 0 |
|
2505 |
printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n", |
|
2506 |
idx, (int)(sizeof(pointer)-1), sz); |
|
2507 |
#endif |
|
13575 | 2508 |
} |
15004 | 2509 |
} else { |
2510 |
#if 0 |
|
2511 |
printf("cp is NULL\n"); |
|
2512 |
#endif |
|
13575 | 2513 |
} |
15004 | 2514 |
} else { |
2515 |
#if 0 |
|
2516 |
printf("bad index\n"); |
|
2517 |
#endif |
|
11850 | 2518 |
} |
2519 |
bad:; |
|
2520 |
%}. |
|
2521 |
||
2522 |
self primitiveFailed. |
|
2523 |
||
2524 |
" |
|
2525 |
|b| |
|
2526 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
13575 | 2527 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
11850 | 2528 |
Transcript showCR:((b unsignedLongAt:1) printStringRadix:16). |
2529 |
Transcript showCR:((b pointerAt:1)). |
|
2530 |
" |
|
2531 |
! |
|
2532 |
||
6492 | 2533 |
pointerAt:index put:value |
15004 | 2534 |
"set the pointer starting at index from the integer or externalAddress value. |
13575 | 2535 |
The index is a smalltalk index (i.e. 1-based). |
6492 | 2536 |
Only aligned accesses are allowed. |
2537 |
The value is either an ExternalAddress or ExternalBytes" |
|
2538 |
||
2539 |
%{ |
|
2540 |
OBJ *pointer; |
|
2541 |
||
7814
c649ba9fd538
#pointerAt:put: now works for ExternalAddressLike objects
Stefan Vogel <sv@exept.de>
parents:
7813
diff
changeset
|
2542 |
if (__isExternalAddressLike(value)) { |
13575 | 2543 |
pointer = __externalAddressVal(value); |
7197
a68adb223592
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7193
diff
changeset
|
2544 |
} else if (__isExternalBytesLike(value)) { |
13575 | 2545 |
pointer = __externalBytesVal(value); |
2546 |
if (pointer == (OBJ *)0) |
|
2547 |
pointer = 0; |
|
11852 | 2548 |
} else if (value == nil) { |
13575 | 2549 |
pointer = 0; |
15004 | 2550 |
} else if (__isSmallInteger(value)) { |
2551 |
pointer = (OBJ *)__intVal(value); |
|
2552 |
} else { |
|
2553 |
if ((pointer = (OBJ *)__unsignedLongIntVal(value)) == 0) { |
|
2554 |
goto bad; |
|
2555 |
} |
|
2556 |
} |
|
6492 | 2557 |
|
2558 |
if (__isSmallInteger(index)) { |
|
13575 | 2559 |
unsigned char *cp; |
15004 | 2560 |
INT sz; |
13575 | 2561 |
|
2562 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2563 |
if (cp) { |
|
2564 |
unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1; |
|
2565 |
||
2566 |
if ((idx+(sizeof(pointer)-1)) < sz) { |
|
2567 |
cp += idx; |
|
2568 |
/* |
|
2569 |
* aligned |
|
2570 |
*/ |
|
2571 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
2572 |
((char **)cp)[0] = (char *) pointer; |
|
2573 |
RETURN (value); |
|
2574 |
} |
|
2575 |
} |
|
2576 |
} |
|
6492 | 2577 |
} |
2578 |
bad:; |
|
2579 |
%}. |
|
2580 |
||
2581 |
self primitiveFailed. |
|
2582 |
||
2583 |
" |
|
2584 |
|b| |
|
2585 |
b := ByteArray new:ExternalAddress pointerSize. |
|
13575 | 2586 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
2587 |
(b unsignedLongAt:1) printStringRadix:16 |
|
6492 | 2588 |
" |
2589 |
||
2590 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
|
2591 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
2592 |
! |
|
2593 |
||
19345 | 2594 |
pointerValueAt:index |
2595 |
"get a pointer starting at index as Integer. |
|
2596 |
The index is a smalltalk index (i.e. 1-based). |
|
2597 |
Only aligned accesses are allowed." |
|
2598 |
||
2599 |
%{ |
|
2600 |
if (__isSmallInteger(index)) { |
|
2601 |
unsigned char *cp; |
|
2602 |
INT sz; |
|
2603 |
||
2604 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2605 |
if (cp) { |
|
2606 |
unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1; |
|
2607 |
char *pointer; |
|
2608 |
||
2609 |
if ((idx+(sizeof(pointer)-1)) < sz) { |
|
2610 |
cp += idx; |
|
2611 |
/* |
|
2612 |
* aligned |
|
2613 |
*/ |
|
2614 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
2615 |
pointer = ((char **)cp)[0]; |
|
2616 |
RETURN (__MKUINT((INT)(pointer))); |
|
2617 |
} else { |
|
2618 |
#if 0 |
|
2619 |
printf("cp UNALIGNED (%"_lx_")\n", (INT)cp); |
|
2620 |
#endif |
|
2621 |
} |
|
2622 |
} else { |
|
2623 |
#if 0 |
|
2624 |
printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n", |
|
2625 |
idx, (int)(sizeof(pointer)-1), sz); |
|
2626 |
#endif |
|
2627 |
} |
|
2628 |
} else { |
|
2629 |
#if 0 |
|
2630 |
printf("cp is NULL\n"); |
|
2631 |
#endif |
|
2632 |
} |
|
2633 |
} else { |
|
2634 |
#if 0 |
|
2635 |
printf("bad index\n"); |
|
2636 |
#endif |
|
2637 |
} |
|
2638 |
bad:; |
|
2639 |
%}. |
|
2640 |
||
2641 |
self primitiveFailed. |
|
2642 |
||
2643 |
" |
|
2644 |
|b| |
|
2645 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
2646 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
2647 |
Transcript showCR:((b unsignedLongAt:1) printStringRadix:16). |
|
2648 |
Transcript showCR:((b pointerAt:1)). |
|
2649 |
Transcript showCR:((b pointerValueAt:1)). |
|
2650 |
" |
|
2651 |
! |
|
2652 |
||
19349 | 2653 |
signedInt32At:byteIndex |
2654 |
"return the 4-bytes starting at byteIndex as a signed Integer. |
|
3433 | 2655 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 2656 |
The value is retrieved in the machine's natural byte order, |
2657 |
therefore, this should only be used for byte-data which is |
|
2658 |
only used inside this machine. |
|
2659 |
To setup data packets which are to be sent to other machines, |
|
2660 |
or stored into a file, always use longAt:MSB: and specify |
|
2661 |
a definite byteOrder." |
|
2662 |
||
2663 |
|w| |
|
2664 |
||
2665 |
%{ |
|
2666 |
/* |
|
2667 |
* handle the most common cases fast ... |
|
2668 |
*/ |
|
2669 |
if (__isSmallInteger(byteIndex)) { |
|
2670 |
unsigned char *cp; |
|
2671 |
INT sz; |
|
2672 |
||
2673 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2674 |
if (cp) { |
|
2675 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
2676 |
||
2677 |
if ((idx+(sizeof(int)-1)) < sz) { |
|
2678 |
cp += idx; |
|
2679 |
#if defined(__i386__) |
|
2680 |
/* |
|
2681 |
* aligned or not, we dont care (i386 can do both) |
|
2682 |
*/ |
|
2683 |
{ |
|
2684 |
int iVal = ((int *)cp)[0]; |
|
2685 |
||
2686 |
RETURN (__MKINT(iVal)); |
|
2687 |
} |
|
2688 |
#else |
|
2689 |
/* |
|
2690 |
* aligned |
|
2691 |
*/ |
|
2692 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
2693 |
int iVal = ((int *)cp)[0]; |
|
2694 |
||
2695 |
# if __POINTER_SIZE__ == 8 |
|
2696 |
RETURN (__mkSmallInteger(iVal)); |
|
2697 |
# else |
|
2698 |
RETURN (__MKINT(iVal)); |
|
2699 |
# endif |
|
2700 |
} |
|
2701 |
#endif |
|
2702 |
} |
|
2703 |
} |
|
2704 |
} |
|
2705 |
%}. |
|
2706 |
||
2707 |
w := self unsignedLongAt:byteIndex. |
|
2708 |
(w > (16r7FFFFFFF)) ifTrue:[ |
|
2709 |
^ w - (16r100000000) |
|
2710 |
]. |
|
2711 |
^ w |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2712 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2713 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2714 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2715 |
b := ByteArray new:4. |
19349 | 2716 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
2717 |
(b longAt:1) |
|
4515 | 2718 |
" |
19349 | 2719 |
|
2720 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
2721 |
"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
|
2722 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2723 |
|
19349 | 2724 |
signedInt32At:byteIndex MSB:msb |
2725 |
"return the 4-bytes starting at byteIndex as a (signed) Integer. |
|
2726 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
4515 | 2727 |
The value is retrieved MSB-first, if the msb-arg is true; |
2728 |
LSB-first otherwise." |
|
2729 |
||
13575 | 2730 |
|val |
4515 | 2731 |
ival "{ Class: SmallInteger }" |
2732 |
i "{ Class: SmallInteger }" |
|
19349 | 2733 |
bHH "{ Class: SmallInteger }" |
2734 |
bHL "{ Class: SmallInteger }" |
|
2735 |
bLH "{ Class: SmallInteger }" |
|
2736 |
bLL "{ Class: SmallInteger }"| |
|
4515 | 2737 |
|
2738 |
%{ |
|
2739 |
/* |
|
2740 |
* handle the most common cases fast ... |
|
2741 |
*/ |
|
19349 | 2742 |
if (__isSmallInteger(byteIndex)) { |
19047 | 2743 |
unsigned char *cp; |
2744 |
INT sz; |
|
2745 |
||
2746 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2747 |
if (cp) { |
|
19349 | 2748 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
19047 | 2749 |
int iVal; |
2750 |
||
19349 | 2751 |
cp += idx; |
2752 |
||
19047 | 2753 |
if ((idx+(sizeof(int)-1)) < sz) { |
2754 |
||
2755 |
if (msb == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2756 |
#if defined(__MSBFIRST__) |
19047 | 2757 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
2758 |
/* |
|
2759 |
* aligned |
|
2760 |
*/ |
|
2761 |
iVal = ((int *)cp)[0]; |
|
2762 |
} else |
|
4515 | 2763 |
#endif |
19047 | 2764 |
{ |
2765 |
iVal = cp[0]; |
|
2766 |
iVal = (iVal << 8) | cp[1]; |
|
2767 |
iVal = (iVal << 8) | cp[2]; |
|
2768 |
iVal = (iVal << 8) | cp[3]; |
|
2769 |
} |
|
2770 |
} else { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2771 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
19047 | 2772 |
/* |
19349 | 2773 |
* aligned or not - we don't care |
19047 | 2774 |
* (i386 can fetch unaligned) |
2775 |
*/ |
|
2776 |
iVal = ((int *)cp)[0]; |
|
4515 | 2777 |
#else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2778 |
# if defined(__LSBFIRST__) |
19047 | 2779 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
2780 |
/* |
|
2781 |
* aligned |
|
2782 |
*/ |
|
2783 |
iVal = ((int *)cp)[0]; |
|
2784 |
} else |
|
4515 | 2785 |
# endif |
19047 | 2786 |
{ |
2787 |
iVal = cp[3]; |
|
2788 |
iVal = (iVal << 8) | cp[2]; |
|
2789 |
iVal = (iVal << 8) | cp[1]; |
|
2790 |
iVal = (iVal << 8) | cp[0]; |
|
2791 |
} |
|
4515 | 2792 |
#endif |
19047 | 2793 |
} |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2794 |
#if __POINTER_SIZE__ == 8 |
19047 | 2795 |
RETURN (__mkSmallInteger(iVal)); |
4515 | 2796 |
#else |
19047 | 2797 |
RETURN (__MKINT(iVal)); |
4515 | 2798 |
#endif |
19047 | 2799 |
} |
2800 |
} |
|
4515 | 2801 |
} |
2802 |
%}. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2803 |
|
4515 | 2804 |
"/ fallBack code - non ByteArray-like receiver |
19349 | 2805 |
"/ or funny byteIndex |
2806 |
||
2807 |
i := byteIndex. |
|
4515 | 2808 |
msb ifFalse:[ |
19349 | 2809 |
bLL := self byteAt:i. |
2810 |
bLH := self byteAt:(i+1). |
|
2811 |
bHL := self byteAt:(i+2). |
|
2812 |
bHH := self byteAt:(i+3). |
|
2813 |
] ifTrue:[ |
|
2814 |
bHH := self byteAt:i. |
|
2815 |
bHL := self byteAt:(i+1). |
|
2816 |
bLH := self byteAt:(i+2). |
|
2817 |
bLL := self byteAt:(i+3). |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2818 |
]. |
19349 | 2819 |
ival := (bHH bitShift:8) + bHL. |
2820 |
ival := (ival bitShift:8) + bLH. |
|
2821 |
val := (ival bitShift:8) + bLL. |
|
4515 | 2822 |
|
2823 |
(val > (16r7FFFFFFF)) ifTrue:[ |
|
19047 | 2824 |
^ val - (16r100000000) |
4515 | 2825 |
]. |
2826 |
^ val |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2827 |
|
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 |
|b| |
4515 | 2830 |
|
2831 |
b := ByteArray withAll:#(1 2 3 4). |
|
19349 | 2832 |
(b signedInt32At:1 MSB:true) printStringRadix:16. |
2833 |
(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
|
2834 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2835 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2836 |
|
19349 | 2837 |
signedInt32At:byteIndex put:anInteger |
2838 |
"set the 4-bytes starting at index from the signed Integer anInteger. |
|
3433 | 2839 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 2840 |
The integer is stored in the machine's natural byte order." |
2841 |
||
2842 |
^ 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
|
2843 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2844 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2845 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2846 |
b := ByteArray new:4. |
19349 | 2847 |
b longAt:1 put:-1. |
2848 |
(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
|
2849 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2850 |
|
19349 | 2851 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
2852 |
"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
|
2853 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2854 |
|
19349 | 2855 |
signedInt32At:byteIndex put:anInteger MSB:msb |
2856 |
"set the 4-bytes starting at byteIndex from the signed Integer value. |
|
2857 |
The byteIndex is a smalltalk index (i.e. 1-based). |
|
2858 |
The value is stored in the machines natural byte order. |
|
2859 |
This may be worth a primitive. |
|
2860 |
||
2861 |
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
|
2862 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2863 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2864 |
|
19349 | 2865 |
%{ |
2866 |
/* |
|
2867 |
* handle the most common case fast ... |
|
2868 |
*/ |
|
2869 |
if (__isSmallInteger(byteIndex)) { |
|
2870 |
unsigned char *cp; |
|
2871 |
INT sz; |
|
2872 |
||
2873 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2874 |
if (cp) { |
|
2875 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
2876 |
||
2877 |
if ((idx+3) < sz) { |
|
2878 |
cp += idx; |
|
2879 |
||
2880 |
if (__isSmallInteger(anInteger)) { |
|
2881 |
INT __v = __intVal(anInteger); |
|
2882 |
||
2883 |
# if __POINTER_SIZE__ == 8 |
|
2884 |
if ((__v < -0x80000000L) || (__v > 0x7FFFFFFF)) { |
|
2885 |
goto badArg; |
|
2886 |
} |
|
2887 |
# endif |
|
2888 |
if (((INT)cp & 3) == 0) { |
|
2889 |
/* |
|
2890 |
* aligned |
|
2891 |
*/ |
|
2892 |
if ( |
|
2893 |
# ifdef __LSBFIRST__ |
|
2894 |
(msb == false) |
|
2895 |
# else |
|
2896 |
# ifdef __MSBFIRST__ |
|
2897 |
(msb == true) |
|
2898 |
# else |
|
2899 |
(0) |
|
2900 |
# endif |
|
2901 |
# endif |
|
2902 |
) { |
|
2903 |
((int *)cp)[0] = (int)__v; |
|
2904 |
RETURN (anInteger); |
|
2905 |
} |
|
2906 |
} |
|
2907 |
if (msb == false) { |
|
2908 |
cp[0] = __v & 0xFF; |
|
2909 |
cp[1] = (__v>>8) & 0xFF; |
|
2910 |
cp[2] = (__v>>16) & 0xFF; |
|
2911 |
cp[3] = (__v>>24) & 0xFF; |
|
2912 |
} else { |
|
2913 |
cp[0] = (__v>>24) & 0xFF; |
|
2914 |
cp[1] = (__v>>16) & 0xFF; |
|
2915 |
cp[2] = (__v>>8) & 0xFF; |
|
2916 |
cp[3] = __v & 0xFF; |
|
2917 |
} |
|
2918 |
RETURN (anInteger); |
|
2919 |
} |
|
2920 |
} |
|
2921 |
} |
|
2922 |
} |
|
2923 |
badArg: ; |
|
2924 |
%}. |
|
2925 |
||
2926 |
anInteger >= 0 ifTrue:[ |
|
2927 |
v := anInteger |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2928 |
] ifFalse:[ |
19349 | 2929 |
v := anInteger + 16r100000000 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2930 |
]. |
19349 | 2931 |
self unsignedInt32At:byteIndex put:v MSB:msb. |
2932 |
^ anInteger |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2933 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2934 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2935 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2936 |
b := ByteArray new:4. |
19349 | 2937 |
b longAt:1 put:-1. |
2938 |
(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
|
2939 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2940 |
|
19349 | 2941 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
2942 |
"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
|
2943 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2944 |
|
19349 | 2945 |
unsignedInt32At:byteIndex |
3323 | 2946 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
3433 | 2947 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 2948 |
The value is retrieved in the machines natural byte order." |
2949 |
||
2950 |
^ self unsignedInt32At:byteIndex MSB:IsBigEndian |
|
3323 | 2951 |
|
2952 |
" |
|
2953 |
|b| |
|
2954 |
||
2955 |
b := ByteArray withAll:#(1 2 3 4). |
|
19349 | 2956 |
(b unsignedInt32At:1) printStringRadix:16 |
3323 | 2957 |
" |
2958 |
||
19349 | 2959 |
"Modified: / 5.3.1998 / 14:57:35 / stefan" |
3323 | 2960 |
! |
2961 |
||
19349 | 2962 |
unsignedInt32At:byteIndex MSB:msb |
2963 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 2964 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 2965 |
The value is retrieved MSB-first, if the msb-arg is true; |
2966 |
LSB-first otherwise." |
|
2967 |
||
2968 |
|val |
|
2969 |
ival "{ Class: SmallInteger }" |
|
2970 |
i "{ Class: SmallInteger }" |
|
2971 |
bHH "{ Class: SmallInteger }" |
|
2972 |
bHL "{ Class: SmallInteger }" |
|
2973 |
bLH "{ Class: SmallInteger }" |
|
2974 |
bLL "{ Class: SmallInteger }"| |
|
2975 |
||
2976 |
%{ |
|
2977 |
/* |
|
2978 |
* handle the most common cases fast ... |
|
2979 |
*/ |
|
2980 |
if (__isSmallInteger(byteIndex)) { |
|
2981 |
unsigned char *cp; |
|
2982 |
INT sz; |
|
2983 |
||
2984 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2985 |
if (cp) { |
|
2986 |
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
2987 |
unsigned int iVal; |
|
2988 |
||
2989 |
if ((idx+(sizeof(int)-1)) < sz) { |
|
2990 |
cp += idx; |
|
2991 |
||
2992 |
if (msb == true) { |
|
2993 |
#if defined(__MSBFIRST__) |
|
2994 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
|
2995 |
/* |
|
2996 |
* aligned |
|
2997 |
*/ |
|
2998 |
iVal = ((unsigned int *)cp)[0]; |
|
2999 |
} else |
|
3000 |
#endif |
|
3001 |
{ |
|
3002 |
iVal = cp[0]; |
|
3003 |
iVal = (iVal << 8) | cp[1]; |
|
3004 |
iVal = (iVal << 8) | cp[2]; |
|
3005 |
iVal = (iVal << 8) | cp[3]; |
|
3006 |
} |
|
3007 |
} else { |
|
3008 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
|
3009 |
/* |
|
3010 |
* aligned or not - we dont care |
|
3011 |
* (i386 can fetch unaligned) |
|
3012 |
*/ |
|
3013 |
iVal = ((unsigned int *)cp)[0]; |
|
3014 |
#else |
|
3015 |
# if defined(__LSBFIRST__) |
|
3016 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
|
3017 |
/* |
|
3018 |
* aligned |
|
3019 |
*/ |
|
3020 |
iVal = ((unsigned int *)cp)[0]; |
|
3021 |
} else |
|
3022 |
# endif |
|
3023 |
{ |
|
3024 |
iVal = cp[3]; |
|
3025 |
iVal = (iVal << 8) | cp[2]; |
|
3026 |
iVal = (iVal << 8) | cp[1]; |
|
3027 |
iVal = (iVal << 8) | cp[0]; |
|
3028 |
} |
|
3029 |
#endif |
|
3030 |
} |
|
3031 |
#if __POINTER_SIZE__ == 8 |
|
3032 |
RETURN (__mkSmallInteger(iVal)); |
|
3033 |
#else |
|
3034 |
RETURN (__MKUINT(iVal)); |
|
3035 |
#endif |
|
3036 |
} |
|
3037 |
} |
|
3038 |
} |
|
3039 |
%}. |
|
3040 |
||
3041 |
"/ fallBack code - non ByteArray-like receiver |
|
3042 |
"/ or funny byteIndex |
|
3043 |
||
3044 |
i := byteIndex. |
|
3045 |
msb ifFalse:[ |
|
3046 |
bLL := self byteAt:i. |
|
3047 |
bLH := self byteAt:(i+1). |
|
3048 |
bHL := self byteAt:(i+2). |
|
3049 |
bHH := self byteAt:(i+3). |
|
3050 |
] ifTrue:[ |
|
3051 |
bHH := self byteAt:i. |
|
3052 |
bHL := self byteAt:(i+1). |
|
3053 |
bLH := self byteAt:(i+2). |
|
3054 |
bLL := self byteAt:(i+3). |
|
3055 |
]. |
|
3056 |
ival := (bHH bitShift:8) + bHL. |
|
3057 |
ival := (ival bitShift:8) + bLH. |
|
3058 |
val := (ival bitShift:8) + bLL. |
|
3059 |
^ val |
|
3323 | 3060 |
|
3061 |
" |
|
3062 |
|b| |
|
19349 | 3063 |
|
3064 |
b := ByteArray withAll:#(1 2 3 4). |
|
3065 |
(b unsignedInt32At:1 MSB:true) printStringRadix:16. |
|
3066 |
(b unsignedInt32At:1 MSB:false) printStringRadix:16 |
|
3323 | 3067 |
" |
3068 |
! |
|
3069 |
||
19349 | 3070 |
unsignedInt32At:byteIndex put:anInteger |
3071 |
"set the 4-bytes starting at index from the (unsigned) integer value. |
|
3433 | 3072 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 3073 |
The value must be in the range 0 to 16rFFFFFFFF. |
19349 | 3074 |
The value is stored in the machine's native byte order" |
3075 |
||
3076 |
^ self unsignedInt32At:byteIndex put:anInteger MSB:IsBigEndian |
|
3323 | 3077 |
|
3078 |
" |
|
3079 |
|b| |
|
3080 |
b := ByteArray new:8. |
|
19349 | 3081 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
3082 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
3083 |
b inspect |
|
3323 | 3084 |
" |
3085 |
||
3086 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
19349 | 3087 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
3088 |
! |
|
3089 |
||
3090 |
unsignedInt32At:byteIndex put:anInteger MSB:msb |
|
3091 |
"set the 4-bytes starting at index from the (unsigned) integer value. |
|
3459 | 3092 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 3093 |
The value must be in the range 0 to 16rFFFFFFFF. |
3094 |
The value is stored MSB-first if msb is true; LSB-first otherwise." |
|
3095 |
||
3096 |
|i "{ Class: SmallInteger }" |
|
3097 |
b1 "{ Class: SmallInteger }" |
|
3098 |
b2 "{ Class: SmallInteger }" |
|
3099 |
b3 "{ Class: SmallInteger }" |
|
3100 |
b4 "{ Class: SmallInteger }"| |
|
3101 |
||
3102 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFF]) ifTrue:[ |
|
3103 |
^ self elementBoundsError:anInteger |
|
3104 |
]. |
|
3105 |
||
3106 |
i := byteIndex. |
|
3107 |
msb ifTrue:[ |
|
3108 |
b1 := (anInteger digitAt:4). |
|
3109 |
b2 := (anInteger digitAt:3). |
|
3110 |
b3 := (anInteger digitAt:2). |
|
3111 |
b4 := (anInteger digitAt:1). |
|
3112 |
] ifFalse:[ |
|
3113 |
b1 := (anInteger digitAt:1). |
|
3114 |
b2 := (anInteger digitAt:2). |
|
3115 |
b3 := (anInteger digitAt:3). |
|
3116 |
b4 := (anInteger digitAt:4). |
|
3117 |
]. |
|
3118 |
self byteAt:i put:b1. |
|
3119 |
self byteAt:(i+1) put:b2. |
|
3120 |
self byteAt:(i+2) put:b3. |
|
3121 |
self byteAt:(i+3) put:b3. |
|
3122 |
^ anInteger |
|
3459 | 3123 |
|
3124 |
" |
|
3125 |
|b| |
|
19349 | 3126 |
b := ByteArray new:8. |
3127 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
|
3128 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
3459 | 3129 |
b inspect |
3130 |
" |
|
3131 |
||
19349 | 3132 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
3133 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
|
3134 |
! ! |
|
3135 |
||
3136 |
!UninterpretedBytes methodsFor:'accessing-shorts (16bit)'! |
|
3137 |
||
3138 |
signedInt16At:byteIndex |
|
3459 | 3139 |
"return the 2-bytes starting at index as a signed Integer. |
3140 |
The index is a smalltalk index (i.e. 1-based). |
|
3141 |
The value is retrieved in the machines natural byte order. |
|
3142 |
This may be worth a primitive." |
|
3143 |
||
19349 | 3144 |
^ (self unsignedInt16At:byteIndex) signExtendedShortValue |
3323 | 3145 |
|
3146 |
" |
|
3147 |
|b| |
|
3459 | 3148 |
b := ByteArray new:2. |
3149 |
b wordAt:1 put:16rFFFF. |
|
13575 | 3150 |
b signedWordAt:1 |
3323 | 3151 |
" |
3152 |
||
3459 | 3153 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
3323 | 3154 |
! |
3155 |
||
19349 | 3156 |
signedInt16At:byteIndex MSB:msb |
3459 | 3157 |
"return the 2-bytes starting at index as a signed Integer. |
3433 | 3158 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 3159 |
The value is retrieved in the machines natural byte order. |
3459 | 3160 |
This may be worth a primitive." |
3323 | 3161 |
|
19349 | 3162 |
^ (self unsignedInt16At:byteIndex MSB:msb) signExtendedShortValue |
3323 | 3163 |
|
3164 |
" |
|
3165 |
|b| |
|
3459 | 3166 |
b := ByteArray new:2. |
19349 | 3167 |
b wordAt:1 put:16rFFFF. |
3168 |
b signedWordAt:1 |
|
3459 | 3169 |
" |
3170 |
||
19349 | 3171 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
3459 | 3172 |
! |
3173 |
||
19349 | 3174 |
signedInt16At:index put:anInteger |
3459 | 3175 |
"set the 2-bytes starting at index from the signed Integer value. |
3176 |
The index is a smalltalk index (i.e. 1-based). |
|
3177 |
The stored value must be in the range -32768 .. +32676. |
|
19349 | 3178 |
The value is stored in the machine's natural byte order." |
3179 |
||
3180 |
^ self signedInt16At:index put:anInteger MSB:IsBigEndian |
|
3459 | 3181 |
|
3182 |
" |
|
3183 |
|b| |
|
19349 | 3184 |
b := ByteArray new:4. |
3185 |
b signedInt16At:1 put:-2. |
|
3186 |
b signedInt16At:3 put:-3. |
|
3323 | 3187 |
b inspect |
3188 |
" |
|
3189 |
||
19349 | 3190 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
3459 | 3191 |
! |
3192 |
||
19349 | 3193 |
signedInt16At:index put:anInteger MSB:msb |
3459 | 3194 |
"set the 2-bytes starting at index from the signed Integer value. |
3195 |
The index is a smalltalk index (i.e. 1-based). |
|
3196 |
The stored value must be in the range -32768 .. +32676. |
|
3197 |
The value is stored MSB-first, if the msb-arg is true; |
|
3198 |
LSB-first otherwise. |
|
3199 |
This may be worth a primitive." |
|
3200 |
||
3201 |
|v| |
|
3202 |
||
19349 | 3203 |
anInteger >= 0 ifTrue:[ |
3204 |
v := anInteger |
|
3459 | 3205 |
] ifFalse:[ |
19349 | 3206 |
v := 16r10000 + anInteger |
3459 | 3207 |
]. |
19349 | 3208 |
self unsignedInt16At:index put:v MSB:msb. |
3209 |
^ anInteger |
|
3459 | 3210 |
|
3211 |
" |
|
3212 |
|b| |
|
3213 |
b := ByteArray new:4. |
|
3214 |
b signedWordAt:1 put:-1. |
|
3215 |
b signedWordAt:3 put:-2. |
|
3216 |
b inspect |
|
3217 |
" |
|
3218 |
||
3219 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
3323 | 3220 |
! |
3221 |
||
19349 | 3222 |
unsignedInt16At:index |
3323 | 3223 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 3224 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 3225 |
The value is retrieved in the machine's natural byte order |
3226 |
Subclasses may redefine this for better performance." |
|
3227 |
||
3228 |
^ self unsignedInt16At:index MSB:IsBigEndian |
|
3323 | 3229 |
! |
3230 |
||
19349 | 3231 |
unsignedInt16At:index MSB:msb |
3323 | 3232 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 3233 |
The index is a smalltalk index (i.e. 1-based). |
19349 | 3234 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
3235 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
|
3236 |
Notice: |
|
3237 |
the index is a byte index; thus, this allows for unaligned access to |
|
3238 |
words on any boundary." |
|
3323 | 3239 |
|
13575 | 3240 |
|b1 "{ Class: SmallInteger }" |
3323 | 3241 |
b2 "{ Class: SmallInteger }"| |
3242 |
||
19046 | 3243 |
b1 := self byteAt:index. |
3244 |
b2 := self byteAt:(index + 1). |
|
3323 | 3245 |
msb ifTrue:[ |
19046 | 3246 |
^ (b1 bitShift:8) + b2 |
3323 | 3247 |
]. |
3248 |
^ (b2 bitShift:8) + b1 |
|
3249 |
! |
|
3250 |
||
19349 | 3251 |
unsignedInt16At:index put:anInteger |
3323 | 3252 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 3253 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 3254 |
The stored value must be in the range 0 .. 16rFFFF. |
3323 | 3255 |
The value is stored in the machines natural byteorder." |
3256 |
||
19349 | 3257 |
^ self unsignedInt16At:index put:anInteger MSB:IsBigEndian |
3323 | 3258 |
|
3259 |
" |
|
3260 |
|b| |
|
3261 |
b := ByteArray new:4. |
|
19349 | 3262 |
b unsignedInt16At:1 put:16r0102. |
3263 |
b unsignedInt16At:3 put:16r0304. |
|
13575 | 3264 |
b inspect |
3323 | 3265 |
" |
3266 |
||
3267 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
3268 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
3269 |
! |
|
3270 |
||
19349 | 3271 |
unsignedInt16At:index put:anInteger MSB:msb |
3323 | 3272 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 3273 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 3274 |
The stored value must be in the range 0 .. 16rFFFF. |
3323 | 3275 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
3276 |
lower index) if msb is false, MSB-first otherwise" |
|
3277 |
||
3278 |
|b1 b2 |
|
3279 |
iVal "{ Class: SmallInteger }"| |
|
3280 |
||
19349 | 3281 |
iVal := anInteger. |
3323 | 3282 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
19046 | 3283 |
^ self elementBoundsError:iVal |
3323 | 3284 |
]. |
3285 |
msb ifTrue:[ |
|
19046 | 3286 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
3287 |
b2 := (iVal bitAnd:16rFF). |
|
3323 | 3288 |
] ifFalse:[ |
19046 | 3289 |
b1 := (iVal bitAnd:16rFF). |
3290 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
|
3323 | 3291 |
]. |
19046 | 3292 |
self byteAt:index put:b1. |
3293 |
self byteAt:index+1 put:b2. |
|
19349 | 3294 |
^ anInteger |
3323 | 3295 |
|
3296 |
" |
|
3297 |
|b| |
|
3298 |
b := ByteArray new:8. |
|
3299 |
b unsignedShortAt:1 put:16r0102 bigEndian:false. |
|
3300 |
b unsignedShortAt:3 put:16r0304 bigEndian:false. |
|
3301 |
b unsignedShortAt:5 put:16r0102 bigEndian:true. |
|
3302 |
b unsignedShortAt:7 put:16r0304 bigEndian:true. |
|
13575 | 3303 |
b inspect |
3323 | 3304 |
" |
3305 |
||
3306 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
3307 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
3459 | 3308 |
! ! |
3309 |
||
3310 |
!UninterpretedBytes methodsFor:'accessing-strings'! |
|
3311 |
||
3312 |
stringAt:index |
|
3313 |
"return a string starting at index up to the 0-byte. |
|
3314 |
The index is a smalltalk index (i.e. 1-based)." |
|
3315 |
||
3316 |
|stream i "{ Class: SmallInteger }" c| |
|
3317 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3318 |
stream := WriteStream on:(String new:40). |
3459 | 3319 |
i := index. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3320 |
[(c := self byteAt:i) ~~ 0] whileTrue:[ |
13575 | 3321 |
stream nextPut:(Character value:c). |
3322 |
i := i + 1. |
|
3459 | 3323 |
]. |
3324 |
^ stream contents |
|
3325 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3326 |
" |
13575 | 3327 |
#[71 72 73 74 75 76 77 0] stringAt:1 |
3328 |
#[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
|
3329 |
'1234567890' stringAt:2 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3330 |
" |
3459 | 3331 |
! |
3332 |
||
3333 |
stringAt:index put:aString |
|
19196 | 3334 |
"copy aString to the receiver, starting at index up to |
7815 | 3335 |
(and including) the 0-byte (which is always written). |
3459 | 3336 |
The index is a smalltalk index (i.e. 1-based)." |
3337 |
||
3338 |
|i "{ Class: SmallInteger }"| |
|
3339 |
||
3340 |
i := index. |
|
3341 |
aString do:[:aChar | |
|
19196 | 3342 |
self byteAt:i put:aChar codePoint. |
3343 |
i := i + 1. |
|
3459 | 3344 |
]. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3345 |
self byteAt:i put:0. |
3459 | 3346 |
^ aString |
3347 |
||
3348 |
" |
|
3349 |
|bytes| |
|
3350 |
||
3351 |
bytes := ExternalBytes new:10. |
|
3352 |
bytes stringAt:1 put:'hello'. |
|
3353 |
1 to:bytes size do:[:i | |
|
19196 | 3354 |
Transcript showCR:(bytes at:i) |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3355 |
]. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3356 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3357 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3358 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3359 |
(String new:20) stringAt:1 put:'hello'; stringAt:6 put:' world'; yourself |
3459 | 3360 |
" |
3361 |
||
3362 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
|
3363 |
! |
|
3364 |
||
7812 | 3365 |
stringAt:index put:aString size:maxSize |
19196 | 3366 |
"copy aString to the receiver, starting at index up to either maxSize characters, |
7812 | 3367 |
or (and including) the 0-byte, whichever is encountered first. |
7815 | 3368 |
The final 0-byte is only written, if the string is shorter than maxSize. |
7812 | 3369 |
The index is a smalltalk index (i.e. 1-based)." |
3370 |
||
3371 |
|remaining "{ Class: SmallInteger }" |
|
3372 |
i "{ Class: SmallInteger }"| |
|
3373 |
||
3374 |
remaining := maxSize. |
|
7816 | 3375 |
remaining <= 0 ifTrue:[^ aString]. |
7812 | 3376 |
|
3377 |
i := index. |
|
3378 |
aString do:[:aChar | |
|
19196 | 3379 |
self byteAt:i put:aChar codePoint. |
3380 |
i := i + 1. |
|
3381 |
remaining := remaining - 1. |
|
3382 |
remaining <= 0 ifTrue:[^ aString]. |
|
7812 | 3383 |
]. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3384 |
self byteAt:i put:0. |
7812 | 3385 |
^ aString |
3386 |
||
3387 |
" |
|
3388 |
|bytes| |
|
3389 |
||
3390 |
bytes := ExternalBytes new:10. |
|
3391 |
bytes stringAt:1 put:'hello' size:3. |
|
3392 |
1 to:bytes size do:[:i | |
|
19196 | 3393 |
Transcript showCR:(bytes at:i) |
7812 | 3394 |
] |
3395 |
" |
|
3396 |
" |
|
3397 |
|bytes| |
|
3398 |
||
3399 |
bytes := ByteArray new:10 withAll:16rFF. |
|
3400 |
bytes stringAt:1 put:'he' size:3. |
|
3401 |
1 to:bytes size do:[:i | |
|
19196 | 3402 |
Transcript showCR:(bytes at:i) |
7812 | 3403 |
] |
3404 |
" |
|
3405 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3406 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3407 |
(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
|
3408 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3409 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3410 |
|
7812 | 3411 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
3412 |
! |
|
3413 |
||
3459 | 3414 |
stringAt:index size:maxSize |
3415 |
"return a string starting at index up to maxSize, or a 0-byte. |
|
3416 |
The index is a smalltalk index (i.e. 1-based)." |
|
3417 |
||
13575 | 3418 |
|stream c |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3419 |
max "{ Class: SmallInteger }" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3420 |
start "{ Class: SmallInteger }"| |
3459 | 3421 |
|
3422 |
stream := WriteStream on:(String new:maxSize). |
|
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3423 |
start := index. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3424 |
max := start + maxSize - 1. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3425 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3426 |
start to:max do:[:eachIndex| |
13575 | 3427 |
c := self byteAt:eachIndex. |
3428 |
c == 0 ifTrue:[ |
|
3429 |
^ stream contents |
|
3430 |
]. |
|
3431 |
stream nextPut:(Character value:c). |
|
3459 | 3432 |
]. |
3433 |
^ stream contents |
|
3434 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3435 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3436 |
#[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
|
3437 |
#[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
|
3438 |
'1234567890' stringAt:2 size:6 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
3439 |
" |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3440 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3441 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3442 |
zeroByteStringAt:index maximumSize:count |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3443 |
"extract a zeroByte-delimited string, given initial index and |
3433 | 3444 |
maximum number of characters (bytes). |
3445 |
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
|
3446 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3447 |
|bytes idx| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3448 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3449 |
bytes := self copyFrom:index to:(index + count - 1). |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3450 |
idx := bytes indexOf:0. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3451 |
idx ~~ 0 ifTrue:[ bytes := bytes copyTo:idx-1 ]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3452 |
^ bytes asString |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3453 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3454 |
"Created: 9.9.1996 / 15:28:34 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3455 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
3456 |
|
12951 | 3457 |
!UninterpretedBytes methodsFor:'converting'! |
3458 |
||
3459 |
asExternalBytes |
|
3460 |
|sz bytes| |
|
3461 |
||
14142 | 3462 |
sz := self byteSize. |
12951 | 3463 |
bytes := ExternalBytes unprotectedNew:sz. |
3464 |
bytes replaceBytesFrom:1 to:sz with:self startingAt:1. |
|
3465 |
^ bytes |
|
3466 |
||
3467 |
" |
|
3468 |
#[1 2 3 4 5 6 7] asExternalBytes |
|
3469 |
'Hello World' asExternalBytes |
|
14142 | 3470 |
'Hello World' asUnicodeString asExternalBytes |
12951 | 3471 |
" |
14132 | 3472 |
! |
3473 |
||
14155 | 3474 |
asExternalBytesUnprotected |
3475 |
"Like asExternalBytes, but does not register the bytes so |
|
15836 | 3476 |
bytes are GARBAGE-COLLECTED." |
14155 | 3477 |
|
3478 |
|bytes sz| |
|
3479 |
||
3480 |
sz := self byteSize. |
|
15836 | 3481 |
bytes := ExternalBytes unprotectedNew:sz. |
14155 | 3482 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
3483 |
^ bytes |
|
3484 |
||
3485 |
" |
|
3486 |
|x| |
|
3487 |
x := 'fooBar' asExternalBytesUnprotected. |
|
3488 |
ObjectMemory garbageCollect |
|
3489 |
" |
|
3490 |
||
3491 |
"Created: / 05-06-2012 / 14:11:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15836 | 3492 |
"Modified: / 30-11-2013 / 11:42:21 / cg" |
14155 | 3493 |
! |
3494 |
||
18600 | 3495 |
asSingleByteString |
3496 |
"return the receiver converted to a 'normal' string. |
|
3497 |
Raises an error if unrepresentable characters are encountered. |
|
3498 |
See also: asSingleByteStringIfPossible and asSingleByteStringReplaceInvalidWith:" |
|
3499 |
||
3500 |
^ String fromString:self |
|
3501 |
||
3502 |
" |
|
3503 |
#[60 61 62 63] asSingleByteString |
|
18616 | 3504 |
#[60 61 62 63] asExternalBytes asSingleByteString |
18969 | 3505 |
#[67 68 69 70] asIntegerArray asSingleByteString |
18600 | 3506 |
(Unicode16String with:(Character value:16rFF)) asSingleByteString |
3507 |
(Unicode16String with:(Character value:16rFFFF)) asSingleByteString |
|
3508 |
" |
|
3509 |
! |
|
3510 |
||
18969 | 3511 |
asSingleByteStringIfPossible |
3512 |
"if possible, return the receiver converted to a 'normal' string. |
|
3513 |
It is only possible, if there are no characters with codePoints above 255 in the receiver. |
|
3514 |
If not possible, the (wideString) receiver is returned." |
|
3515 |
||
3516 |
self containsNon8BitElements ifTrue:[^ self asString]. |
|
3517 |
^ self asSingleByteString. |
|
3518 |
||
3519 |
" |
|
3520 |
#[67 68 69 70] asSingleByteStringIfPossible |
|
3521 |
#[67 68 69 70] asIntegerArray asSingleByteStringIfPossible |
|
3522 |
'hello' asUnicodeString asSingleByteStringIfPossible |
|
3523 |
" |
|
3524 |
! |
|
3525 |
||
18616 | 3526 |
asString |
3527 |
"speed up string conversions" |
|
3528 |
||
3529 |
|size cls| |
|
3530 |
||
3531 |
cls := self class. |
|
3532 |
||
3533 |
(cls == ByteArray or:[cls == ImmutableByteArray or:[cls == ExternalBytes]]) ifTrue:[ |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3534 |
size := self size. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3535 |
^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1. |
18616 | 3536 |
]. |
3537 |
^ super asString. |
|
3538 |
||
3539 |
" |
|
3540 |
#[16r41 16r42 16r43] asString |
|
3541 |
#[16r41 16r42 16r43] asExternalBytes asString |
|
3542 |
" |
|
3543 |
! |
|
3544 |
||
14132 | 3545 |
asUUID |
3546 |
^ UUID fromBytes:self |
|
12951 | 3547 |
! ! |
3548 |
||
18616 | 3549 |
!UninterpretedBytes methodsFor:'encoding & decoding'! |
3550 |
||
3551 |
utf8Decoded |
|
3552 |
"Interpreting myself as an UTF-8 representation, decode and return the decoded string." |
|
3553 |
||
3554 |
^ CharacterArray decodeFromUTF8:self. |
|
3555 |
||
3556 |
" |
|
3557 |
#[16rC8 16rA0] utf8Decoded |
|
3558 |
#[16rC8 16rA0] asString utf8Decoded |
|
3559 |
#[16rC8 16rA0] asExternalBytes utf8Decoded |
|
3560 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
3561 |
||
3562 |
(Character value:16r800) utf8Encoded |
|
3563 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
3564 |
" |
|
3565 |
||
3566 |
"test: |
|
3567 |
||
3568 |
|utf8Encoding original readBack| |
|
3569 |
||
3570 |
1 to:16rFFFF do:[:ascii | |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3571 |
original := (Character value:ascii) asString. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3572 |
utf8Encoding := original utf8Encoded. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3573 |
readBack := utf8Encoding utf8Decoded. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3574 |
readBack = original ifFalse:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3575 |
self halt |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3576 |
] |
18616 | 3577 |
] |
3578 |
" |
|
3579 |
! |
|
3580 |
||
3581 |
utf8DecodedWithTwoByteCharactersReplacedBy:replacementCharacter |
|
3582 |
"Interpreting myself as an UTF-8 representation, decode and return |
|
3583 |
the decoded string. Suppress all 2-byte (above 16rFF) characters, |
|
3584 |
and replace them with replacementCharacter" |
|
3585 |
||
3586 |
|in out c| |
|
3587 |
||
3588 |
self containsNon7BitAscii ifFalse:[ |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3589 |
^ self asSingleByteString |
18616 | 3590 |
]. |
3591 |
||
3592 |
out := WriteStream on:(String uninitializedNew:self size * 3 // 2). |
|
3593 |
in := self readStream. |
|
3594 |
[in atEnd] whileFalse:[ |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3595 |
c := Character utf8DecodeFrom:in. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3596 |
c codePoint > 16rFF ifTrue:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3597 |
c := replacementCharacter |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3598 |
]. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3599 |
out nextPut:c. |
18616 | 3600 |
]. |
3601 |
^ out contents |
|
3602 |
||
3603 |
" |
|
3604 |
(Character value:16r220) utf8Encoded |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3605 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
18616 | 3606 |
|
3607 |
(Character value:16r220) utf8Encoded asExternalBytes copyButLast |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3608 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
18616 | 3609 |
" |
3610 |
! ! |
|
3611 |
||
4782 | 3612 |
!UninterpretedBytes methodsFor:'filling & replacing'! |
3613 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3614 |
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
|
3615 |
"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
|
3616 |
like collection. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3617 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3618 |
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
|
3619 |
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
|
3620 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3621 |
%{ /* NOCONTEXT */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3622 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3623 |
int nIndex, repNIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3624 |
int startIndex, stopIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3625 |
REGISTER unsigned char *src; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3626 |
REGISTER int repStartIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3627 |
int repStopIndex, count; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3628 |
REGISTER unsigned char *dst; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3629 |
OBJ cls; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3630 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3631 |
#ifndef NO_PRIM_BYTEARR |
14082 | 3632 |
if ((__isBytes(aCollection) || __isExternalBytesLike(aCollection)) |
14142 | 3633 |
&& (__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
|
3634 |
&& __bothSmallInteger(start, stop) |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3635 |
&& __isSmallInteger(repStart)) { |
15004 | 3636 |
startIndex = __intVal(start) - 1; |
3637 |
if (startIndex >= 0) { |
|
3638 |
dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex; |
|
3639 |
nIndex = __byteArraySize(self); |
|
3640 |
||
3641 |
if ((cls = __qClass(self)) != @global(ByteArray)) { |
|
3642 |
int nInst; |
|
3643 |
||
3644 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
3645 |
dst += nInst; |
|
3646 |
nIndex -= nInst; |
|
3647 |
} |
|
3648 |
||
3649 |
stopIndex = __intVal(stop) - 1; |
|
3650 |
count = stopIndex - startIndex + 1; |
|
3651 |
if (count == 0) { |
|
3652 |
RETURN ( self ); |
|
3653 |
} |
|
3654 |
||
3655 |
if ((count > 0) && (stopIndex < nIndex)) { |
|
3656 |
repStartIndex = __intVal(repStart) - 1; |
|
3657 |
if (repStartIndex >= 0) { |
|
3658 |
if (__isExternalBytesLike(aCollection)) { |
|
3659 |
OBJ sz; |
|
3660 |
||
3661 |
src = __externalAddressVal(aCollection); |
|
3662 |
if (src == 0) goto fallBack; |
|
3663 |
||
3664 |
sz = __externalBytesSize(aCollection); |
|
3665 |
if (__isSmallInteger(sz)) { |
|
3666 |
repNIndex = __smallIntegerVal(sz); |
|
3667 |
} else { |
|
3668 |
repNIndex = repStopIndex+1; /* always enough */ |
|
3669 |
} |
|
3670 |
src = src + repStartIndex; |
|
3671 |
} else { |
|
3672 |
if (__isStringLike(aCollection)) { |
|
3673 |
repNIndex = __stringSize(aCollection); |
|
3674 |
} else { |
|
3675 |
repNIndex = __qSize(aCollection) - OHDR_SIZE; |
|
3676 |
} |
|
3677 |
src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex; |
|
3678 |
if ((cls = __qClass(aCollection)) != @global(ByteArray)) { |
|
3679 |
int nInst; |
|
3680 |
||
3681 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
3682 |
src += nInst; |
|
3683 |
repNIndex -= nInst; |
|
3684 |
} |
|
3685 |
} |
|
3686 |
repStopIndex = repStartIndex + (stopIndex - startIndex); |
|
3687 |
if (repStopIndex < repNIndex) { |
|
3688 |
if (aCollection == self) { |
|
3689 |
/* take care of overlapping copy */ |
|
3690 |
if (src < dst) { |
|
3691 |
/* must do a reverse copy */ |
|
3692 |
src += count; |
|
3693 |
dst += count; |
|
3694 |
while (count-- > 0) { |
|
3695 |
*--dst = *--src; |
|
3696 |
} |
|
3697 |
RETURN ( self ); |
|
3698 |
} |
|
3699 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3700 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3701 |
# ifdef bcopy4 |
15004 | 3702 |
if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) { |
3703 |
int nW; |
|
3704 |
||
3705 |
/* copy unaligned part */ |
|
3706 |
while (count && ((unsigned INT)src & 3)) { |
|
3707 |
*dst++ = *src++; |
|
3708 |
count--; |
|
3709 |
} |
|
3710 |
||
3711 |
if (count > 0) { |
|
3712 |
/* copy aligned part */ |
|
3713 |
nW = count >> 2; |
|
3714 |
bcopy4(src, dst, nW); |
|
3715 |
if ((count = count & 3) != 0) { |
|
3716 |
/* copy any remaining part */ |
|
3717 |
src += (nW<<2); |
|
3718 |
dst += (nW<<2); |
|
3719 |
while (count--) { |
|
3720 |
*dst++ = *src++; |
|
3721 |
} |
|
3722 |
} |
|
3723 |
} |
|
3724 |
RETURN ( self ); |
|
3725 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3726 |
# else |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3727 |
# if __POINTER_SIZE__ == 8 |
15004 | 3728 |
if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) { |
3729 |
/* copy unaligned part */ |
|
3730 |
while (count && ((unsigned INT)src & 7)) { |
|
3731 |
*dst++ = *src++; |
|
3732 |
count--; |
|
3733 |
} |
|
3734 |
||
3735 |
/* copy aligned part */ |
|
3736 |
while (count >= 8) { |
|
3737 |
((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0]; |
|
3738 |
dst += 8; |
|
3739 |
src += 8; |
|
3740 |
count -= 8; |
|
3741 |
} |
|
3742 |
while (count--) { |
|
3743 |
*dst++ = *src++; |
|
3744 |
} |
|
3745 |
RETURN ( self ); |
|
3746 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3747 |
# endif /* 64bit */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3748 |
# endif /* bcopy4 */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3749 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3750 |
# ifdef FAST_MEMCPY |
15004 | 3751 |
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
|
3752 |
# else |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3753 |
# ifdef __UNROLL_LOOPS__ |
15004 | 3754 |
while (count >= 8) { |
3755 |
dst[0] = src[0]; dst[1] = src[1]; |
|
3756 |
dst[2] = src[2]; dst[3] = src[3]; |
|
3757 |
dst[4] = src[4]; dst[5] = src[5]; |
|
3758 |
dst[6] = src[6]; dst[7] = src[7]; |
|
3759 |
dst += 8; src += 8; |
|
3760 |
count -= 8; |
|
3761 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3762 |
# endif /* __UNROLL_LOOPS__ */ |
15004 | 3763 |
while (count-- > 0) { |
3764 |
*dst++ = *src++; |
|
3765 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3766 |
# endif |
15004 | 3767 |
RETURN ( self ); |
3768 |
} |
|
3769 |
} |
|
3770 |
} |
|
3771 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3772 |
} |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3773 |
fallBack: ; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3774 |
#endif |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3775 |
%}. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3776 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3777 |
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
|
3778 |
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
|
3779 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3780 |
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
|
3781 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3782 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3783 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3784 |
copy |
3785 |
replaceFrom:1 to:8 |
|
3786 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3787 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3788 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3789 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3790 |
copy |
3791 |
replaceFrom:3 to:10 |
|
3792 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3793 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3794 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3795 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3796 |
copy |
3797 |
replaceFrom:3 to:4 |
|
3798 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3799 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3800 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3801 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3802 |
copy |
3803 |
replaceFrom:0 to:9 |
|
3804 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3805 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3806 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3807 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3808 |
copy |
3809 |
replaceFrom:1 to:10 |
|
3810 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3811 |
startingAt:0 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3812 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3813 |
! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3814 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3815 |
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
|
3816 |
"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
|
3817 |
byte-array-like. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3818 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3819 |
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
|
3820 |
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
|
3821 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3822 |
^ self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3823 |
replaceBytesFrom:startIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3824 |
to:(startIndex + replacementCollection size - repStartIndex) |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3825 |
with:replacementCollection |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3826 |
startingAt:repStartIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3827 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3828 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3829 |
args: startIndex : <integer> |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3830 |
replacementCollection : <collection of <bytes> > |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3831 |
repStartIndex : <integer> |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3832 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3833 |
returns: self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3834 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3835 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3836 |
"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
|
3837 |
"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
|
3838 |
! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3839 |
|
13902 | 3840 |
replaceBytesWith:replacementCollection |
3841 |
"replace elements from another collection, which must be byte-array-like. |
|
3842 |
Replace stops at whichever collection is smaller. |
|
3843 |
||
3844 |
Notice: This operation modifies the receiver, NOT a copy; |
|
3845 |
therefore the change may affect all others referencing the receiver." |
|
3846 |
||
3847 |
^ self |
|
15004 | 3848 |
replaceBytesFrom:1 |
3849 |
to:(replacementCollection size min:self size) |
|
3850 |
with:replacementCollection |
|
3851 |
startingAt:1 |
|
13902 | 3852 |
|
3853 |
" |
|
15004 | 3854 |
(ByteArray new:10) replaceBytesWith:'hello' |
3855 |
(ByteArray new:10) replaceBytesWith:'hello world bla bla bla' |
|
13902 | 3856 |
" |
3857 |
||
3858 |
"Created: / 09-01-2012 / 16:18:10 / cg" |
|
3859 |
! |
|
3860 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3861 |
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
|
3862 |
"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
|
3863 |
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
|
3864 |
Return the receiver. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3865 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3866 |
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
|
3867 |
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
|
3868 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
3869 |
self class isBytes ifTrue:[ |
15004 | 3870 |
((aCollection class == self class) |
3871 |
or:[aCollection isByteCollection]) ifTrue:[ |
|
3872 |
^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex |
|
3873 |
]. |
|
7252
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
3874 |
]. |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3875 |
^ 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
|
3876 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3877 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3878 |
args: startIndex : <integer> |
15004 | 3879 |
stopIndex : <integer> |
3880 |
replacementCollection : <collection of <bytes> > |
|
3881 |
repStartIndex : <integer> |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3882 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3883 |
returns: self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3884 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3885 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
3886 |
"Modified: / 08-05-2012 / 13:23:27 / cg" |
4782 | 3887 |
! ! |
3888 |
||
12757 | 3889 |
!UninterpretedBytes methodsFor:'hashing'! |
3890 |
||
3891 |
computeXorHashFrom:startIndex to:endIndex |
|
3892 |
"compute and answer the SmallInteger-Hash of the bytes |
|
3893 |
from startIndex to endIndex. |
|
3894 |
If endindex = 0 or endIndex > size, hash up the size. |
|
3895 |
||
3896 |
NOTE: startIndex and endIndex are only hints about what should be hashed. |
|
13575 | 3897 |
In fact, more bytes could be involved in hashing. |
3898 |
SO ARRAYS MUST BE EQUAL TO HASH TO THE SAME VALUE" |
|
12757 | 3899 |
|
3900 |
|w| |
|
3901 |
||
3902 |
%{ |
|
3903 |
if (__bothSmallInteger(startIndex, endIndex)) { |
|
13575 | 3904 |
unsigned char *cp; |
3905 |
INT sz; |
|
3906 |
||
3907 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3908 |
if (cp) { |
|
3909 |
INT sidx = ((unsigned INT)__smallIntegerVal(startIndex)) - 1; |
|
3910 |
INT eidx = ((unsigned INT)__smallIntegerVal(endIndex)) - 1; |
|
3911 |
unsigned char *ep; |
|
3912 |
unsigned INT hash = 0, hash2 = 0, carry; |
|
3913 |
int i; |
|
3914 |
||
3915 |
if (eidx < 0 || eidx >= sz) eidx = sz - 1; |
|
3916 |
if (sidx > eidx) sidx = eidx; |
|
3917 |
if (sidx < 0) { |
|
3918 |
RETURN(__mkSmallInteger(0)); |
|
3919 |
} |
|
3920 |
||
3921 |
ep = cp + eidx; |
|
3922 |
cp += sidx; |
|
12757 | 3923 |
|
3924 |
#if 0 |
|
13575 | 3925 |
/* |
3926 |
* On LSB-First (little endian) cpus, |
|
3927 |
* this code does not produce the same result |
|
3928 |
* if the same bytes are at different positions |
|
3929 |
*/ |
|
3930 |
||
3931 |
if ((INT)cp & (sizeof(INT)-1)) { |
|
3932 |
/* not aligned */ |
|
3933 |
||
3934 |
for (i=0; cp <= ep; cp++) { |
|
3935 |
hash2 = (hash2 << 8) | *cp; |
|
3936 |
if (++i == sizeof(INT)) { |
|
3937 |
hash ^= hash2; |
|
3938 |
i = hash2 = 0; |
|
3939 |
} |
|
3940 |
} |
|
3941 |
} else { |
|
3942 |
/* aligned */ |
|
3943 |
for (; cp+sizeof(INT) <= ep; cp += sizeof(INT)) { |
|
3944 |
hash ^= *(unsigned INT *)cp; |
|
3945 |
} |
|
3946 |
for (; cp <= ep; cp++) { |
|
3947 |
hash2 = (hash2 << 8) | *cp; |
|
3948 |
} |
|
3949 |
} |
|
12757 | 3950 |
#else |
13575 | 3951 |
for (i=0; cp <= ep-sizeof(INT); cp += sizeof(INT)) { |
3952 |
hash2 = cp[0]; |
|
3953 |
hash2 = (hash2 << 8) | cp[1]; |
|
3954 |
hash2 = (hash2 << 8) | cp[2]; |
|
3955 |
hash2 = (hash2 << 8) | cp[3]; |
|
12757 | 3956 |
#if __POINTER_SIZE__ == 8 |
13575 | 3957 |
hash2 = (hash2 << 8) | cp[4]; |
3958 |
hash2 = (hash2 << 8) | cp[5]; |
|
3959 |
hash2 = (hash2 << 8) | cp[6]; |
|
3960 |
hash2 = (hash2 << 8) | cp[7]; |
|
12757 | 3961 |
#endif |
13575 | 3962 |
/* |
3963 |
* multiply by large prime to scramble bits and |
|
3964 |
* to avoid a 0 result from |
|
3965 |
* #[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8. |
|
3966 |
*/ |
|
3967 |
hash ^= (hash * 31415821) ^ hash2; |
|
3968 |
} |
|
3969 |
for (hash2 = 0; cp <= ep; cp++) { |
|
3970 |
hash2 = (hash2 << 8) | *cp; |
|
3971 |
} |
|
12757 | 3972 |
#endif |
13575 | 3973 |
hash ^= (hash * 31415821) ^ hash2; |
3974 |
||
3975 |
/* |
|
3976 |
* fold the high bits not fitting into a SmallInteger |
|
3977 |
*/ |
|
3978 |
carry = hash & ~_MAX_INT; |
|
3979 |
if (carry) { |
|
3980 |
hash = (hash & _MAX_INT) ^ (carry >> 8); |
|
3981 |
} |
|
3982 |
||
3983 |
RETURN(__mkSmallInteger(hash)); |
|
3984 |
} |
|
12757 | 3985 |
} |
3986 |
%}. |
|
3987 |
||
3988 |
^ self primitiveFailed |
|
3989 |
||
3990 |
" |
|
3991 |
#[1 2 3 4] computeXorHashFrom:1 to:4. |
|
3992 |
#[1 2 3 4] computeXorHashFrom:1 to:32. |
|
3993 |
#[1 2 3 4] computeXorHashFrom:1 to:0. |
|
3994 |
#[1 2 3 4 5] computeXorHashFrom:1 to:4. |
|
3995 |
#[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8. |
|
3996 |
#[1 2 3 4 5 6 7 8] computeXorHashFrom:2 to:8. |
|
3997 |
#[2 3 4 5 6 7 8] computeXorHashFrom:1 to:7. |
|
3998 |
" |
|
3999 |
! ! |
|
4000 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4001 |
!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
|
4002 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4003 |
copyReverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4004 |
"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
|
4005 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4006 |
^ self copy reverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4007 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4008 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4009 |
#[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
|
4010 |
#[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
|
4011 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4012 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4013 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
4014 |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4015 |
!UninterpretedBytes methodsFor:'misc'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4016 |
|
13575 | 4017 |
swapLongAt:byteIndex |
3433 | 4018 |
"swap the byteOrder of a long. |
4019 |
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
|
4020 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4021 |
|t| |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4022 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4023 |
t := self byteAt:byteIndex. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4024 |
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
|
4025 |
self byteAt:(byteIndex + 3) put:t. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4026 |
t := self byteAt:(byteIndex + 1). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4027 |
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
|
4028 |
self byteAt:(byteIndex + 2) put:t |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4029 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4030 |
"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
|
4031 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
4032 |
|
18664 | 4033 |
!UninterpretedBytes methodsFor:'printing & storing'! |
4034 |
||
4035 |
hexPrintOn:aStream |
|
4036 |
"print as hex string, eg: 'FF0243'. |
|
4037 |
This string can be used in #fromHexString: to recreate the byteArray" |
|
4038 |
||
4039 |
self hexPrintOn:aStream withSeparator:nil |
|
4040 |
||
4041 |
" |
|
4042 |
#[1 2 3 4 10 17] hexPrintOn:Transcript |
|
4043 |
" |
|
4044 |
||
4045 |
" |
|
4046 |
|s| |
|
4047 |
s := String streamContents:[:s | #[1 2 3 4 10 17] hexPrintOn:s]. |
|
4048 |
ByteArray fromHexString:s |
|
4049 |
" |
|
4050 |
! |
|
4051 |
||
4052 |
hexPrintOn:aStream withSeparator:aSeparatorStringOrCharacterOrNil |
|
4053 |
"print as hex string with separators, eg: 'FF:02:43'" |
|
4054 |
||
4055 |
|first| |
|
4056 |
||
4057 |
first := true. |
|
4058 |
1 to:self size do:[:idx | |
|
18666 | 4059 |
aSeparatorStringOrCharacterOrNil notNil ifTrue:[ |
4060 |
first ifFalse:[ |
|
4061 |
aSeparatorStringOrCharacterOrNil printOn:aStream |
|
4062 |
] ifTrue:[ |
|
4063 |
first := false. |
|
4064 |
]. |
|
4065 |
]. |
|
4066 |
(self byteAt:idx) printOn:aStream base:16 size:2 fill:$0. |
|
18664 | 4067 |
]. |
4068 |
||
4069 |
" |
|
4070 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:$: |
|
4071 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:(Character space) |
|
4072 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:'-' |
|
4073 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:nil |
|
4074 |
" |
|
4075 |
! |
|
4076 |
||
4077 |
hexPrintString |
|
4078 |
"print as hex string, eg: 'FF0243'. |
|
4079 |
This string can be used in #fromHexString: to recreate the byteArray" |
|
4080 |
||
4081 |
^ self hexPrintStringWithSeparator:nil |
|
4082 |
||
4083 |
" |
|
4084 |
#[1 2 3 4 10 17] hexPrintString |
|
4085 |
ByteArray fromHexString:#[1 2 3 4 10 17] hexPrintString |
|
4086 |
" |
|
4087 |
||
4088 |
"Modified: / 03-07-2010 / 01:59:19 / cg" |
|
4089 |
! |
|
4090 |
||
4091 |
hexPrintStringWithSeparator:aSeparatorStringOrCharacterOrNil |
|
4092 |
"print as hex string, eg: 'FF:02:43'." |
|
4093 |
||
4094 |
^ String |
|
18666 | 4095 |
streamContents:[:s | |
4096 |
self hexPrintOn:s withSeparator:aSeparatorStringOrCharacterOrNil. |
|
4097 |
] |
|
18664 | 4098 |
|
4099 |
" |
|
4100 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:$: |
|
4101 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:Character space |
|
4102 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:' - ' |
|
4103 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:nil |
|
4104 |
" |
|
4105 |
! ! |
|
4106 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4107 |
!UninterpretedBytes methodsFor:'private'! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4108 |
|
18969 | 4109 |
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
|
4110 |
"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
|
4111 |
|
18969 | 4112 |
|srcIdx "{ Class:SmallInteger }" |
4113 |
start "{ Class:SmallInteger }" |
|
4114 |
stop "{ Class:SmallInteger }"| |
|
4115 |
||
4116 |
start := startArg. |
|
4117 |
stop := stopArg. |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4118 |
srcIdx := sourceIndex. |
18969 | 4119 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4120 |
start to:stop do:[:dstIdx | |
18969 | 4121 |
self at:dstIdx put:(sourceBytes at:srcIdx). |
4122 |
srcIdx := srcIdx + 1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4123 |
]. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4124 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
4125 |
|
3323 | 4126 |
!UninterpretedBytes methodsFor:'queries'! |
4127 |
||
18616 | 4128 |
containsNon7BitAscii |
18969 | 4129 |
"return true, if the underlying collection contains elements longer than 7 bits |
18616 | 4130 |
(i.e. if it is non-ascii)" |
4131 |
||
4132 |
|sz "{ Class:SmallInteger }"| |
|
4133 |
||
4134 |
sz := self size. |
|
4135 |
1 to:sz do:[:idx| |
|
18969 | 4136 |
(self at:idx) > 16r7F ifTrue:[ |
4137 |
^ true. |
|
4138 |
]. |
|
4139 |
]. |
|
4140 |
^ false. |
|
4141 |
! |
|
4142 |
||
4143 |
containsNon8BitElements |
|
4144 |
"return true, if the underlying structure contains elements larger than a single byte" |
|
4145 |
||
4146 |
|sz "{ Class:SmallInteger }"| |
|
4147 |
||
4148 |
sz := self size. |
|
4149 |
1 to:sz do:[:idx| |
|
4150 |
(self at:idx) > 16rFF ifTrue:[ |
|
4151 |
^ true. |
|
4152 |
]. |
|
18616 | 4153 |
]. |
4154 |
^ false. |
|
4155 |
! |
|
4156 |
||
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4157 |
defaultElement |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4158 |
^ 0 |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4159 |
! |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
4160 |
|
18616 | 4161 |
referencesAny:aCollection |
4162 |
"redefined to speed up searching when many of my instances are present" |
|
4163 |
||
4164 |
%{ /* NOCONTEXT */ |
|
4165 |
if (__mkSmallInteger(0) == __ClassInstPtr(__qClass(self))->c_ninstvars) { |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
4166 |
/* I am only bytes */ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
4167 |
RETURN(false) |
18616 | 4168 |
} |
4169 |
%}. |
|
4170 |
^ super referencesAny:aCollection |
|
4171 |
||
4172 |
" |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
4173 |
'abc' referencesAny:#() |
18616 | 4174 |
" |
4175 |
! |
|
4176 |
||
3323 | 4177 |
sizeInBytes |
4178 |
"return the number of 8-bit bytes in the receiver. |
|
4179 |
This is needed since subclasse may redefine #size (TwoByteString)" |
|
4180 |
||
4181 |
^ super size |
|
4182 |
||
4183 |
"Created: / 5.3.1998 / 10:41:13 / stefan" |
|
4184 |
! ! |
|
4185 |
||
8986 | 4186 |
!UninterpretedBytes methodsFor:'testing'! |
4187 |
||
4188 |
isByteCollection |
|
4189 |
"return true, if the receiver has access methods for bytes; |
|
4190 |
true is returned here - the method is redefined from Object." |
|
4191 |
||
4192 |
^ true |
|
9005 | 4193 |
! |
4194 |
||
4195 |
isNonByteCollection |
|
4196 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
4197 |
false is returned here - the method is redefined from Collection." |
|
4198 |
||
4199 |
^ false |
|
8986 | 4200 |
! ! |
4201 |
||
11009
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4202 |
!UninterpretedBytes methodsFor:'visiting'! |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4203 |
|
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4204 |
acceptVisitor:aVisitor with:aParameter |
16719 | 4205 |
"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
|
4206 |
|
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4207 |
^ aVisitor visitByteArray:self with:aParameter |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4208 |
! ! |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
4209 |
|
695 | 4210 |
!UninterpretedBytes class methodsFor:'documentation'! |
4211 |
||
4212 |
version |
|
18600 | 4213 |
^ '$Header$' |
12253
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
4214 |
! |
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
4215 |
|
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
4216 |
version_CVS |
18600 | 4217 |
^ '$Header$' |
695 | 4218 |
! ! |
15087 | 4219 |
|
18284 | 4220 |
|
4221 |
UninterpretedBytes initialize! |