author | Claus Gittinger <cg@exept.de> |
Fri, 11 Mar 2016 17:16:10 +0100 | |
changeset 19345 | e2526c51d771 |
parent 19301 | 21b0b9bf3a74 |
child 19349 | d10a0648ff0f |
child 19353 | 2b04ee017e72 |
permissions | -rw-r--r-- |
19345 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
300 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
6492 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
18284 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
18 |
ArrayedCollection subclass:#UninterpretedBytes |
1266 | 19 |
instanceVariableNames:'' |
3323 | 20 |
classVariableNames:'IsBigEndian' |
1266 | 21 |
poolDictionaries:'' |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
22 |
category:'Collections-Abstract' |
1 | 23 |
! |
24 |
||
3433 | 25 |
!UninterpretedBytes primitiveDefinitions! |
26 |
%{ |
|
27 |
/* |
|
28 |
* Notice: I am abstract, and my subclasses may be anything. |
|
29 |
* Therefore, the code must always handle the fallback case |
|
30 |
* where the receiver is neither an ExternalBytes nor a ByteArray. |
|
31 |
* (which are, however, the most common) |
|
32 |
* |
|
33 |
* macro to fetch my byte address and size-in-bytes; |
|
34 |
* convenient for inline-C code. |
|
35 |
* (yes, C is bad ...) |
|
36 |
*/ |
|
37 |
#define __fetchBytePointerAndSize__(o, pPtr, pSize) \ |
|
38 |
{\ |
|
39 |
if (__isNonNilObject(o)) { \ |
|
13575 | 40 |
if (__isByteArrayLike(o)) { \ |
41 |
*(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \ |
|
42 |
*(pSize) = __byteArraySize(o); \ |
|
15004 | 43 |
} else if (__qIsExternalBytesLike(o)) { \ |
13575 | 44 |
OBJ __sz__ = __externalBytesSize(o); \ |
45 |
if (__isSmallInteger(__sz__)) { \ |
|
46 |
*(pSize) = __intVal(__sz__); \ |
|
47 |
*(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \ |
|
48 |
} else { \ |
|
15004 | 49 |
*(pSize) = 0; \ |
13575 | 50 |
*(pPtr) = (unsigned char *)0; \ |
51 |
} \ |
|
52 |
} else { \ |
|
53 |
*(pSize) /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(o))->c_ninstvars)); \ |
|
54 |
*(pPtr) = (char *)(__InstPtr(self)) + *(pSize) /* nInstBytes */; \ |
|
55 |
*(pSize) = __qSize(self) - *(pSize) /* nInstBytes */; \ |
|
56 |
} \ |
|
3433 | 57 |
} else { \ |
15004 | 58 |
*(pSize) = 0; \ |
13575 | 59 |
*(pPtr) = (unsigned char *)0; \ |
3433 | 60 |
} \ |
61 |
} |
|
62 |
||
63 |
%} |
|
64 |
! ! |
|
65 |
||
68 | 66 |
!UninterpretedBytes class methodsFor:'documentation'! |
1 | 67 |
|
88 | 68 |
copyright |
69 |
" |
|
70 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
300 | 71 |
All Rights Reserved |
88 | 72 |
|
73 |
This software is furnished under a license and may be used |
|
74 |
only in accordance with the terms of that license and with the |
|
75 |
inclusion of the above copyright notice. This software may not |
|
76 |
be provided or otherwise made available to, or used by, any |
|
77 |
other person. No title to or ownership of the software is |
|
78 |
hereby transferred. |
|
79 |
" |
|
80 |
! |
|
81 |
||
68 | 82 |
documentation |
83 |
" |
|
13575 | 84 |
UninterpretedBytes provides the common protocol for byte-storage |
85 |
containers; concrete subclasses are |
|
19101 | 86 |
ByteArray (which store the bytes within the Smalltalk object memory) |
87 |
String (knows that the bytes represent characters) |
|
13575 | 88 |
and |
19101 | 89 |
ExternalBytes (which store the bytes in the malloc-heap). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
90 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
91 |
UninterpretedBytes itself is abstract, so no instances of it can be created. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
92 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
93 |
[See also:] |
19101 | 94 |
ByteArray String ExternalBytes |
1294 | 95 |
|
96 |
[author:] |
|
19101 | 97 |
Claus Gittinger |
3433 | 98 |
|
99 |
[Notice:] |
|
19101 | 100 |
Notice the confusion due to multiple methods with the same |
101 |
functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:'). |
|
102 |
The reason is that at the time this class was written, |
|
103 |
ST80 did not offer protocol to specify the byteOrder, and |
|
104 |
ST/X provided methods ending in 'MSB:' for this. |
|
105 |
In the meanwhile, VW added protocol ending in 'bigEndian:', |
|
106 |
which has been added here for compatibility. |
|
107 |
(certainly a point, where an ansi-standard will help) |
|
68 | 108 |
" |
109 |
! ! |
|
1 | 110 |
|
18284 | 111 |
!UninterpretedBytes class methodsFor:'initialization'! |
112 |
||
113 |
initialize |
|
114 |
IsBigEndian := self isBigEndian. |
|
115 |
! ! |
|
116 |
||
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
117 |
!UninterpretedBytes class methodsFor:'instance creation'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
118 |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
119 |
from:aByteArray |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
120 |
"return new instance which is a copy of aByteArray" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
121 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
122 |
|len bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
123 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
124 |
len := aByteArray size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
125 |
bytes := self new:len. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
126 |
bytes replaceBytesFrom:1 to:len with:aByteArray startingAt:1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
127 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
128 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
129 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
130 |
String from:#[40 41 42] |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
131 |
String with:#[40 41 42 43 44 45 46 47 48 49 50] from:2 to:5 |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
132 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
133 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
134 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
135 |
fromHexString:aString |
15717 | 136 |
"decode a byteArray from a hex string (as generated by hexPrintOn:)" |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
137 |
|
12551 | 138 |
| sz bytes s hi lo | |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
139 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
140 |
sz := aString size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
141 |
sz == 0 ifTrue:[^ self new]. |
14970 | 142 |
sz odd ifTrue:[ ConversionError raiseWith:aString errorString:'invalid hex string (odd size)' ]. |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
143 |
|
12551 | 144 |
bytes := self new: sz // 2. |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
145 |
s := aString readStream. |
12551 | 146 |
1 to: sz // 2 do: [ :idx | |
18346 | 147 |
hi := s next digitValue. |
148 |
lo := s next digitValue. |
|
149 |
bytes at:idx put: ((hi bitShift:4) bitOr: lo) |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
150 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
151 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
152 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
153 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
154 |
ByteArray fromHexString:'1234FEFF' |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
155 |
ExternalBytes fromHexString:'1234FEFF' |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
156 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
157 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
158 |
|s| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
159 |
s := String streamContents:[:s | #[1 2 3] hexPrintOn:s]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
160 |
ByteArray fromHexString:s |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
161 |
" |
12551 | 162 |
" |
163 |
Time millisecondsToRun:[ |
|
18346 | 164 |
1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ] |
12551 | 165 |
]. |
166 |
" |
|
15717 | 167 |
|
168 |
"Modified (comment): / 28-08-2013 / 20:40:04 / cg" |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
169 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
170 |
|
11874
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
171 |
fromHexStringWithSeparators:aString |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
172 |
"read a bytearray from a printed string representation, where |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
173 |
individual bytes are encoded as two hex digits, optionally separated by whiteSpace. |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
174 |
See also fromHexString:, which does something similar, but does not allow for spaces" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
175 |
|
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
176 |
^ self streamContents:[:outStream | |
13575 | 177 |
|inStream h| |
178 |
||
179 |
inStream := aString readStream. |
|
180 |
||
181 |
[ |
|
182 |
inStream skipSeparators. |
|
183 |
inStream atEnd |
|
184 |
] whileFalse:[ |
|
185 |
h := inStream next:2. |
|
186 |
outStream nextPut:(Integer readFrom:h base:16). |
|
187 |
]. |
|
11874
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
188 |
]. |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
189 |
|
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
190 |
" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
191 |
ByteArray fromHexString:'1234FEFF' |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
192 |
ByteArray fromHexStringWithSeparators:' 12 34 FE FF' |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
193 |
" |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
194 |
! |
aebca3972774
+fromHexStringWithSeparators
Claus Gittinger <cg@exept.de>
parents:
11852
diff
changeset
|
195 |
|
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
196 |
fromPackedString:aString |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
197 |
"ST-80 compatibility: decode a byteArray from a packed string in which |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
198 |
6bits are encoded per character. The argument, aString must be a multiple |
18633 | 199 |
of 4 in size (since 24 is the lcm of 6 and 8). |
200 |
Every 6 bit packet is encoded as a character in 32..95. |
|
201 |
Characters below 32 are ignored (so line breaks can be inserted at any place). |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
202 |
An addition final byte defines how many bytes of the last triple are valid. |
18633 | 203 |
This is somewhat like the radix-encoding used in good old PDP11 times ;-) |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
204 |
ST-80 uses this encoding for Images ... |
16798 | 205 |
This is a base64 encoding, very similar (but not equal) to the algorithm used in RFC1421. |
18346 | 206 |
PS: It took a while to figure that one out ... |
18633 | 207 |
PPS: I don't like it ;-)" |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
208 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
209 |
|index "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
210 |
dstIndex "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
211 |
stop "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
212 |
sixBits "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
213 |
n "{ Class: SmallInteger }" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
214 |
sz "{ Class: SmallInteger }" |
12551 | 215 |
last bytes| |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
216 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
217 |
sz := aString size. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
218 |
sz == 0 ifTrue:[^ self new]. |
12551 | 219 |
sz := sz - (aString count:[:ch | ch codePoint < 32]). |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
220 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
221 |
stop := sz // 4 * 3. |
12551 | 222 |
"the size modulo 3 is encoded in the last character, if it is in the |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
223 |
range 97 .. otherwise, its exact." |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
224 |
|
12551 | 225 |
last := aString last codePoint. |
226 |
last > 96 ifTrue:[ |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
227 |
stop := stop - 3 + (last - 96) |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
228 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
229 |
bytes := self new:stop. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
230 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
231 |
index := 1. dstIndex := 1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
232 |
[dstIndex <= stop] whileTrue:[ |
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
233 |
"/ take 4 characters ... |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
234 |
"/ allow a line break before each group of 4 |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
235 |
sixBits := (aString at:index) codePoint. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
236 |
[sixBits < 32] whileTrue:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
237 |
index := index + 1. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
238 |
sixBits := (aString at:index) codePoint. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
239 |
]. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
240 |
sixBits := sixBits bitAnd:16r3F. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
241 |
n := sixBits. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
242 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
243 |
"/ self assert:(aString at:index+1) codePoint >= 32. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
244 |
sixBits := (aString at:index+1) codePoint bitAnd:16r3F. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
245 |
n := (n bitShift:6) + sixBits. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
246 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
247 |
"/ self assert:(aString at:index+2) codePoint >= 32. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
248 |
sixBits := (aString at:index+2) codePoint bitAnd:16r3F. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
249 |
n := (n bitShift:6) + sixBits. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
250 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
251 |
"/ self assert:(aString at:index+3) codePoint >= 32. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
252 |
sixBits := (aString at:index+3) codePoint bitAnd:16r3F. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
253 |
n := (n bitShift:6) + sixBits. |
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 |
index := index + 4. |
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 |
"/ now have 24 bits in n |
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 |
bytes at:dstIndex put:(n bitShift:-16). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
260 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
261 |
dstIndex < stop ifTrue:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
262 |
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
|
263 |
dstIndex+2 <= stop ifTrue:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
264 |
bytes at:dstIndex+2 put:(n bitAnd:16rFF). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
265 |
] |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
266 |
]. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
267 |
dstIndex := dstIndex + 3. |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
268 |
]. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
269 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
270 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
271 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
272 |
ByteArray fromPackedString:(#[1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
273 |
ByteArray fromPackedString:(#[1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
274 |
ByteArray fromPackedString:(#[1 1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
275 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1] asPackedString) |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
276 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1 1] asPackedString) |
18633 | 277 |
ByteArray fromPackedString:((ByteArray new:256) asPackedString) |
278 |
ByteArray fromPackedString:((ByteArray new:128) asPackedString) |
|
279 |
ByteArray fromPackedString:((ByteArray new:129) asPackedString) |
|
280 |
ByteArray fromPackedString:((ByteArray new:130) asPackedString) |
|
281 |
ByteArray fromPackedString:((ByteArray new:131) asPackedString) |
|
282 |
ByteArray fromPackedString:((ByteArray new:132) asPackedString) |
|
283 |
ByteArray fromPackedString:((ByteArray new:64) asPackedString) |
|
284 |
||
285 |
0 to:256 do:[:l | |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
286 |
|orig copy| |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
287 |
|
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
288 |
0 to:255 do:[:fill | |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
289 |
orig := ByteArray new:l withAll:fill. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
290 |
copy := ByteArray fromPackedString:(orig asPackedString). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
291 |
self assert:(orig = copy). |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
292 |
] |
18633 | 293 |
] |
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
294 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
295 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
296 |
"Modified: / 6.3.1997 / 15:28:52 / cg" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
297 |
"Modified: / 18.12.1997 / 17:17:11 / stefan" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
298 |
! |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
299 |
|
18284 | 300 |
uninitializedNew:anInteger |
301 |
"return a new instance of the receiver with uninitialized |
|
302 |
(i.e. undefined) contents. The indexed elements have any random |
|
303 |
value. However, any named instance variables are still nilled. |
|
304 |
For use, when contents will be set anyway shortly after - this |
|
305 |
is a bit faster than the regular basicNew:, which clears the bytes. |
|
306 |
Of course, it only makes a difference for very big ByteArrays, such |
|
307 |
as used for images/bitmaps. |
|
308 |
||
309 |
Notice: if you want to port code using uninitializedNew: to another |
|
310 |
smalltalk, you have to add an 'uninitializedNew: -> basicNew:'-calling |
|
311 |
method to the ByteArray class of the other smalltalk." |
|
312 |
||
313 |
%{ /* NOCONTEXT */ |
|
314 |
OBJ newobj; |
|
315 |
INT instsize, nInstVars, nindexedinstvars; |
|
316 |
REGISTER OBJ *op; |
|
317 |
||
318 |
if (__isSmallInteger(anInteger)) { |
|
18346 | 319 |
nindexedinstvars = __intVal(anInteger); |
320 |
if (nindexedinstvars >= 0) { |
|
321 |
if (self == ByteArray) { |
|
322 |
/* |
|
323 |
* the most common case |
|
324 |
*/ |
|
325 |
instsize = OHDR_SIZE + nindexedinstvars; |
|
326 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
327 |
__qCheckedNew(newobj, instsize); |
|
328 |
__InstPtr(newobj)->o_class = self; |
|
329 |
__qSTORE(newobj, self); |
|
330 |
RETURN (newobj ); |
|
331 |
} |
|
332 |
} else { |
|
333 |
/* |
|
334 |
* Take care for subclasses like TwoByteString |
|
335 |
*/ |
|
336 |
switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) { |
|
337 |
case BYTEARRAY: |
|
338 |
break; |
|
339 |
||
340 |
case WORDARRAY: |
|
341 |
case SWORDARRAY: |
|
342 |
nindexedinstvars *= 2; |
|
343 |
break; |
|
344 |
||
345 |
case LONGARRAY: |
|
346 |
case SLONGARRAY: |
|
347 |
nindexedinstvars *= 4; |
|
348 |
break; |
|
349 |
||
350 |
default: |
|
351 |
/* don't know about this array type, delegate to super */ |
|
352 |
goto out; |
|
353 |
} |
|
354 |
} |
|
355 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
|
356 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars; |
|
357 |
__PROTECT_CONTEXT__ |
|
358 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
359 |
__UNPROTECT_CONTEXT__ |
|
360 |
if (newobj != nil) { |
|
361 |
__InstPtr(newobj)->o_class = self; |
|
362 |
__qSTORE(newobj, self); |
|
363 |
if (nInstVars) { |
|
364 |
/* |
|
365 |
* still have to nil out named instvars ... |
|
366 |
*/ |
|
18284 | 367 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) |
18346 | 368 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
18284 | 369 |
#else |
370 |
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES) |
|
18346 | 371 |
/* |
372 |
* knowing that nil is 0 |
|
373 |
*/ |
|
374 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
18284 | 375 |
# else |
18346 | 376 |
op = __InstPtr(newobj)->i_instvars; |
377 |
while (nInstVars--) |
|
378 |
*op++ = nil; |
|
18284 | 379 |
# endif |
380 |
#endif |
|
18346 | 381 |
} |
382 |
RETURN ( newobj ); |
|
383 |
} |
|
384 |
} |
|
18284 | 385 |
} |
386 |
out:; |
|
387 |
%}. |
|
388 |
^ self basicNew:anInteger |
|
389 |
! |
|
390 |
||
8995
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
391 |
with:aByteArray from:start to:stop |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
392 |
"return new instance with a copy of aByteArray |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
393 |
beginning at index start up to and including index stop" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
394 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
395 |
|len bytes| |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
396 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
397 |
len := stop-start+1. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
398 |
bytes := self new:len. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
399 |
bytes replaceBytesFrom:1 to:len with:aByteArray startingAt:start. |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
400 |
^ bytes |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
401 |
|
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
402 |
" |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
403 |
String with:#[40 41 42 43 44 45 46 47 48 49 50] from:2 to:5 |
ab9905b339bb
Moved some methods from ByteArray -> UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
8986
diff
changeset
|
404 |
" |
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
405 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
406 |
|
1 | 407 |
!UninterpretedBytes class methodsFor:'queries'! |
408 |
||
8893 | 409 |
isAbstract |
11220 | 410 |
"Return if this class is an abstract class. |
411 |
True is returned for UninterpretedBytes here; false for subclasses. |
|
412 |
Abstract subclasses must redefine again." |
|
413 |
||
8893 | 414 |
^ self == UninterpretedBytes |
415 |
! |
|
416 |
||
1 | 417 |
isBigEndian |
77 | 418 |
"return true, if words/shorts store the most-significant |
13575 | 419 |
byte first (MSB), false if least-sign.-first (LSB). |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
420 |
I.e. false for vax, intel; true for m68k, sun. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
421 |
|
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
422 |
Notice: UninterpretedBytes isBigEndian |
4308 | 423 |
this is inlined both by stc and the jit compiler" |
1 | 424 |
|
425 |
%{ /* NOCONTEXT */ |
|
426 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
427 |
#if defined(__MSBFIRST__) |
3936 | 428 |
RETURN (true); |
429 |
#else |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
430 |
# if defined(__LSBFIRST__) |
4275 | 431 |
RETURN (false); |
432 |
# else |
|
1 | 433 |
/* |
434 |
* I dont like ifdefs - you always forget some ... |
|
3433 | 435 |
* therefore we look into a structure at run-time. |
436 |
* (also, there are CPUs around [mips], where the byteorder |
|
437 |
* is programmable, and which come in different flavours) |
|
438 |
* |
|
13575 | 439 |
* NOTICE: |
440 |
* both the JIT and stc may inline this to a |
|
3433 | 441 |
* constant for systems where this is known. |
1 | 442 |
*/ |
443 |
union { |
|
4308 | 444 |
unsigned int u_l; |
445 |
char u_c[sizeof(int)]; |
|
1 | 446 |
} u; |
447 |
||
448 |
u.u_l = 0x87654321; |
|
77 | 449 |
if (u.u_c[0] == 0x21) RETURN (false); |
450 |
RETURN (true); |
|
4275 | 451 |
# endif |
3936 | 452 |
#endif |
18346 | 453 |
%}. |
454 |
^ false "/ an arbitrary default |
|
455 |
||
3433 | 456 |
" |
457 |
UninterpretedBytes isBigEndian |
|
458 |
" |
|
3209 | 459 |
! |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
460 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
461 |
isBuiltInClass |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
462 |
"return true if this class is known by the run-time-system. |
3323 | 463 |
Here, true is returned, since UninterpretedBytes is the superclass of |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
464 |
some builtIn classes (ByteArray & ExternalBytes)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
465 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
466 |
^ self == UninterpretedBytes |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
467 |
|
3323 | 468 |
"Modified: / 23.4.1996 / 15:56:25 / cg" |
469 |
"Modified: / 5.3.1998 / 14:56:22 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
470 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
471 |
|
19345 | 472 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
473 |
!UninterpretedBytes methodsFor:'Compatibility-Squeak'! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
474 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
475 |
copyFromByteArray:aByteArray |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
476 |
"copy as much as possible from aByteArray" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
477 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
478 |
self replaceBytesFrom:1 to:(self size min:aByteArray size) with:aByteArray startingAt:1 |
15087 | 479 |
! |
480 |
||
481 |
signedLongAt:index |
|
482 |
"return the 4-bytes starting at index as a signed Integer. |
|
483 |
The index is a smalltalk index (i.e. 1-based). |
|
484 |
The value is retrieved in the machines natural byte order. |
|
485 |
This may be worth a primitive." |
|
486 |
||
487 |
^ self longAt:index |
|
488 |
||
489 |
" |
|
490 |
|b| |
|
491 |
b := ByteArray new:4. |
|
492 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
493 |
b signedLongAt:1 |
|
494 |
" |
|
495 |
||
496 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
497 |
! |
|
498 |
||
499 |
signedLongAt:index put:newValue |
|
500 |
"store a 4-bytes value starting at index. |
|
501 |
The index is a smalltalk index (i.e. 1-based). |
|
502 |
The value is in the machines natural byte order." |
|
503 |
||
504 |
^ self longAt:index put:newValue |
|
505 |
||
506 |
" |
|
507 |
|b| |
|
508 |
b := ByteArray new:4. |
|
509 |
b signedLongAt:1 put:-1. |
|
510 |
b unsignedLongAt:1 |
|
511 |
" |
|
512 |
||
513 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
514 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
515 |
|
9185 | 516 |
!UninterpretedBytes methodsFor:'Compatibility-V''Age'! |
517 |
||
518 |
uint32At:zeroBasedIndex |
|
519 |
"return the 4-bytes starting at index as (unsigned) Integer. |
|
520 |
The index is a C index (i.e. 0-based). |
|
19301 | 521 |
The value is retrieved in the machine's natural byte order. |
9185 | 522 |
Similar to unsignedLongAt:, except for the index base" |
523 |
||
524 |
^ self unsignedLongAt:zeroBasedIndex+1 |
|
525 |
||
526 |
" |
|
527 |
|b| |
|
528 |
||
529 |
b := ByteArray withAll:#(0 0 0 0). |
|
530 |
b uint32At:0 put:16r12345678. |
|
531 |
b uint32At:0. |
|
532 |
b |
|
533 |
" |
|
534 |
! |
|
535 |
||
536 |
uint32At:zeroBasedIndex put:anInteger |
|
537 |
"set the 4-bytes starting at index to the value given by (unsigned) Integer. |
|
538 |
The index is a C index (i.e. 0-based). |
|
539 |
The value is stored in the machines natural byte order. |
|
540 |
Similar to unsignedLongAt:put:, except for the index base" |
|
541 |
||
542 |
^ self unsignedLongAt:zeroBasedIndex+1 put:anInteger |
|
543 |
||
544 |
" |
|
545 |
|b| |
|
546 |
||
547 |
b := ByteArray withAll:#(0 0 0 0). |
|
548 |
b uint32At:0 put:16r12345678. |
|
549 |
b |
|
550 |
" |
|
551 |
! ! |
|
552 |
||
16796 | 553 |
!UninterpretedBytes methodsFor:'accessing-arbitrary-long ints'! |
554 |
||
19197 | 555 |
signedIntegerAt:index length:n bigEndian:bigEndian |
556 |
"return the n-byte signed integer starting at index. |
|
557 |
With n=1, this returns the single signed byte's value, |
|
558 |
n=2, a signed short, n=4 a signed int etc. |
|
559 |
Useful to extract arbitrary long integers" |
|
560 |
||
561 |
|val highByte| |
|
562 |
||
563 |
val := 0. |
|
564 |
bigEndian ifTrue:[ |
|
565 |
highByte := (self at:index). |
|
566 |
index to:index+n-1 do:[:i | |
|
567 |
val := (val<<8) + (self at:i) |
|
568 |
] |
|
569 |
] ifFalse:[ |
|
570 |
highByte := (self at:index+n-1). |
|
571 |
index+n-1 to:index by:-1 do:[:i | |
|
572 |
val := (val<<8) + (self at:i) |
|
573 |
] |
|
574 |
]. |
|
575 |
(highByte bitTest:16r80) ifTrue:[ |
|
576 |
^ val - (1 bitShift:(n*8)) |
|
577 |
]. |
|
578 |
^ val |
|
579 |
||
580 |
" |
|
581 |
|b| |
|
582 |
b := #[ 16r01 16rFF 16r00 16r04 16r05 ]. |
|
583 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> 255 (00FF) '. |
|
584 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> -256 (FF00) '. |
|
585 |
||
586 |
b := #[ 16r01 16r00 16rFF 16r04 16r05 ]. |
|
587 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> -256 (FF00) '. |
|
588 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> 255 (00FF) '. |
|
589 |
||
590 |
b := #[ 16r01 16r7F 16r00 16r04 16r05 ]. |
|
591 |
(b signedIntegerAt:2 length:2 bigEndian:false). ' -> 127 (007F) '. |
|
592 |
(b signedIntegerAt:2 length:2 bigEndian:true). ' -> 32512 (7F00) '. |
|
593 |
" |
|
594 |
||
595 |
" |
|
596 |
|b| |
|
597 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ]. |
|
598 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
599 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
600 |
||
601 |
b := #[ 16r01 16r82 16r03 16r04 16r05 ]. |
|
602 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
603 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
604 |
||
605 |
b := #[ 16r01 16r82 16r03 16r04 16r85 ]. |
|
606 |
(b signedIntegerAt:2 length:4 bigEndian:false). |
|
607 |
(b signedIntegerAt:2 length:4 bigEndian:true). |
|
608 |
" |
|
609 |
! |
|
610 |
||
16796 | 611 |
unsignedIntegerAt:index length:n bigEndian:bigEndian |
612 |
"return the n-byte unsigned integer starting at index. |
|
613 |
With n=1, this returns the single byte's value, |
|
614 |
n=2, an unsigned short, n=4 an unsigned int etc. |
|
615 |
Useful to extract arbitrary long integers" |
|
616 |
||
617 |
|val| |
|
618 |
||
619 |
val := 0. |
|
18346 | 620 |
bigEndian ifTrue:[ |
621 |
index to:index+n-1 do:[:i | |
|
622 |
val := (val<<8) + (self at:i) |
|
623 |
] |
|
624 |
] ifFalse:[ |
|
625 |
index+n-1 to:index by:-1 do:[:i | |
|
626 |
val := (val<<8) + (self at:i) |
|
627 |
] |
|
16796 | 628 |
]. |
629 |
^ val |
|
630 |
||
631 |
" |
|
632 |
|b| |
|
633 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ]. |
|
18346 | 634 |
(b unsignedIntegerAt:2 length:4 bigEndian:false). |
635 |
(b unsignedIntegerAt:2 length:4 bigEndian:true). |
|
16796 | 636 |
" |
19301 | 637 |
! |
638 |
||
639 |
unsignedIntegerAt:index put:newValue length:n bigEndian:bigEndian |
|
640 |
"store the n-byte unsigned integer starting at index. |
|
641 |
With n=1, this stores a single byte's value, |
|
642 |
n=2, an unsigned short, n=4 an unsigned int etc. |
|
643 |
Useful to replace arbitrary long integers" |
|
644 |
||
645 |
|val| |
|
646 |
||
647 |
val := newValue. |
|
648 |
bigEndian ifTrue:[ |
|
649 |
index to:index+n-1 do:[:i | |
|
650 |
self at:i put:(val bitAnd:16rFF). |
|
651 |
val := val bitShift:-8. |
|
652 |
] |
|
653 |
] ifFalse:[ |
|
654 |
index+n-1 to:index by:-1 do:[:i | |
|
655 |
self at:i put:(val bitAnd:16rFF). |
|
656 |
val := val bitShift:-8. |
|
657 |
] |
|
658 |
]. |
|
659 |
||
660 |
" |
|
661 |
|b| |
|
662 |
b := #[ 16r01 16r02 16r03 16r04 16r05 ] copy. |
|
663 |
(b unsignedIntegerAt:2 put:16r11223344 length:3 bigEndian:false). b. |
|
664 |
(b unsignedIntegerAt:2 put:16r11223344 length:3 bigEndian:true). b. |
|
665 |
" |
|
16796 | 666 |
! ! |
667 |
||
3459 | 668 |
!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
|
669 |
|
4422 | 670 |
bcdByteAt:index |
13724 | 671 |
"return the bcd-value for a byte at index in the range 0..99. |
672 |
BCD treats nibbles (4-bit) as an encoded decimal number's digits |
|
673 |
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)" |
|
4422 | 674 |
|
4425 | 675 |
^ (self byteAt:index) decodeFromBCD |
4422 | 676 |
|
677 |
" |
|
15004 | 678 |
#[ 16r55 ] bcdByteAt:1 |
679 |
#[ 16r99] bcdByteAt:1 |
|
13575 | 680 |
#[ 16rAA] bcdByteAt:1 |
4422 | 681 |
" |
13724 | 682 |
|
683 |
"Modified (comment): / 26-09-2011 / 11:57:33 / cg" |
|
4422 | 684 |
! |
685 |
||
686 |
bcdByteAt:index put:aNumber |
|
13724 | 687 |
"set the byte at index as bcd-value in the range 0..99. |
688 |
BCD treats nibbles (4-bit) as an encoded decimal number's digits |
|
689 |
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)" |
|
4422 | 690 |
|
691 |
(aNumber between:0 and:99) ifFalse:[ |
|
15004 | 692 |
self error:'invalid value for BCD encoding' |
4422 | 693 |
]. |
4425 | 694 |
^ self byteAt:index put:aNumber encodeAsBCD |
4422 | 695 |
|
696 |
" |
|
13575 | 697 |
(((ByteArray new:1) bcdByteAt:1 put:55; yourself) at:1) hexPrintString |
698 |
(((ByteArray new:1) bcdByteAt:1 put:99; yourself) at:1) hexPrintString |
|
699 |
(((ByteArray new:1) bcdByteAt:1 put:100; yourself) at:1) hexPrintString |
|
700 |
(((ByteArray new:1) bcdByteAt:1 put:-1; yourself) at:1) hexPrintString |
|
4422 | 701 |
" |
13724 | 702 |
|
703 |
"Modified (comment): / 26-09-2011 / 11:57:36 / cg" |
|
4422 | 704 |
! |
705 |
||
3459 | 706 |
signedByteAt:index |
13724 | 707 |
"return the byte at index as a signed 8 bit value in the range -128..+127. |
3459 | 708 |
The index is a smalltalk index (i.e. 1-based). |
709 |
This may be worth a primitive." |
|
710 |
||
711 |
^ (self at:index) signExtendedByteValue |
|
712 |
||
713 |
" |
|
714 |
|b| |
|
715 |
b := ByteArray new:2. |
|
716 |
b at:1 put:16rFF. |
|
717 |
b at:2 put:16r7F. |
|
13575 | 718 |
b signedByteAt:1 |
3459 | 719 |
" |
720 |
||
13724 | 721 |
"Modified: / 01-07-1996 / 21:13:53 / cg" |
722 |
"Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
|
3459 | 723 |
! |
724 |
||
725 |
signedByteAt:index put:aSignedByteValue |
|
13724 | 726 |
"return the byte at index as a signed 8 bit value in the range -128..+127. |
3459 | 727 |
The index is a smalltalk index (i.e. 1-based). |
728 |
Return the signedByteValue argument. |
|
729 |
This may be worth a primitive." |
|
730 |
||
731 |
|b "{ Class: SmallInteger }"| |
|
732 |
||
733 |
aSignedByteValue >= 0 ifTrue:[ |
|
15004 | 734 |
b := aSignedByteValue |
3459 | 735 |
] ifFalse:[ |
15004 | 736 |
b := 16r100 + aSignedByteValue |
3459 | 737 |
]. |
738 |
self at:index put:b. |
|
739 |
^ aSignedByteValue |
|
740 |
||
741 |
" |
|
742 |
|b| |
|
743 |
b := ByteArray new:2. |
|
744 |
b signedByteAt:1 put:-1. |
|
13575 | 745 |
b at:1 |
3459 | 746 |
" |
747 |
||
13724 | 748 |
"Modified: / 01-07-1996 / 21:12:37 / cg" |
749 |
"Modified (comment): / 26-09-2011 / 11:57:18 / cg" |
|
3459 | 750 |
! ! |
751 |
||
752 |
!UninterpretedBytes methodsFor:'accessing-floats & doubles'! |
|
753 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
754 |
doubleAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
755 |
"return the 8-bytes starting at index as a Float. |
3433 | 756 |
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
|
757 |
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
|
758 |
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
|
759 |
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
|
760 |
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
|
761 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
762 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
763 |
|
3433 | 764 |
%{ |
765 |
/* |
|
766 |
* handle the most common cases fast ... |
|
767 |
*/ |
|
768 |
if (__isSmallInteger(index)) { |
|
4308 | 769 |
unsigned char *cp; |
15004 | 770 |
INT sz; |
13575 | 771 |
|
3433 | 772 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
4308 | 773 |
if (cp) { |
3433 | 774 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
775 |
||
3434 | 776 |
if ((idx+(sizeof(double)-1)) < sz) { |
3433 | 777 |
cp += idx; |
778 |
/* |
|
779 |
* aligned |
|
780 |
*/ |
|
3434 | 781 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
3433 | 782 |
double dVal = ((double *)cp)[0]; |
3434 | 783 |
OBJ f; |
784 |
||
785 |
__qMKFLOAT(f, dVal); |
|
4308 | 786 |
RETURN (f); |
3433 | 787 |
} |
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
%}. |
|
792 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
793 |
newFloat := Float basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
794 |
1 to:8 do:[:destIndex| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
795 |
newFloat basicAt:destIndex put:(self at:index - 1 + destIndex) |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
796 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
797 |
^ newFloat. |
3433 | 798 |
|
799 |
" |
|
800 |
|b| |
|
801 |
||
802 |
b := ByteArray new:20. |
|
803 |
b doubleAt:1 put:(Float pi). |
|
804 |
Transcript showCR:b. |
|
805 |
Transcript showCR:(b doubleAt:1) |
|
806 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
807 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
808 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
809 |
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
|
810 |
"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
|
811 |
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
|
812 |
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
|
813 |
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
|
814 |
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
|
815 |
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
|
816 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
817 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
818 |
|
18284 | 819 |
msb == IsBigEndian ifTrue:[ |
18346 | 820 |
^ 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
|
821 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
822 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
823 |
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
|
824 |
1 to:8 do:[:destIndex| |
18346 | 825 |
newFloat basicAt:(9-destIndex) put:(self at:index - 1 + destIndex) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
826 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
827 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
828 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
829 |
"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
|
830 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
831 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
832 |
doubleAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
833 |
"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
|
834 |
starting at index. |
3433 | 835 |
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
|
836 |
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
|
837 |
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
|
838 |
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
|
839 |
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
|
840 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
841 |
|flt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
842 |
|
3433 | 843 |
%{ |
844 |
/* |
|
845 |
* handle the most common cases fast ... |
|
846 |
*/ |
|
16320 | 847 |
if (__isSmallInteger(index)) { |
18346 | 848 |
unsigned char *cp; |
849 |
INT sz; |
|
850 |
||
851 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
852 |
if (cp) { |
|
853 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
854 |
||
855 |
if ((idx+(sizeof(double)-1)) < sz) { |
|
856 |
cp += idx; |
|
857 |
/* |
|
858 |
* aligned |
|
859 |
*/ |
|
860 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
861 |
if (__isFloat(aFloat)) { |
|
862 |
((double *)cp)[0] = __floatVal(aFloat); |
|
863 |
RETURN (aFloat); |
|
864 |
} |
|
865 |
if (__isShortFloat(aFloat)) { |
|
866 |
((double *)cp)[0] = (double)(__shortFloatVal(aFloat)); |
|
867 |
RETURN (aFloat); |
|
868 |
} |
|
869 |
if (__isSmallInteger(aFloat)) { |
|
870 |
((double *)cp)[0] = (double)(__intVal(aFloat)); |
|
871 |
RETURN (aFloat); |
|
872 |
} |
|
873 |
} |
|
874 |
} |
|
875 |
} |
|
3433 | 876 |
} |
877 |
%}. |
|
878 |
||
16320 | 879 |
flt := aFloat asFloat. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
880 |
1 to:8 do:[:srcIndex| |
18346 | 881 |
self at:index - 1 + srcIndex put:(flt basicAt:srcIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
882 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
883 |
^ aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
884 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
885 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
886 |
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
|
887 |
"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
|
888 |
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
|
889 |
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
|
890 |
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
|
891 |
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
|
892 |
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
|
893 |
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
|
894 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
895 |
|flt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
896 |
|
18284 | 897 |
msb == IsBigEndian ifTrue:[ |
18346 | 898 |
^ 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
|
899 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
900 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
901 |
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
|
902 |
1 to:8 do:[:srcIndex| |
18346 | 903 |
self at:index - 1 + srcIndex put:(flt basicAt:(9-srcIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
904 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
905 |
^ aFloat |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
906 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
907 |
"Created: / 15.5.1998 / 17:22:27 / cg" |
3447 | 908 |
"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
|
909 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
910 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
911 |
floatAt:index |
3434 | 912 |
"return the 4-bytes starting at index as a ShortFloat. |
3433 | 913 |
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
|
914 |
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
|
915 |
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
|
916 |
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
|
917 |
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
|
918 |
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
|
919 |
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
|
920 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
921 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
922 |
|
3434 | 923 |
%{ |
924 |
/* |
|
925 |
* handle the most common cases fast ... |
|
926 |
*/ |
|
927 |
if (__isSmallInteger(index)) { |
|
4308 | 928 |
unsigned char *cp; |
15004 | 929 |
INT sz; |
3434 | 930 |
|
4308 | 931 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
932 |
if (cp) { |
|
933 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 934 |
|
4308 | 935 |
if ((idx+(sizeof(float)-1)) < sz) { |
936 |
cp += idx; |
|
937 |
/* |
|
938 |
* aligned |
|
939 |
*/ |
|
940 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
941 |
float fVal = ((float *)cp)[0]; |
|
3434 | 942 |
OBJ f; |
943 |
||
944 |
__qMKSFLOAT(f, fVal); |
|
4308 | 945 |
RETURN (f); |
946 |
} |
|
947 |
} |
|
948 |
} |
|
3434 | 949 |
} |
950 |
%}. |
|
951 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
952 |
newFloat := ShortFloat basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
953 |
1 to:4 do:[:destIndex| |
4308 | 954 |
newFloat basicAt:destIndex put:(self at:index - 1 + destIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
955 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
956 |
^ newFloat. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
957 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
958 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
959 |
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
|
960 |
"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
|
961 |
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
|
962 |
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
|
963 |
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
|
964 |
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
|
965 |
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
|
966 |
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
|
967 |
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
|
968 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
969 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
970 |
|
18284 | 971 |
msb == IsBigEndian ifTrue:[ |
18346 | 972 |
^ 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
|
973 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
974 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
975 |
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
|
976 |
1 to:4 do:[:destIndex| |
18346 | 977 |
newFloat basicAt:(5-destIndex) put:(self at:index - 1 + destIndex) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
978 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
979 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
980 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
981 |
"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
|
982 |
"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
|
983 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
984 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
985 |
floatAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
986 |
"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
|
987 |
starting at index. |
3433 | 988 |
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
|
989 |
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
|
990 |
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
|
991 |
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
|
992 |
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
|
993 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
994 |
|sflt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
995 |
|
3434 | 996 |
%{ |
997 |
/* |
|
998 |
* handle the most common cases fast ... |
|
999 |
*/ |
|
16320 | 1000 |
if (__isSmallInteger(index)) { |
18346 | 1001 |
unsigned char *cp; |
1002 |
INT sz; |
|
1003 |
||
1004 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1005 |
if (cp) { |
|
1006 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1007 |
||
1008 |
if ((idx+(sizeof(float)-1)) < sz) { |
|
1009 |
cp += idx; |
|
1010 |
/* |
|
1011 |
* aligned |
|
1012 |
*/ |
|
1013 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
1014 |
if (__isShortFloat(aFloat)) { |
|
1015 |
((float *)cp)[0] = __shortFloatVal(aFloat); |
|
1016 |
RETURN (self); |
|
1017 |
} |
|
1018 |
if (__isFloat(aFloat)) { |
|
1019 |
((float *)cp)[0] = (float)__floatVal(aFloat); |
|
1020 |
RETURN (self); |
|
1021 |
} |
|
1022 |
if (__isSmallInteger(aFloat)) { |
|
1023 |
((float *)cp)[0] = (float)__intVal(aFloat); |
|
1024 |
RETURN (self); |
|
1025 |
} |
|
1026 |
// bail out to smalltalk code |
|
1027 |
} |
|
1028 |
} |
|
1029 |
} |
|
3434 | 1030 |
} |
1031 |
%}. |
|
1032 |
||
16320 | 1033 |
sflt := aFloat asShortFloat. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1034 |
1 to:4 do:[:srcIndex| |
18346 | 1035 |
self at:index - 1 + srcIndex put:(sflt basicAt:srcIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1036 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1037 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1038 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1039 |
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
|
1040 |
"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
|
1041 |
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
|
1042 |
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
|
1043 |
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
|
1044 |
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
|
1045 |
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
|
1046 |
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
|
1047 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1048 |
|sflt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1049 |
|
18284 | 1050 |
msb == IsBigEndian ifTrue:[ |
18346 | 1051 |
self floatAt:index put:aFloat. |
1052 |
^ self. |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1053 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1054 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1055 |
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
|
1056 |
1 to:4 do:[:srcIndex| |
18346 | 1057 |
self at:index - 1 + srcIndex put:(sflt basicAt:(5-srcIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1058 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1059 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1060 |
"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
|
1061 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
1062 |
|
3323 | 1063 |
ieeeDoubleAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1064 |
"retrieve the 8 bytes starting at index as a float. |
3433 | 1065 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1066 |
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
|
1067 |
number format." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1068 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1069 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1070 |
currently, we assume that the machines native number format is already |
3323 | 1071 |
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
|
1072 |
to an IBM 370 or old VAX etc. |
3323 | 1073 |
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
|
1074 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1075 |
" |
9258 | 1076 |
Float isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 1077 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1078 |
^ self doubleAt:index |
3323 | 1079 |
|
1080 |
"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
|
1081 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1082 |
|
3323 | 1083 |
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
|
1084 |
"store the value of the argument, aFloat into the receiver |
3433 | 1085 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1086 |
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
|
1087 |
(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
|
1088 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1089 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1090 |
currently, we assume that the machines native number format is already |
3323 | 1091 |
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
|
1092 |
to an IBM 370 or old VAX etc. |
3323 | 1093 |
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
|
1094 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1095 |
" |
9258 | 1096 |
Float isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 1097 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1098 |
^ self doubleAt:index put:aFloat |
3323 | 1099 |
|
1100 |
"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
|
1101 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1102 |
|
3323 | 1103 |
ieeeFloatAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1104 |
"retrieve the 4 bytes starting at index as a float. |
3433 | 1105 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1106 |
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
|
1107 |
number format." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1108 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1109 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1110 |
currently, we assume that the machines native number format is already |
3323 | 1111 |
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
|
1112 |
to an IBM 370 or old VAX etc. |
3323 | 1113 |
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
|
1114 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1115 |
" |
9258 | 1116 |
ShortFloat isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 1117 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1118 |
^ self floatAt:index |
3323 | 1119 |
|
1120 |
"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
|
1121 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1122 |
|
3323 | 1123 |
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
|
1124 |
"store the value of the argument, aFloat into the receiver |
13575 | 1125 |
starting at index, which is a smalltalk index (i.e. 1-based). |
3433 | 1126 |
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
|
1127 |
(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
|
1128 |
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
|
1129 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1130 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1131 |
currently, we assume that the machines native number format is already |
3323 | 1132 |
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
|
1133 |
to an IBM 370 or old VAX etc. |
3323 | 1134 |
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
|
1135 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1136 |
" |
9258 | 1137 |
ShortFloat isIEEEFormat ifFalse:[self error:'unsupported operation']. |
3433 | 1138 |
|
16320 | 1139 |
self floatAt:index put:aFloat |
3323 | 1140 |
|
1141 |
"Created: / 5.3.1998 / 10:51:11 / stefan" |
|
3459 | 1142 |
! ! |
1143 |
||
13724 | 1144 |
!UninterpretedBytes methodsFor:'accessing-longlongs (64bit)'! |
3459 | 1145 |
|
1146 |
longLongAt:index |
|
1147 |
"return the 8-bytes starting at index as a signed Integer. |
|
1148 |
The index is a smalltalk index (i.e. 1-based). |
|
1149 |
The value is retrieved in the machines natural byte order. |
|
1150 |
This may be worth a primitive." |
|
1151 |
||
1152 |
|w| |
|
1153 |
||
18284 | 1154 |
w := self unsignedLongLongAt:index bigEndian:IsBigEndian. |
3459 | 1155 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
18346 | 1156 |
^ w - (16r10000000000000000) |
3459 | 1157 |
]. |
1158 |
^ w |
|
1159 |
||
1160 |
" |
|
1161 |
|b| |
|
1162 |
b := ByteArray new:4. |
|
1163 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
13575 | 1164 |
(b longLongAt:1) |
3459 | 1165 |
" |
1166 |
||
1167 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
1168 |
"Created: / 5.3.1998 / 14:40:05 / stefan" |
|
1169 |
"Modified: / 5.3.1998 / 14:58:32 / stefan" |
|
1170 |
! |
|
1171 |
||
1172 |
longLongAt:index bigEndian:msb |
|
1173 |
"return the 8-bytes starting at index as a signed Integer. |
|
1174 |
The index is a smalltalk index (i.e. 1-based). |
|
1175 |
The value is retrieved in the given byte order. |
|
1176 |
This may be worth a primitive." |
|
1177 |
||
1178 |
|w| |
|
1179 |
||
1180 |
w := self unsignedLongLongAt:index bigEndian:msb. |
|
1181 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
|
4308 | 1182 |
^ w - (16r10000000000000000) |
3459 | 1183 |
]. |
1184 |
^ w |
|
1185 |
||
1186 |
" |
|
1187 |
|b| |
|
1188 |
b := ByteArray new:4. |
|
1189 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
13575 | 1190 |
(b longLongAt:1 msb:true) |
3459 | 1191 |
" |
1192 |
||
1193 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
1194 |
"Created: / 5.3.1998 / 14:40:54 / stefan" |
|
1195 |
"Modified: / 9.5.1998 / 01:10:59 / cg" |
|
1196 |
! |
|
1197 |
||
1198 |
longLongAt:byteIndex put:anInteger |
|
1199 |
"store a signed longLong (64bit) integer. |
|
1200 |
The index is a smalltalk index (i.e. 1-based). |
|
1201 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
1202 |
||
7813 | 1203 |
|v| |
3459 | 1204 |
|
7813 | 1205 |
v := anInteger. |
1206 |
anInteger < 0 ifTrue:[ |
|
13575 | 1207 |
v := v + 16r10000000000000000 |
7813 | 1208 |
]. |
1209 |
^ self unsignedLongLongAt:byteIndex put:v |
|
3459 | 1210 |
! |
1211 |
||
1212 |
longLongAt:byteIndex put:anInteger bigEndian:msb |
|
1213 |
"store a signed longLong (64bit) integer. |
|
1214 |
The index is a smalltalk index (i.e. 1-based). |
|
1215 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
1216 |
||
1217 |
|v| |
|
1218 |
||
1219 |
v := anInteger. |
|
1220 |
anInteger < 0 ifTrue:[ |
|
4308 | 1221 |
v := v + 16r10000000000000000 |
3459 | 1222 |
]. |
1223 |
^ self unsignedLongLongAt:byteIndex put:v bigEndian:msb |
|
1224 |
||
1225 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
1226 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
1227 |
! |
|
1228 |
||
1229 |
quadWordAt:index MSB:msb |
|
1230 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
1231 |
The index is a smalltalk index (i.e. 1-based). |
|
1232 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
1233 |
||
13575 | 1234 |
|l |
3459 | 1235 |
bIdx "{ Class: SmallInteger }" |
1236 |
delta "{ Class: SmallInteger }"| |
|
1237 |
||
1238 |
l := LargeInteger basicNew numberOfDigits:8. |
|
1239 |
msb ifTrue:[ |
|
4308 | 1240 |
bIdx := index + 7. |
1241 |
delta := -1 |
|
3459 | 1242 |
] ifFalse:[ |
4308 | 1243 |
bIdx := index. |
1244 |
delta := 1 |
|
3459 | 1245 |
]. |
1246 |
1 to:8 do:[:i | |
|
4308 | 1247 |
l digitAt:i put:(self basicAt:bIdx). |
1248 |
bIdx := bIdx + delta |
|
3459 | 1249 |
]. |
1250 |
^ l compressed |
|
1251 |
||
1252 |
" |
|
1253 |
|b| |
|
1254 |
||
1255 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
13575 | 1256 |
(b quadWordAt:1 MSB:false) printStringRadix:16 |
3459 | 1257 |
" |
1258 |
||
1259 |
"Modified: 5.11.1996 / 14:06:21 / cg" |
|
1260 |
! |
|
1261 |
||
1262 |
quadWordAt:index put:anInteger MSB:msb |
|
1263 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1264 |
The index is a smalltalk index (i.e. 1-based). |
|
1265 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1266 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
1267 |
||
1268 |
|bIdx "{ Class: SmallInteger }" |
|
1269 |
delta "{ Class: SmallInteger }"| |
|
1270 |
||
1271 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[ |
|
13575 | 1272 |
^ self elementBoundsError:anInteger |
3459 | 1273 |
]. |
1274 |
||
1275 |
msb ifTrue:[ |
|
13575 | 1276 |
bIdx := index + 7. |
1277 |
delta := -1 |
|
3459 | 1278 |
] ifFalse:[ |
13575 | 1279 |
bIdx := index. |
1280 |
delta := 1 |
|
3459 | 1281 |
]. |
1282 |
1 to:8 do:[:i | |
|
13575 | 1283 |
self basicAt:bIdx put:(anInteger digitAt:i). |
1284 |
bIdx := bIdx + delta. |
|
3459 | 1285 |
]. |
1286 |
^ anInteger |
|
1287 |
||
1288 |
" |
|
1289 |
|b| |
|
1290 |
b := ByteArray new:8. |
|
1291 |
b quadWordAtIndex:1 put:16r0807060504030201 MSB:false. |
|
1292 |
b inspect |
|
1293 |
" |
|
1294 |
! |
|
1295 |
||
1296 |
unsignedLongLongAt:index bigEndian:msb |
|
1297 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
1298 |
The index is a smalltalk index (i.e. 1-based). |
|
1299 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
1300 |
||
13575 | 1301 |
|l |
3459 | 1302 |
bIdx "{ Class: SmallInteger }" |
1303 |
delta "{ Class: SmallInteger }"| |
|
1304 |
||
1305 |
l := LargeInteger basicNew numberOfDigits:8. |
|
1306 |
msb ifTrue:[ |
|
4308 | 1307 |
bIdx := index + 7. |
1308 |
delta := -1 |
|
3459 | 1309 |
] ifFalse:[ |
4308 | 1310 |
bIdx := index. |
1311 |
delta := 1 |
|
3459 | 1312 |
]. |
1313 |
1 to:8 do:[:i | |
|
4308 | 1314 |
l digitAt:i put:(self basicAt:bIdx). |
1315 |
bIdx := bIdx + delta |
|
3459 | 1316 |
]. |
1317 |
^ l compressed |
|
1318 |
||
1319 |
" |
|
1320 |
|b| |
|
1321 |
||
1322 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
13575 | 1323 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
3459 | 1324 |
" |
1325 |
||
1326 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
1327 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
1328 |
! |
|
1329 |
||
1330 |
unsignedLongLongAt:index put:anInteger |
|
1331 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1332 |
The index is a smalltalk index (i.e. 1-based). |
|
1333 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1334 |
The value is stored in natural byte order." |
|
1335 |
||
18284 | 1336 |
^ self unsignedLongLongAt:index put:anInteger bigEndian:IsBigEndian |
3459 | 1337 |
|
1338 |
"Created: / 5.3.1998 / 14:44:00 / stefan" |
|
1339 |
"Modified: / 5.3.1998 / 15:02:32 / stefan" |
|
1340 |
! |
|
1341 |
||
1342 |
unsignedLongLongAt:index put:anInteger bigEndian:msb |
|
1343 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
1344 |
The index is a smalltalk index (i.e. 1-based). |
|
1345 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
1346 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
1347 |
||
1348 |
|bIdx "{ Class: SmallInteger }" |
|
1349 |
delta "{ Class: SmallInteger }"| |
|
1350 |
||
1351 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[ |
|
13575 | 1352 |
^ self elementBoundsError:anInteger |
3459 | 1353 |
]. |
1354 |
||
1355 |
msb ifTrue:[ |
|
13575 | 1356 |
bIdx := index + 7. |
1357 |
delta := -1 |
|
3459 | 1358 |
] ifFalse:[ |
13575 | 1359 |
bIdx := index. |
1360 |
delta := 1 |
|
3459 | 1361 |
]. |
1362 |
1 to:8 do:[:i | |
|
13575 | 1363 |
self basicAt:bIdx put:(anInteger digitAt:i). |
1364 |
bIdx := bIdx + delta. |
|
3459 | 1365 |
]. |
1366 |
^ anInteger |
|
1367 |
||
1368 |
" |
|
1369 |
|b| |
|
1370 |
b := ByteArray new:8. |
|
1371 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
1372 |
b inspect |
|
1373 |
" |
|
1374 |
||
1375 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
1376 |
! ! |
|
1377 |
||
13724 | 1378 |
!UninterpretedBytes methodsFor:'accessing-longs (32bit)'! |
3459 | 1379 |
|
1380 |
doubleWordAt:index |
|
1381 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1382 |
The index is a smalltalk index (i.e. 1-based). |
|
4515 | 1383 |
The value is retrieved in the machines natural byte order." |
3459 | 1384 |
|
18284 | 1385 |
^ self doubleWordAt:index MSB:IsBigEndian |
3459 | 1386 |
|
1387 |
" |
|
1388 |
|b| |
|
1389 |
||
1390 |
b := ByteArray withAll:#(1 2 3 4). |
|
13575 | 1391 |
(b doubleWordAt:1) printStringRadix:16 |
3459 | 1392 |
" |
1393 |
||
1394 |
"Modified: / 5.3.1998 / 14:57:35 / stefan" |
|
1395 |
! |
|
1396 |
||
1397 |
doubleWordAt:index MSB:msb |
|
1398 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
1399 |
The index is a smalltalk index (i.e. 1-based). |
|
1400 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
4515 | 1401 |
LSB-first otherwise." |
3459 | 1402 |
|
13575 | 1403 |
|val |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1404 |
ival "{ Class: SmallInteger }" |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1405 |
t "{ Class: SmallInteger }" |
3459 | 1406 |
i "{ Class: SmallInteger }" |
1407 |
b1 "{ Class: SmallInteger }" |
|
1408 |
b2 "{ Class: SmallInteger }" |
|
1409 |
b3 "{ Class: SmallInteger }" |
|
1410 |
b4 "{ Class: SmallInteger }"| |
|
1411 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1412 |
%{ |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1413 |
/* |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1414 |
* handle the most common cases fast ... |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1415 |
*/ |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1416 |
if (__isSmallInteger(index)) { |
19047 | 1417 |
unsigned char *cp; |
1418 |
INT sz; |
|
1419 |
||
1420 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1421 |
if (cp) { |
|
1422 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1423 |
unsigned int iVal; |
|
1424 |
||
1425 |
if ((idx+(sizeof(int)-1)) < sz) { |
|
1426 |
cp += idx; |
|
1427 |
||
1428 |
if (msb == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1429 |
#if defined(__MSBFIRST__) |
19047 | 1430 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
1431 |
/* |
|
1432 |
* aligned |
|
1433 |
*/ |
|
1434 |
iVal = ((unsigned int *)cp)[0]; |
|
1435 |
} else |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1436 |
#endif |
19047 | 1437 |
{ |
1438 |
iVal = cp[0]; |
|
1439 |
iVal = (iVal << 8) | cp[1]; |
|
1440 |
iVal = (iVal << 8) | cp[2]; |
|
1441 |
iVal = (iVal << 8) | cp[3]; |
|
1442 |
} |
|
1443 |
} else { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1444 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
19047 | 1445 |
/* |
1446 |
* aligned or not - we dont care |
|
1447 |
* (i386 can fetch unaligned) |
|
1448 |
*/ |
|
1449 |
iVal = ((unsigned int *)cp)[0]; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1450 |
#else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1451 |
# if defined(__LSBFIRST__) |
19047 | 1452 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
1453 |
/* |
|
1454 |
* aligned |
|
1455 |
*/ |
|
1456 |
iVal = ((unsigned int *)cp)[0]; |
|
1457 |
} else |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1458 |
# endif |
19047 | 1459 |
{ |
1460 |
iVal = cp[3]; |
|
1461 |
iVal = (iVal << 8) | cp[2]; |
|
1462 |
iVal = (iVal << 8) | cp[1]; |
|
1463 |
iVal = (iVal << 8) | cp[0]; |
|
1464 |
} |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1465 |
#endif |
19047 | 1466 |
} |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1467 |
#if __POINTER_SIZE__ == 8 |
19047 | 1468 |
RETURN (__mkSmallInteger(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1469 |
#else |
19047 | 1470 |
RETURN (__MKUINT(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1471 |
#endif |
19047 | 1472 |
} |
1473 |
} |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1474 |
} |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1475 |
%}. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1476 |
|
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1477 |
"/ fallBack code - non ByteArray-like receiver |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1478 |
"/ or funny index |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1479 |
|
3459 | 1480 |
i := index. |
19047 | 1481 |
b1 := self byteAt:i. |
1482 |
b2 := self byteAt:(i+1). |
|
1483 |
b3 := self byteAt:(i+2). |
|
1484 |
b4 := self byteAt:(i+3). |
|
3459 | 1485 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1486 |
msb ifFalse:[ |
19047 | 1487 |
t := b4. b4 := b1. b1 := t. |
1488 |
t := b3. b3 := b2. b2 := t. |
|
3459 | 1489 |
]. |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1490 |
ival := b1. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1491 |
ival := (ival bitShift:8) + b2. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1492 |
ival := (ival bitShift:8) + b3. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1493 |
val := (ival bitShift:8) + b4. |
3459 | 1494 |
^ val |
1495 |
||
1496 |
" |
|
1497 |
|b| |
|
1498 |
||
1499 |
b := ByteArray withAll:#(1 2 3 4). |
|
13575 | 1500 |
(b doubleWordAt:1 MSB:true) printStringRadix:16. |
1501 |
(b doubleWordAt:1 MSB:false) printStringRadix:16 |
|
3459 | 1502 |
" |
1503 |
! |
|
1504 |
||
1505 |
doubleWordAt:index put:value |
|
1506 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1507 |
The index is a smalltalk index (i.e. 1-based). |
|
1508 |
The value should be in the range 0 to 16rFFFFFFFF |
|
1509 |
(for negative values, the stored value is not defined). |
|
4515 | 1510 |
The value is stored in the machines natural byte order." |
3459 | 1511 |
|
18284 | 1512 |
^ self doubleWordAt:index put:value MSB:IsBigEndian |
3459 | 1513 |
|
1514 |
" |
|
1515 |
|b| |
|
1516 |
b := ByteArray new:4. |
|
1517 |
b doubleWordAt:1 put:16r04030201. |
|
1518 |
b inspect |
|
1519 |
" |
|
1520 |
||
1521 |
"Modified: / 5.3.1998 / 14:57:48 / stefan" |
|
1522 |
! |
|
1523 |
||
1524 |
doubleWordAt:index put:aNumber MSB:msb |
|
1525 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1526 |
The index is a smalltalk index (i.e. 1-based). |
|
1527 |
The value must be in the range 0 to 16rFFFFFFFF. |
|
4515 | 1528 |
The value is stored MSB-first if msb is true; LSB-first otherwise." |
3459 | 1529 |
|
1530 |
|i "{ Class: SmallInteger }" | |
|
1531 |
||
1532 |
((aNumber < 0) or:[aNumber > 16rFFFFFFFF]) ifTrue:[ |
|
19047 | 1533 |
^ self elementBoundsError:aNumber |
3459 | 1534 |
]. |
1535 |
||
1536 |
i := index. |
|
1537 |
msb ifTrue:[ |
|
19047 | 1538 |
self byteAt:i put:(aNumber digitAt:4). |
1539 |
self byteAt:(i+1) put:(aNumber digitAt:3). |
|
1540 |
self byteAt:(i+2) put:(aNumber digitAt:2). |
|
1541 |
self byteAt:(i+3) put:(aNumber digitAt:1). |
|
3459 | 1542 |
] ifFalse:[ |
19047 | 1543 |
self byteAt:i put:(aNumber digitAt:1). |
1544 |
self byteAt:(i+1) put:(aNumber digitAt:2). |
|
1545 |
self byteAt:(i+2) put:(aNumber digitAt:3). |
|
1546 |
self byteAt:(i+3) put:(aNumber digitAt:4). |
|
3459 | 1547 |
]. |
1548 |
^ aNumber |
|
1549 |
||
1550 |
" |
|
1551 |
|b| |
|
1552 |
b := ByteArray new:8. |
|
1553 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
|
1554 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
1555 |
b inspect |
|
1556 |
" |
|
1557 |
||
1558 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
1559 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
|
1560 |
! |
|
1561 |
||
1562 |
doubleWordAtDoubleWordIndex:index |
|
13575 | 1563 |
"return the unsigned long at index, anInteger. |
3459 | 1564 |
Fetching in the machines natural byte order. |
1565 |
Indices are 1-based and scaled as appropriate to allow |
|
1566 |
accessing the memory as an array of doubleWord entries. |
|
1567 |
(i.e. indices are 1, 2, ...)" |
|
1568 |
||
18284 | 1569 |
^ self doubleWordAtDoubleWordIndex:index MSB:IsBigEndian |
3459 | 1570 |
|
1571 |
"Created: / 21.1.1998 / 17:43:53 / cg" |
|
1572 |
"Modified: / 5.3.1998 / 14:58:06 / stefan" |
|
1573 |
! |
|
1574 |
||
1575 |
doubleWordAtDoubleWordIndex:index MSB:msb |
|
13575 | 1576 |
"return the unsigned long at index, anInteger. |
3459 | 1577 |
Fetching is MSB if msb is true, LSB otherwise. |
1578 |
Indices are 1-based and scaled as appropriate to allow |
|
1579 |
accessing the memory as an array of doubleWord entries. |
|
1580 |
(i.e. indices are 1, 2, ...)" |
|
1581 |
||
1582 |
^ self doubleWordAt:(index - 1 * 4 + 1) MSB:msb |
|
1583 |
||
1584 |
"Created: / 21.1.1998 / 17:44:07 / cg" |
|
1585 |
! |
|
1586 |
||
1587 |
doubleWordAtDoubleWordIndex:index put:value |
|
13575 | 1588 |
"set the long at index, anInteger. |
3459 | 1589 |
Storing in the machines natural byte order. |
1590 |
Indices are 1-based and scaled as appropriate to allow |
|
1591 |
accessing the memory as an array of doubleWord entries. |
|
1592 |
(i.e. indices are 1, 2, ...)" |
|
1593 |
||
18284 | 1594 |
^ self doubleWordAtDoubleWordIndex:index put:value MSB:IsBigEndian |
3459 | 1595 |
|
1596 |
"Created: / 21.1.1998 / 17:44:13 / cg" |
|
1597 |
"Modified: / 5.3.1998 / 14:58:19 / stefan" |
|
1598 |
! |
|
1599 |
||
1600 |
doubleWordAtDoubleWordIndex:index put:value MSB:msb |
|
13575 | 1601 |
"set the long at index, anInteger. |
3459 | 1602 |
Storing is MSB if msb is true, LSB otherwise. |
1603 |
Indices are 1-based and scaled as appropriate to allow |
|
1604 |
accessing the memory as an array of doubleWord entries. |
|
1605 |
(i.e. indices are 1, 2, ...)" |
|
1606 |
||
1607 |
^ self doubleWordAt:(index - 1 * 4 + 1) put:value MSB:msb |
|
1608 |
||
1609 |
"Created: / 21.1.1998 / 17:44:19 / cg" |
|
3323 | 1610 |
! |
1611 |
||
1612 |
longAt:index |
|
1613 |
"return the 4-bytes starting at index as a signed Integer. |
|
3433 | 1614 |
The index is a smalltalk index (i.e. 1-based). |
4308 | 1615 |
The value is retrieved in the machines natural byte order, |
1616 |
therefore, this should only be used for byte-data which is |
|
1617 |
only used inside this machine. |
|
1618 |
To setup data packets which are to be sent to other machines, |
|
1619 |
or stored into a file, always use longAt:MSB: and specify |
|
1620 |
a definite byteOrder." |
|
3323 | 1621 |
|
1622 |
|w| |
|
1623 |
||
3434 | 1624 |
%{ |
1625 |
/* |
|
1626 |
* handle the most common cases fast ... |
|
1627 |
*/ |
|
1628 |
if (__isSmallInteger(index)) { |
|
4308 | 1629 |
unsigned char *cp; |
15004 | 1630 |
INT sz; |
3434 | 1631 |
|
4308 | 1632 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
1633 |
if (cp) { |
|
1634 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 1635 |
|
4308 | 1636 |
if ((idx+(sizeof(int)-1)) < sz) { |
1637 |
cp += idx; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1638 |
#if defined(__i386__) |
4308 | 1639 |
/* |
1640 |
* aligned or not, we dont care (i386 can do both) |
|
1641 |
*/ |
|
1642 |
{ |
|
1643 |
int iVal = ((int *)cp)[0]; |
|
3434 | 1644 |
|
4308 | 1645 |
RETURN (__MKINT(iVal)); |
1646 |
} |
|
1647 |
#else |
|
1648 |
/* |
|
1649 |
* aligned |
|
1650 |
*/ |
|
1651 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1652 |
int iVal = ((int *)cp)[0]; |
4308 | 1653 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
1654 |
# if __POINTER_SIZE__ == 8 |
8913 | 1655 |
RETURN (__mkSmallInteger(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1656 |
# else |
4308 | 1657 |
RETURN (__MKINT(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1658 |
# endif |
4308 | 1659 |
} |
1660 |
#endif |
|
1661 |
} |
|
1662 |
} |
|
3434 | 1663 |
} |
1664 |
%}. |
|
1665 |
||
3323 | 1666 |
w := self unsignedLongAt:index. |
1667 |
(w > (16r7FFFFFFF)) ifTrue:[ |
|
4308 | 1668 |
^ w - (16r100000000) |
3323 | 1669 |
]. |
1670 |
^ w |
|
1671 |
||
1672 |
" |
|
1673 |
|b| |
|
1674 |
b := ByteArray new:4. |
|
1675 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
13575 | 1676 |
(b longAt:1) |
3323 | 1677 |
" |
1678 |
||
1679 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
1680 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
1681 |
! |
|
1682 |
||
1683 |
longAt:index bigEndian:msb |
|
1684 |
"return the 4-bytes starting at index as a signed Integer. |
|
3433 | 1685 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1686 |
Depending on msb, the value is retrieved MSB-first or LSB-first. |
1687 |
This may be worth a primitive." |
|
1688 |
||
1689 |
|w| |
|
1690 |
||
1691 |
w := self unsignedLongAt:index bigEndian:msb. |
|
1692 |
(w > (16r7FFFFFFF)) ifTrue:[ |
|
4308 | 1693 |
^ w - (16r100000000) |
3323 | 1694 |
]. |
1695 |
^ w |
|
1696 |
||
1697 |
" |
|
1698 |
|b| |
|
1699 |
b := ByteArray new:4. |
|
1700 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
13575 | 1701 |
(b longAt:1) |
3323 | 1702 |
" |
1703 |
||
1704 |
"Modified: / 1.7.1996 / 21:11:33 / cg" |
|
1705 |
"Created: / 5.3.1998 / 14:02:03 / stefan" |
|
1706 |
! |
|
1707 |
||
1708 |
longAt:index put:value |
|
1709 |
"set the 4-bytes starting at index from the signed Integer value. |
|
3433 | 1710 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1711 |
The value is stored in the machines natural byte order. |
1712 |
This may be worth a primitive. |
|
1713 |
||
1714 |
This is the ST80 version of #signedDoubleWordAt:put:" |
|
1715 |
||
1716 |
|v| |
|
1717 |
||
3434 | 1718 |
%{ |
1719 |
/* |
|
1720 |
* handle the most common cases fast ... |
|
1721 |
*/ |
|
1722 |
if (__isSmallInteger(index)) { |
|
4308 | 1723 |
unsigned char *cp; |
15004 | 1724 |
INT sz; |
3434 | 1725 |
|
4308 | 1726 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
1727 |
if (cp) { |
|
1728 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 1729 |
|
4308 | 1730 |
if ((idx+(sizeof(int)-1)) < sz) { |
1731 |
cp += idx; |
|
1732 |
/* |
|
1733 |
* aligned |
|
1734 |
*/ |
|
1735 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
1736 |
INT __v; |
3434 | 1737 |
|
4308 | 1738 |
if (__isSmallInteger(value)) { |
18650 | 1739 |
// how about a range check? |
1740 |
((int *)cp)[0] = (int)(__intVal(value)); |
|
4308 | 1741 |
RETURN (value); |
3434 | 1742 |
} |
18666 | 1743 |
# if __POINTER_SIZE__ == 4 |
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
1744 |
if ((__v = __signedLongIntVal(value)) != 0) { |
18650 | 1745 |
// how about a range check? |
1746 |
((int *)cp)[0] = (int)(__v); |
|
3434 | 1747 |
RETURN (value); |
1748 |
} |
|
18666 | 1749 |
#endif |
4308 | 1750 |
} |
1751 |
} |
|
1752 |
} |
|
3434 | 1753 |
} |
1754 |
%}. |
|
1755 |
||
3323 | 1756 |
value >= 0 ifTrue:[ |
4308 | 1757 |
v := value |
3323 | 1758 |
] ifFalse:[ |
4308 | 1759 |
v := value + 16r100000000 |
3323 | 1760 |
]. |
1761 |
self unsignedLongAt:index put:v. |
|
1762 |
^ value |
|
1763 |
||
1764 |
" |
|
1765 |
|b| |
|
1766 |
b := ByteArray new:4. |
|
1767 |
b longAt:1 put:-1. |
|
13575 | 1768 |
(b unsignedLongAt:1) printStringRadix:16 |
3323 | 1769 |
" |
1770 |
||
1771 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
|
1772 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
1773 |
! |
|
1774 |
||
3444 | 1775 |
longAt:byteIndex put:anInteger bigEndian:msb |
1776 |
"store a signed long (32bit) integer. |
|
1777 |
The index is a smalltalk index (i.e. 1-based). |
|
1778 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
1779 |
||
1780 |
|v| |
|
1781 |
||
1782 |
v := anInteger. |
|
1783 |
anInteger < 0 ifTrue:[ |
|
4308 | 1784 |
v := v + 16r100000000 |
3444 | 1785 |
]. |
1786 |
^ self unsignedLongAt:byteIndex put:v bigEndian:msb |
|
1787 |
||
1788 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
1789 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
1790 |
! |
|
1791 |
||
18880 | 1792 |
nativeIntAt:index |
1793 |
"return the 4- or 8-bytes (depending on the native integer/pointer size) starting at index as a signed Integer. |
|
1794 |
The index is a smalltalk index (i.e. 1-based). |
|
1795 |
The value is retrieved in the machines natural byte order, |
|
1796 |
therefore, this should only be used for byte-data which is |
|
1797 |
only used inside this machine." |
|
1798 |
||
1799 |
|w| |
|
1800 |
||
1801 |
%{ |
|
1802 |
/* |
|
1803 |
* handle the most common cases fast ... |
|
1804 |
*/ |
|
1805 |
if (__isSmallInteger(index)) { |
|
1806 |
unsigned char *cp; |
|
1807 |
INT sz; |
|
1808 |
||
1809 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1810 |
if (cp) { |
|
1811 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1812 |
||
1813 |
if ((idx+(sizeof(INT)-1)) < sz) { |
|
1814 |
cp += idx; |
|
1815 |
#if defined(__i386__) |
|
1816 |
/* |
|
1817 |
* aligned or not, we dont care (i386 can do both) |
|
1818 |
*/ |
|
1819 |
{ |
|
1820 |
INT iVal = ((INT *)cp)[0]; |
|
1821 |
||
1822 |
RETURN (__MKINT(iVal)); |
|
1823 |
} |
|
1824 |
#else |
|
1825 |
/* |
|
1826 |
* aligned |
|
1827 |
*/ |
|
1828 |
if (((INT)cp & (sizeof(INT)-1)) == 0) { |
|
1829 |
INT iVal = ((INT *)cp)[0]; |
|
1830 |
||
1831 |
RETURN (__MKINT(iVal)); |
|
1832 |
} |
|
1833 |
#endif |
|
1834 |
} |
|
1835 |
} |
|
1836 |
} |
|
1837 |
%}. |
|
1838 |
||
1839 |
^ self primitiveFailed. |
|
1840 |
||
1841 |
" |
|
1842 |
|b| |
|
1843 |
b := ByteArray new:8. |
|
1844 |
b nativeIntAt:1 put:SmallInteger maxVal. |
|
1845 |
b nativeIntAt:1 |
|
1846 |
" |
|
1847 |
! |
|
1848 |
||
1849 |
nativeIntAt:index put:value |
|
1850 |
"set the 4- or 8-bytes (depending on INT-/pointer size) starting at index from the signed Integer value. |
|
1851 |
The index is a smalltalk index (i.e. 1-based). |
|
1852 |
The value is stored in the machines natural byte order." |
|
1853 |
||
1854 |
|v| |
|
1855 |
||
1856 |
%{ |
|
1857 |
/* |
|
1858 |
* handle the most common cases fast ... |
|
1859 |
*/ |
|
1860 |
if (__isSmallInteger(index)) { |
|
1861 |
unsigned char *cp; |
|
1862 |
INT sz; |
|
1863 |
||
1864 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1865 |
if (cp) { |
|
1866 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1867 |
||
1868 |
if ((idx+(sizeof(INT)-1)) < sz) { |
|
1869 |
cp += idx; |
|
1870 |
/* |
|
1871 |
* aligned |
|
1872 |
*/ |
|
1873 |
if (((INT)cp & (sizeof(INT)-1)) == 0) { |
|
1874 |
INT __v; |
|
1875 |
||
1876 |
if (__isSmallInteger(value)) { |
|
1877 |
// how about a range check? |
|
1878 |
((INT *)cp)[0] = (INT)(__intVal(value)); |
|
1879 |
RETURN (value); |
|
1880 |
} |
|
1881 |
if ((__v = __signedLongIntVal(value)) != 0) { |
|
1882 |
// how about a range check? |
|
1883 |
((INT *)cp)[0] = (INT)(__v); |
|
1884 |
RETURN (value); |
|
1885 |
} |
|
1886 |
} |
|
1887 |
} |
|
1888 |
} |
|
1889 |
} |
|
1890 |
%}. |
|
1891 |
^ self primitiveFailed. |
|
1892 |
||
1893 |
" |
|
1894 |
|b| |
|
1895 |
b := ByteArray new:8. |
|
1896 |
b nativeIntAt:1 put:SmallInteger maxVal. |
|
1897 |
(b nativeIntAt:1) |
|
1898 |
" |
|
1899 |
! |
|
1900 |
||
11850 | 1901 |
pointerAt:index |
1902 |
"get a pointer starting at index as ExternalAddress. |
|
13575 | 1903 |
The index is a smalltalk index (i.e. 1-based). |
11850 | 1904 |
Only aligned accesses are allowed." |
1905 |
||
1906 |
%{ |
|
1907 |
if (__isSmallInteger(index)) { |
|
13575 | 1908 |
unsigned char *cp; |
15004 | 1909 |
INT sz; |
13575 | 1910 |
|
1911 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1912 |
if (cp) { |
|
1913 |
unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1; |
|
13576 | 1914 |
char *pointer; |
13575 | 1915 |
|
1916 |
if ((idx+(sizeof(pointer)-1)) < sz) { |
|
1917 |
cp += idx; |
|
1918 |
/* |
|
1919 |
* aligned |
|
1920 |
*/ |
|
1921 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
1922 |
pointer = ((char **)cp)[0]; |
|
1923 |
RETURN (__MKEXTERNALADDRESS(pointer)); |
|
15004 | 1924 |
} else { |
1925 |
#if 0 |
|
1926 |
printf("cp UNALIGNED (%"_lx_")\n", (INT)cp); |
|
1927 |
#endif |
|
13575 | 1928 |
} |
15004 | 1929 |
} else { |
1930 |
#if 0 |
|
1931 |
printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n", |
|
1932 |
idx, (int)(sizeof(pointer)-1), sz); |
|
1933 |
#endif |
|
13575 | 1934 |
} |
15004 | 1935 |
} else { |
1936 |
#if 0 |
|
1937 |
printf("cp is NULL\n"); |
|
1938 |
#endif |
|
13575 | 1939 |
} |
15004 | 1940 |
} else { |
1941 |
#if 0 |
|
1942 |
printf("bad index\n"); |
|
1943 |
#endif |
|
11850 | 1944 |
} |
1945 |
bad:; |
|
1946 |
%}. |
|
1947 |
||
1948 |
self primitiveFailed. |
|
1949 |
||
1950 |
" |
|
1951 |
|b| |
|
1952 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
13575 | 1953 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
11850 | 1954 |
Transcript showCR:((b unsignedLongAt:1) printStringRadix:16). |
1955 |
Transcript showCR:((b pointerAt:1)). |
|
1956 |
" |
|
1957 |
! |
|
1958 |
||
6492 | 1959 |
pointerAt:index put:value |
15004 | 1960 |
"set the pointer starting at index from the integer or externalAddress value. |
13575 | 1961 |
The index is a smalltalk index (i.e. 1-based). |
6492 | 1962 |
Only aligned accesses are allowed. |
1963 |
The value is either an ExternalAddress or ExternalBytes" |
|
1964 |
||
1965 |
%{ |
|
1966 |
OBJ *pointer; |
|
1967 |
||
7814
c649ba9fd538
#pointerAt:put: now works for ExternalAddressLike objects
Stefan Vogel <sv@exept.de>
parents:
7813
diff
changeset
|
1968 |
if (__isExternalAddressLike(value)) { |
13575 | 1969 |
pointer = __externalAddressVal(value); |
7197
a68adb223592
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7193
diff
changeset
|
1970 |
} else if (__isExternalBytesLike(value)) { |
13575 | 1971 |
pointer = __externalBytesVal(value); |
1972 |
if (pointer == (OBJ *)0) |
|
1973 |
pointer = 0; |
|
11852 | 1974 |
} else if (value == nil) { |
13575 | 1975 |
pointer = 0; |
15004 | 1976 |
} else if (__isSmallInteger(value)) { |
1977 |
pointer = (OBJ *)__intVal(value); |
|
1978 |
} else { |
|
1979 |
if ((pointer = (OBJ *)__unsignedLongIntVal(value)) == 0) { |
|
1980 |
goto bad; |
|
1981 |
} |
|
1982 |
} |
|
6492 | 1983 |
|
1984 |
if (__isSmallInteger(index)) { |
|
13575 | 1985 |
unsigned char *cp; |
15004 | 1986 |
INT sz; |
13575 | 1987 |
|
1988 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1989 |
if (cp) { |
|
1990 |
unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1; |
|
1991 |
||
1992 |
if ((idx+(sizeof(pointer)-1)) < sz) { |
|
1993 |
cp += idx; |
|
1994 |
/* |
|
1995 |
* aligned |
|
1996 |
*/ |
|
1997 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
1998 |
((char **)cp)[0] = (char *) pointer; |
|
1999 |
RETURN (value); |
|
2000 |
} |
|
2001 |
} |
|
2002 |
} |
|
6492 | 2003 |
} |
2004 |
bad:; |
|
2005 |
%}. |
|
2006 |
||
2007 |
self primitiveFailed. |
|
2008 |
||
2009 |
" |
|
2010 |
|b| |
|
2011 |
b := ByteArray new:ExternalAddress pointerSize. |
|
13575 | 2012 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
2013 |
(b unsignedLongAt:1) printStringRadix:16 |
|
6492 | 2014 |
" |
2015 |
||
2016 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
|
2017 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
2018 |
! |
|
2019 |
||
19345 | 2020 |
pointerValueAt:index |
2021 |
"get a pointer starting at index as Integer. |
|
2022 |
The index is a smalltalk index (i.e. 1-based). |
|
2023 |
Only aligned accesses are allowed." |
|
2024 |
||
2025 |
%{ |
|
2026 |
if (__isSmallInteger(index)) { |
|
2027 |
unsigned char *cp; |
|
2028 |
INT sz; |
|
2029 |
||
2030 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2031 |
if (cp) { |
|
2032 |
unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1; |
|
2033 |
char *pointer; |
|
2034 |
||
2035 |
if ((idx+(sizeof(pointer)-1)) < sz) { |
|
2036 |
cp += idx; |
|
2037 |
/* |
|
2038 |
* aligned |
|
2039 |
*/ |
|
2040 |
if (((INT)cp & (sizeof(pointer)-1)) == 0) { |
|
2041 |
pointer = ((char **)cp)[0]; |
|
2042 |
RETURN (__MKUINT((INT)(pointer))); |
|
2043 |
} else { |
|
2044 |
#if 0 |
|
2045 |
printf("cp UNALIGNED (%"_lx_")\n", (INT)cp); |
|
2046 |
#endif |
|
2047 |
} |
|
2048 |
} else { |
|
2049 |
#if 0 |
|
2050 |
printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n", |
|
2051 |
idx, (int)(sizeof(pointer)-1), sz); |
|
2052 |
#endif |
|
2053 |
} |
|
2054 |
} else { |
|
2055 |
#if 0 |
|
2056 |
printf("cp is NULL\n"); |
|
2057 |
#endif |
|
2058 |
} |
|
2059 |
} else { |
|
2060 |
#if 0 |
|
2061 |
printf("bad index\n"); |
|
2062 |
#endif |
|
2063 |
} |
|
2064 |
bad:; |
|
2065 |
%}. |
|
2066 |
||
2067 |
self primitiveFailed. |
|
2068 |
||
2069 |
" |
|
2070 |
|b| |
|
2071 |
b := ByteArray new:(ExternalAddress pointerSize). |
|
2072 |
b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). |
|
2073 |
Transcript showCR:((b unsignedLongAt:1) printStringRadix:16). |
|
2074 |
Transcript showCR:((b pointerAt:1)). |
|
2075 |
Transcript showCR:((b pointerValueAt:1)). |
|
2076 |
" |
|
2077 |
! |
|
2078 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2079 |
signedDoubleWordAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2080 |
"return the 4-bytes starting at index as a signed Integer. |
3433 | 2081 |
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
|
2082 |
The value is retrieved in the machines natural byte order. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2083 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2084 |
|
18284 | 2085 |
^ self signedDoubleWordAt:index MSB:IsBigEndian |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2086 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2087 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2088 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2089 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2090 |
b doubleWordAt:1 put:16rFFFFFFFF. |
13575 | 2091 |
(b signedDoubleWordAt:1) |
4515 | 2092 |
" |
2093 |
" |
|
2094 |
|b| |
|
2095 |
b := ByteArray new:4. |
|
2096 |
b signedDoubleWordAt:1 put:-1. |
|
13575 | 2097 |
(b doubleWordAt:1) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2098 |
" |
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 |
"Modified: 1.7.1996 / 21:11:28 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2101 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2102 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2103 |
signedDoubleWordAt:index MSB:msb |
4515 | 2104 |
"return the 4-bytes starting at index as a (signed) Integer. |
3433 | 2105 |
The index is a smalltalk index (i.e. 1-based). |
4515 | 2106 |
The value is retrieved MSB-first, if the msb-arg is true; |
2107 |
LSB-first otherwise." |
|
2108 |
||
13575 | 2109 |
|val |
4515 | 2110 |
ival "{ Class: SmallInteger }" |
2111 |
t "{ Class: SmallInteger }" |
|
2112 |
i "{ Class: SmallInteger }" |
|
2113 |
b1 "{ Class: SmallInteger }" |
|
2114 |
b2 "{ Class: SmallInteger }" |
|
2115 |
b3 "{ Class: SmallInteger }" |
|
2116 |
b4 "{ Class: SmallInteger }"| |
|
2117 |
||
2118 |
%{ |
|
2119 |
/* |
|
2120 |
* handle the most common cases fast ... |
|
2121 |
*/ |
|
2122 |
if (__isSmallInteger(index)) { |
|
19047 | 2123 |
unsigned char *cp; |
2124 |
INT sz; |
|
2125 |
||
2126 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
2127 |
if (cp) { |
|
2128 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
2129 |
int iVal; |
|
2130 |
||
2131 |
if ((idx+(sizeof(int)-1)) < sz) { |
|
2132 |
cp += idx; |
|
2133 |
||
2134 |
if (msb == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2135 |
#if defined(__MSBFIRST__) |
19047 | 2136 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
2137 |
/* |
|
2138 |
* aligned |
|
2139 |
*/ |
|
2140 |
iVal = ((int *)cp)[0]; |
|
2141 |
} else |
|
4515 | 2142 |
#endif |
19047 | 2143 |
{ |
2144 |
iVal = cp[0]; |
|
2145 |
iVal = (iVal << 8) | cp[1]; |
|
2146 |
iVal = (iVal << 8) | cp[2]; |
|
2147 |
iVal = (iVal << 8) | cp[3]; |
|
2148 |
} |
|
2149 |
} else { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2150 |
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__)) |
19047 | 2151 |
/* |
2152 |
* aligned or not - we dont care |
|
2153 |
* (i386 can fetch unaligned) |
|
2154 |
*/ |
|
2155 |
iVal = ((int *)cp)[0]; |
|
4515 | 2156 |
#else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2157 |
# if defined(__LSBFIRST__) |
19047 | 2158 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
2159 |
/* |
|
2160 |
* aligned |
|
2161 |
*/ |
|
2162 |
iVal = ((int *)cp)[0]; |
|
2163 |
} else |
|
4515 | 2164 |
# endif |
19047 | 2165 |
{ |
2166 |
iVal = cp[3]; |
|
2167 |
iVal = (iVal << 8) | cp[2]; |
|
2168 |
iVal = (iVal << 8) | cp[1]; |
|
2169 |
iVal = (iVal << 8) | cp[0]; |
|
2170 |
} |
|
4515 | 2171 |
#endif |
19047 | 2172 |
} |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8893
diff
changeset
|
2173 |
#if __POINTER_SIZE__ == 8 |
19047 | 2174 |
RETURN (__mkSmallInteger(iVal)); |
4515 | 2175 |
#else |
19047 | 2176 |
RETURN (__MKINT(iVal)); |
4515 | 2177 |
#endif |
19047 | 2178 |
} |
2179 |
} |
|
4515 | 2180 |
} |
2181 |
%}. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2182 |
|
4515 | 2183 |
"/ fallBack code - non ByteArray-like receiver |
2184 |
"/ or funny index |
|
2185 |
||
2186 |
i := index. |
|
19047 | 2187 |
b1 := self byteAt:i. |
2188 |
b2 := self byteAt:(i+1). |
|
2189 |
b3 := self byteAt:(i+2). |
|
2190 |
b4 := self byteAt:(i+3). |
|
4515 | 2191 |
|
2192 |
msb ifFalse:[ |
|
19047 | 2193 |
t := b4. b4 := b1. b1 := t. |
2194 |
t := b3. b3 := b2. b2 := t. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2195 |
]. |
4515 | 2196 |
ival := b1. |
2197 |
ival := (ival bitShift:8) + b2. |
|
2198 |
ival := (ival bitShift:8) + b3. |
|
2199 |
val := (ival bitShift:8) + b4. |
|
2200 |
||
2201 |
(val > (16r7FFFFFFF)) ifTrue:[ |
|
19047 | 2202 |
^ val - (16r100000000) |
4515 | 2203 |
]. |
2204 |
^ val |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2205 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2206 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2207 |
|b| |
4515 | 2208 |
|
2209 |
b := ByteArray withAll:#(1 2 3 4). |
|
13575 | 2210 |
(b signedDoubleWordAt:1 MSB:true) printStringRadix:16. |
2211 |
(b signedDoubleWordAt:1 MSB:false) printStringRadix:16 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2212 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2213 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2214 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2215 |
signedDoubleWordAt:index put:value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2216 |
"set the 4-bytes starting at index from the signed Integer value. |
3433 | 2217 |
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
|
2218 |
The value is stored in the machines natural byte order. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2219 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2220 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2221 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2222 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2223 |
value >= 0 ifTrue:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2224 |
v := value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2225 |
] ifFalse:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2226 |
v := value + 16r100000000 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2227 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2228 |
self doubleWordAt:index put:v. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2229 |
^ value |
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 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2233 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2234 |
b signedDoubleWordAt:1 put:-1. |
13575 | 2235 |
(b doubleWordAt:1) printStringRadix:16 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2236 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2237 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2238 |
"Modified: 1.7.1996 / 21:11:39 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2239 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2240 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2241 |
signedDoubleWordAt:index put:value MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2242 |
"set the 4-bytes starting at index from the signed Integer value. |
3433 | 2243 |
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
|
2244 |
Depending on msb, the value is stored MSB-first or LSB-first. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2245 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2246 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2247 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2248 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2249 |
value >= 0 ifTrue:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2250 |
v := value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2251 |
] ifFalse:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2252 |
v := value + 16r100000000 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2253 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2254 |
self doubleWordAt:index put:v MSB:msb. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2255 |
^ value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2256 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2257 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2258 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2259 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2260 |
b signedDoubleWordAt:1 put:-1. |
13575 | 2261 |
(b doubleWordAt:1) printStringRadix:16 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2262 |
" |
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 |
"Modified: 1.7.1996 / 21:11:46 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2265 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2266 |
|
3323 | 2267 |
unsignedLongAt:index |
2268 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 2269 |
The index is a smalltalk index (i.e. 1-based). |
19301 | 2270 |
The value is retrieved in the machine's natural byte order. |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2271 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2272 |
Same as doubleWordAt: for protocol completeness" |
3323 | 2273 |
|
19301 | 2274 |
^ self doubleWordAt:index MSB:IsBigEndian |
3323 | 2275 |
|
2276 |
" |
|
2277 |
|b| |
|
2278 |
||
2279 |
b := ByteArray withAll:#(1 2 3 4). |
|
13575 | 2280 |
(b unsignedLongAt:1) printStringRadix:16 |
3323 | 2281 |
" |
2282 |
||
2283 |
"Created: / 5.3.1998 / 11:56:53 / stefan" |
|
2284 |
"Modified: / 5.3.1998 / 14:58:48 / stefan" |
|
2285 |
! |
|
2286 |
||
2287 |
unsignedLongAt:index bigEndian:msb |
|
2288 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 2289 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2290 |
The value is retrieved MSB-first, if the msb-arg is true; |
2291 |
LSB-first otherwise. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2292 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2293 |
Same as doubleWordAt:MSB: for protocol completeness" |
3323 | 2294 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2295 |
^ self doubleWordAt:index MSB:msb |
3323 | 2296 |
|
2297 |
" |
|
2298 |
|b| |
|
2299 |
||
2300 |
b := ByteArray withAll:#(1 2 3 4). |
|
13575 | 2301 |
(b unsignedLongAt:1 bigEndian:true) printStringRadix:16. |
2302 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
3323 | 2303 |
" |
2304 |
||
2305 |
"Modified: / 21.1.1998 / 17:42:30 / cg" |
|
2306 |
"Created: / 5.3.1998 / 11:46:05 / stefan" |
|
2307 |
! |
|
2308 |
||
2309 |
unsignedLongAt:index put:value |
|
2310 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 2311 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2312 |
The value should be in the range 0 to 16rFFFFFFFF |
2313 |
(for negative values, the stored value is not defined). |
|
2314 |
The value is stored in the machines natural byte order. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2315 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2316 |
Same as doubleWordAt:put: for protocol completeness" |
3323 | 2317 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2318 |
^ self doubleWordAt:index put:value |
3323 | 2319 |
|
2320 |
" |
|
2321 |
|b| |
|
2322 |
b := ByteArray new:4. |
|
2323 |
b unsignedLongAt:1 put:16r04030201. |
|
2324 |
b inspect |
|
2325 |
" |
|
2326 |
||
2327 |
"Created: / 5.3.1998 / 11:57:44 / stefan" |
|
2328 |
"Modified: / 5.3.1998 / 14:58:59 / stefan" |
|
2329 |
! |
|
2330 |
||
2331 |
unsignedLongAt:index put:aNumber bigEndian:msb |
|
2332 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 2333 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2334 |
The value must be in the range 0 to 16rFFFFFFFF. |
2335 |
The value is stored MSB-first if msb is true; LSB-first otherwise. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2336 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2337 |
Same as doubleWordAt:put:MSB: for protocol completeness" |
3323 | 2338 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
2339 |
^ self doubleWordAt:index put:aNumber MSB:msb |
3323 | 2340 |
|
2341 |
" |
|
2342 |
|b| |
|
2343 |
b := ByteArray new:8. |
|
2344 |
b unsignedLongAt:1 put:16r04030201 bigEndian:true. |
|
2345 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
2346 |
" |
|
2347 |
||
2348 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
2349 |
"Created: / 5.3.1998 / 11:43:53 / stefan" |
|
2350 |
"Modified: / 5.3.1998 / 11:47:30 / stefan" |
|
3459 | 2351 |
! ! |
2352 |
||
13724 | 2353 |
!UninterpretedBytes methodsFor:'accessing-shorts (16bit)'! |
3459 | 2354 |
|
2355 |
shortAt:index |
|
2356 |
"return the 2-bytes starting at index as a signed Integer. |
|
2357 |
The index is a smalltalk index (i.e. 1-based). |
|
2358 |
The value is retrieved in the machines natural byte order. |
|
2359 |
This may be worth a primitive. |
|
2360 |
This is the ST80 equivalent of #signedWordAt:" |
|
2361 |
||
2362 |
^ (self unsignedShortAt:index) signExtendedShortValue |
|
2363 |
||
2364 |
" |
|
2365 |
|b| |
|
2366 |
b := ByteArray new:2. |
|
2367 |
b unsignedShortAt:1 put:16rFFFF. |
|
13575 | 2368 |
b shortAt:1 |
3459 | 2369 |
" |
2370 |
||
2371 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
|
2372 |
"Created: / 5.3.1998 / 10:59:57 / stefan" |
|
2373 |
"Modified: / 5.3.1998 / 23:39:38 / stefan" |
|
3323 | 2374 |
! |
2375 |
||
3459 | 2376 |
shortAt:index bigEndian:msb |
2377 |
"return the 2-bytes starting at index as a signed Integer. |
|
3433 | 2378 |
The index is a smalltalk index (i.e. 1-based). |
3459 | 2379 |
The value is retrieved MSB-first, if the msb-arg is true; |
2380 |
LSB-first otherwise. |
|
2381 |
This is the ST80 equivalent of #signedWordAt:" |
|
2382 |
||
2383 |
^ (self unsignedShortAt:index bigEndian:msb) signExtendedShortValue |
|
2384 |
||
2385 |
" |
|
2386 |
|b| |
|
2387 |
b := ByteArray new:2. |
|
2388 |
b unsignedShortAt:1 put:16rFFFF. |
|
13575 | 2389 |
b shortAt:1 |
3459 | 2390 |
" |
3323 | 2391 |
|
3459 | 2392 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
2393 |
"Created: / 5.3.1998 / 23:41:21 / stefan" |
|
2394 |
! |
|
2395 |
||
2396 |
shortAt:index put:value |
|
2397 |
"set the 2-bytes starting at index from the signed Integer value. |
|
2398 |
The index is a smalltalk index (i.e. 1-based). |
|
2399 |
The stored value must be in the range -32768 .. +32676. |
|
2400 |
The value is stored in the machines natural byteorder. |
|
2401 |
This may be worth a primitive. |
|
2402 |
This is the ST80 equivalent of #signedWordAt:put:" |
|
2403 |
||
3323 | 2404 |
|
3459 | 2405 |
|v| |
2406 |
||
2407 |
value >= 0 ifTrue:[ |
|
18346 | 2408 |
v := value |
3323 | 2409 |
] ifFalse:[ |
18346 | 2410 |
v := 16r10000 + value |
3323 | 2411 |
]. |
18284 | 2412 |
self unsignedShortAt:index put:v bigEndian:IsBigEndian. |
3459 | 2413 |
^ value |
2414 |
||
2415 |
" |
|
2416 |
|b| |
|
2417 |
b := ByteArray new:6. |
|
2418 |
b shortAt:1 put:-1. |
|
2419 |
b shortAt:3 put:-2. |
|
2420 |
b shortAt:5 put:0. |
|
2421 |
b inspect |
|
2422 |
" |
|
2423 |
||
2424 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
2425 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
2426 |
! |
|
2427 |
||
8017 | 2428 |
shortAt:index put:value bigEndian:bigEndian |
2429 |
"set the 2-bytes starting at index from the signed Integer value. |
|
2430 |
The index is a smalltalk index (i.e. 1-based). |
|
2431 |
The stored value must be in the range -32768 .. +32676. |
|
8018 | 2432 |
The value is stored in the byteorder given by bigEndian. |
2433 |
This may be worth a primitive." |
|
8017 | 2434 |
|
2435 |
||
2436 |
|v| |
|
2437 |
||
2438 |
value >= 0 ifTrue:[ |
|
13575 | 2439 |
v := value |
8017 | 2440 |
] ifFalse:[ |
13575 | 2441 |
v := 16r10000 + value |
8017 | 2442 |
]. |
2443 |
self unsignedShortAt:index put:v bigEndian:bigEndian. |
|
2444 |
^ value |
|
2445 |
||
2446 |
" |
|
2447 |
|b| |
|
2448 |
b := ByteArray new:4. |
|
2449 |
b shortAt:1 put:1 bigEndian:true. |
|
2450 |
b shortAt:3 put:1 bigEndian:false. |
|
2451 |
b inspect |
|
2452 |
" |
|
2453 |
||
2454 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
2455 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
2456 |
! |
|
2457 |
||
3459 | 2458 |
signedWordAt:index |
2459 |
"return the 2-bytes starting at index as a signed Integer. |
|
2460 |
The index is a smalltalk index (i.e. 1-based). |
|
2461 |
The value is retrieved in the machines natural byte order. |
|
2462 |
This may be worth a primitive." |
|
2463 |
||
2464 |
^ (self wordAt:index) signExtendedShortValue |
|
3323 | 2465 |
|
2466 |
" |
|
2467 |
|b| |
|
3459 | 2468 |
b := ByteArray new:2. |
2469 |
b wordAt:1 put:16rFFFF. |
|
13575 | 2470 |
b signedWordAt:1 |
3323 | 2471 |
" |
2472 |
||
3459 | 2473 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
3323 | 2474 |
! |
2475 |
||
3459 | 2476 |
signedWordAt:index MSB:msb |
2477 |
"return the 2-bytes starting at index as a signed Integer. |
|
3433 | 2478 |
The index is a smalltalk index (i.e. 1-based). |
3459 | 2479 |
The value is retrieved MSB-first if the msb-arg is true, |
2480 |
LSB-first otherwise. |
|
2481 |
This may be worth a primitive." |
|
3323 | 2482 |
|
3459 | 2483 |
^ (self wordAt:index MSB:msb) signExtendedShortValue |
3323 | 2484 |
|
2485 |
" |
|
2486 |
|b| |
|
3459 | 2487 |
b := ByteArray new:2. |
2488 |
b wordAt:1 put:16r0080. |
|
13575 | 2489 |
b signedWordAt:1 MSB:true. |
2490 |
b signedWordAt:1 MSB:false. |
|
3459 | 2491 |
" |
2492 |
||
2493 |
"Modified: 1.7.1996 / 21:15:57 / cg" |
|
2494 |
! |
|
2495 |
||
2496 |
signedWordAt:index put:value |
|
2497 |
"set the 2-bytes starting at index from the signed Integer value. |
|
2498 |
The index is a smalltalk index (i.e. 1-based). |
|
2499 |
The stored value must be in the range -32768 .. +32676. |
|
2500 |
The value is stored in the machines natural byteorder. |
|
2501 |
This may be worth a primitive. |
|
2502 |
This is the ST80 equivalent of #signedWordAt:put:" |
|
2503 |
||
2504 |
||
2505 |
|v| |
|
2506 |
||
2507 |
value >= 0 ifTrue:[ |
|
4308 | 2508 |
v := value |
3459 | 2509 |
] ifFalse:[ |
4308 | 2510 |
v := 16r10000 + value |
3459 | 2511 |
]. |
2512 |
self unsignedShortAt:index put:v. |
|
2513 |
^ value |
|
2514 |
||
2515 |
" |
|
2516 |
|b| |
|
2517 |
b := ByteArray new:6. |
|
2518 |
b shortAt:1 put:-1. |
|
2519 |
b shortAt:3 put:-2. |
|
2520 |
b shortAt:5 put:0. |
|
3323 | 2521 |
b inspect |
2522 |
" |
|
2523 |
||
3459 | 2524 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
2525 |
"Modified: / 5.3.1998 / 11:01:30 / stefan" |
|
2526 |
! |
|
2527 |
||
2528 |
signedWordAt:index put:value MSB:msb |
|
2529 |
"set the 2-bytes starting at index from the signed Integer value. |
|
2530 |
The index is a smalltalk index (i.e. 1-based). |
|
2531 |
The stored value must be in the range -32768 .. +32676. |
|
2532 |
The value is stored MSB-first, if the msb-arg is true; |
|
2533 |
LSB-first otherwise. |
|
2534 |
This may be worth a primitive." |
|
2535 |
||
2536 |
|v| |
|
2537 |
||
2538 |
value >= 0 ifTrue:[ |
|
2539 |
v := value |
|
2540 |
] ifFalse:[ |
|
2541 |
v := 16r10000 + value |
|
2542 |
]. |
|
2543 |
self wordAt:index put:v MSB:msb. |
|
2544 |
^ value |
|
2545 |
||
2546 |
" |
|
2547 |
|b| |
|
2548 |
b := ByteArray new:4. |
|
2549 |
b signedWordAt:1 put:-1. |
|
2550 |
b signedWordAt:3 put:-2. |
|
2551 |
b inspect |
|
2552 |
" |
|
2553 |
||
2554 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
3323 | 2555 |
! |
2556 |
||
2557 |
unsignedShortAt:index |
|
2558 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
3433 | 2559 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2560 |
The value is retrieved in the machines natural byte order |
2561 |
Subclasses may redefine this for better performance. |
|
2562 |
This is the ST80 equivalent of #wordAt:" |
|
2563 |
||
2564 |
||
18284 | 2565 |
^ self unsignedShortAt:index bigEndian:IsBigEndian |
3323 | 2566 |
|
2567 |
"Created: / 5.3.1998 / 11:38:25 / stefan" |
|
2568 |
"Modified: / 5.3.1998 / 14:59:25 / stefan" |
|
2569 |
! |
|
2570 |
||
2571 |
unsignedShortAt:index bigEndian:msb |
|
2572 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
3433 | 2573 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 2574 |
The value is retrieved MSB-first (high 8 bits at lower index) if msb is true; |
2575 |
LSB-first (i.e. low 8-bits at lower byte index) if its false)" |
|
2576 |
||
13575 | 2577 |
|b1 "{ Class: SmallInteger }" |
3323 | 2578 |
b2 "{ Class: SmallInteger }"| |
2579 |
||
19046 | 2580 |
b1 := self byteAt:index. |
2581 |
b2 := self byteAt:(index + 1). |
|
3323 | 2582 |
msb ifTrue:[ |
19046 | 2583 |
^ (b1 bitShift:8) + b2 |
3323 | 2584 |
]. |
2585 |
^ (b2 bitShift:8) + b1 |
|
2586 |
||
2587 |
"Modified: / 21.1.1998 / 17:46:07 / cg" |
|
2588 |
"Created: / 5.3.1998 / 11:49:29 / stefan" |
|
2589 |
! |
|
2590 |
||
2591 |
unsignedShortAt:index put:value |
|
2592 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 2593 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 2594 |
The stored value must be in the range 0 .. 16rFFFF. |
3323 | 2595 |
The value is stored in the machines natural byteorder." |
2596 |
||
18284 | 2597 |
^ self unsignedShortAt:index put:value bigEndian:IsBigEndian |
3323 | 2598 |
|
2599 |
" |
|
2600 |
|b| |
|
2601 |
b := ByteArray new:4. |
|
2602 |
b unsignedShortAt:1 put:16r0102. |
|
2603 |
b unsignedShortAt:3 put:16r0304. |
|
13575 | 2604 |
b inspect |
3323 | 2605 |
" |
2606 |
||
2607 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
2608 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
2609 |
! |
|
2610 |
||
2611 |
unsignedShortAt:index put:value bigEndian:msb |
|
2612 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 2613 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 2614 |
The stored value must be in the range 0 .. 16rFFFF. |
3323 | 2615 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
2616 |
lower index) if msb is false, MSB-first otherwise" |
|
2617 |
||
2618 |
|b1 b2 |
|
2619 |
iVal "{ Class: SmallInteger }"| |
|
2620 |
||
2621 |
iVal := value. |
|
2622 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
|
19046 | 2623 |
^ self elementBoundsError:iVal |
3323 | 2624 |
]. |
2625 |
msb ifTrue:[ |
|
19046 | 2626 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
2627 |
b2 := (iVal bitAnd:16rFF). |
|
3323 | 2628 |
] ifFalse:[ |
19046 | 2629 |
b1 := (iVal bitAnd:16rFF). |
2630 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
|
3323 | 2631 |
]. |
19046 | 2632 |
self byteAt:index put:b1. |
2633 |
self byteAt:index+1 put:b2. |
|
3323 | 2634 |
^ value |
2635 |
||
2636 |
" |
|
2637 |
|b| |
|
2638 |
b := ByteArray new:8. |
|
2639 |
b unsignedShortAt:1 put:16r0102 bigEndian:false. |
|
2640 |
b unsignedShortAt:3 put:16r0304 bigEndian:false. |
|
2641 |
b unsignedShortAt:5 put:16r0102 bigEndian:true. |
|
2642 |
b unsignedShortAt:7 put:16r0304 bigEndian:true. |
|
13575 | 2643 |
b inspect |
3323 | 2644 |
" |
2645 |
||
2646 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
2647 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
2648 |
! |
|
2649 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2650 |
wordAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2651 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 2652 |
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
|
2653 |
The value is retrieved in the machines natural byte order |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2654 |
Subclasses may redefine this for better performance." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2655 |
|
18284 | 2656 |
^ self wordAt:index MSB:IsBigEndian |
3323 | 2657 |
|
2658 |
"Modified: / 5.3.1998 / 14:59:51 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2659 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2660 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2661 |
wordAt:index MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2662 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 2663 |
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
|
2664 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2665 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
19046 | 2666 |
Notice: |
2667 |
the index is a byte index; thus, this allows for unaligned access to |
|
2668 |
words on any boundary. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2669 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2670 |
|
13575 | 2671 |
|b1 "{ Class: SmallInteger }" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2672 |
b2 "{ Class: SmallInteger }"| |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2673 |
|
19046 | 2674 |
b1 := self byteAt:index. |
2675 |
b2 := self byteAt:(index + 1). |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2676 |
msb ifTrue:[ |
19046 | 2677 |
^ (b1 bitShift:8) + b2 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2678 |
]. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2679 |
^ (b2 bitShift:8) + b1 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2680 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2681 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2682 |
wordAt:index put:value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2683 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 2684 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 2685 |
The stored value must be in the range 0 .. 16rFFFF. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2686 |
The value is stored in the machines natural byteorder. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2687 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2688 |
|
18284 | 2689 |
^ self wordAt:index put:value MSB:IsBigEndian |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2690 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2691 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2692 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2693 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2694 |
b wordAt:1 put:16r0102. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2695 |
b wordAt:3 put:16r0304. |
13575 | 2696 |
b inspect |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2697 |
" |
3323 | 2698 |
|
2699 |
"Modified: / 5.3.1998 / 15:00:03 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2700 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2701 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2702 |
wordAt:index put:value MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2703 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 2704 |
The index is a smalltalk index (i.e. 1-based). |
13575 | 2705 |
The stored value must be in the range 0 .. 16rFFFF. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2706 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2707 |
lower index) if msb is false, MSB-first otherwise. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2708 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2709 |
|
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2710 |
|b1 b2 |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2711 |
iVal "{ Class: SmallInteger }"| |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2712 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2713 |
iVal := value. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2714 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
19046 | 2715 |
^ self elementBoundsError:iVal |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2716 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2717 |
msb ifTrue:[ |
19046 | 2718 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
2719 |
b2 := (iVal bitAnd:16rFF). |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2720 |
] ifFalse:[ |
19046 | 2721 |
b1 := (iVal bitAnd:16rFF). |
2722 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2723 |
]. |
19046 | 2724 |
self byteAt:index put:b1. |
2725 |
self byteAt:index+1 put:b2. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2726 |
^ value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2727 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2728 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2729 |
b := ByteArray new:8. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2730 |
b wordAt:1 put:16r0102 MSB:false. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2731 |
b wordAt:3 put:16r0304 MSB:false. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2732 |
b wordAt:5 put:16r0102 MSB:true. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2733 |
b wordAt:7 put:16r0304 MSB:true. |
13575 | 2734 |
b inspect |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2735 |
" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2736 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2737 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2738 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2739 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2740 |
wordAtWordIndex:index |
13575 | 2741 |
"return the unsigned short at index, anInteger. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2742 |
Fetching in the machines natural byte order. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2743 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2744 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2745 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2746 |
|
18284 | 2747 |
^ self wordAtWordIndex:index MSB:IsBigEndian |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2748 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2749 |
"Created: / 21.1.1998 / 17:48:26 / cg" |
3323 | 2750 |
"Modified: / 5.3.1998 / 15:00:16 / stefan" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2751 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2752 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2753 |
wordAtWordIndex:index MSB:msb |
13575 | 2754 |
"return the unsigned short at index, anInteger. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2755 |
Fetching is MSB if msb is true, LSB otherwise. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2756 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2757 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2758 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2759 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2760 |
^ self wordAt:(index - 1 * 2 + 1) MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2761 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2762 |
"Created: / 21.1.1998 / 17:48:30 / cg" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2763 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2764 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2765 |
wordAtWordIndex:index put:value |
13575 | 2766 |
"set the short at index, anInteger. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2767 |
Storing in the machines natural byte order. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2768 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2769 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2770 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2771 |
|
18284 | 2772 |
^ self wordAtWordIndex:index put:value MSB:IsBigEndian |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2773 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2774 |
"Created: / 21.1.1998 / 17:48:34 / cg" |
3323 | 2775 |
"Modified: / 5.3.1998 / 15:00:27 / stefan" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2776 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2777 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2778 |
wordAtWordIndex:index put:value MSB:msb |
13575 | 2779 |
"set the short at index, anInteger. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2780 |
Storing is MSB if msb is true, LSB otherwise. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2781 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2782 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2783 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2784 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2785 |
^ self wordAt:(index - 1 * 2 + 1) put:value MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2786 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
2787 |
"Created: / 21.1.1998 / 17:48:38 / cg" |
3459 | 2788 |
! ! |
2789 |
||
2790 |
!UninterpretedBytes methodsFor:'accessing-strings'! |
|
2791 |
||
2792 |
stringAt:index |
|
2793 |
"return a string starting at index up to the 0-byte. |
|
2794 |
The index is a smalltalk index (i.e. 1-based)." |
|
2795 |
||
2796 |
|stream i "{ Class: SmallInteger }" c| |
|
2797 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2798 |
stream := WriteStream on:(String new:40). |
3459 | 2799 |
i := index. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2800 |
[(c := self byteAt:i) ~~ 0] whileTrue:[ |
13575 | 2801 |
stream nextPut:(Character value:c). |
2802 |
i := i + 1. |
|
3459 | 2803 |
]. |
2804 |
^ stream contents |
|
2805 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2806 |
" |
13575 | 2807 |
#[71 72 73 74 75 76 77 0] stringAt:1 |
2808 |
#[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
|
2809 |
'1234567890' stringAt:2 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2810 |
" |
3459 | 2811 |
! |
2812 |
||
2813 |
stringAt:index put:aString |
|
19196 | 2814 |
"copy aString to the receiver, starting at index up to |
7815 | 2815 |
(and including) the 0-byte (which is always written). |
3459 | 2816 |
The index is a smalltalk index (i.e. 1-based)." |
2817 |
||
2818 |
|i "{ Class: SmallInteger }"| |
|
2819 |
||
2820 |
i := index. |
|
2821 |
aString do:[:aChar | |
|
19196 | 2822 |
self byteAt:i put:aChar codePoint. |
2823 |
i := i + 1. |
|
3459 | 2824 |
]. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2825 |
self byteAt:i put:0. |
3459 | 2826 |
^ aString |
2827 |
||
2828 |
" |
|
2829 |
|bytes| |
|
2830 |
||
2831 |
bytes := ExternalBytes new:10. |
|
2832 |
bytes stringAt:1 put:'hello'. |
|
2833 |
1 to:bytes size do:[:i | |
|
19196 | 2834 |
Transcript showCR:(bytes at:i) |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2835 |
]. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2836 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2837 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2838 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2839 |
(String new:20) stringAt:1 put:'hello'; stringAt:6 put:' world'; yourself |
3459 | 2840 |
" |
2841 |
||
2842 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
|
2843 |
! |
|
2844 |
||
7812 | 2845 |
stringAt:index put:aString size:maxSize |
19196 | 2846 |
"copy aString to the receiver, starting at index up to either maxSize characters, |
7812 | 2847 |
or (and including) the 0-byte, whichever is encountered first. |
7815 | 2848 |
The final 0-byte is only written, if the string is shorter than maxSize. |
7812 | 2849 |
The index is a smalltalk index (i.e. 1-based)." |
2850 |
||
2851 |
|remaining "{ Class: SmallInteger }" |
|
2852 |
i "{ Class: SmallInteger }"| |
|
2853 |
||
2854 |
remaining := maxSize. |
|
7816 | 2855 |
remaining <= 0 ifTrue:[^ aString]. |
7812 | 2856 |
|
2857 |
i := index. |
|
2858 |
aString do:[:aChar | |
|
19196 | 2859 |
self byteAt:i put:aChar codePoint. |
2860 |
i := i + 1. |
|
2861 |
remaining := remaining - 1. |
|
2862 |
remaining <= 0 ifTrue:[^ aString]. |
|
7812 | 2863 |
]. |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2864 |
self byteAt:i put:0. |
7812 | 2865 |
^ aString |
2866 |
||
2867 |
" |
|
2868 |
|bytes| |
|
2869 |
||
2870 |
bytes := ExternalBytes new:10. |
|
2871 |
bytes stringAt:1 put:'hello' size:3. |
|
2872 |
1 to:bytes size do:[:i | |
|
19196 | 2873 |
Transcript showCR:(bytes at:i) |
7812 | 2874 |
] |
2875 |
" |
|
2876 |
" |
|
2877 |
|bytes| |
|
2878 |
||
2879 |
bytes := ByteArray new:10 withAll:16rFF. |
|
2880 |
bytes stringAt:1 put:'he' size:3. |
|
2881 |
1 to:bytes size do:[:i | |
|
19196 | 2882 |
Transcript showCR:(bytes at:i) |
7812 | 2883 |
] |
2884 |
" |
|
2885 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2886 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2887 |
(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
|
2888 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2889 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2890 |
|
7812 | 2891 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
2892 |
! |
|
2893 |
||
3459 | 2894 |
stringAt:index size:maxSize |
2895 |
"return a string starting at index up to maxSize, or a 0-byte. |
|
2896 |
The index is a smalltalk index (i.e. 1-based)." |
|
2897 |
||
13575 | 2898 |
|stream c |
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2899 |
max "{ Class: SmallInteger }" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2900 |
start "{ Class: SmallInteger }"| |
3459 | 2901 |
|
2902 |
stream := WriteStream on:(String new:maxSize). |
|
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2903 |
start := index. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2904 |
max := start + maxSize - 1. |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2905 |
|
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2906 |
start to:max do:[:eachIndex| |
13575 | 2907 |
c := self byteAt:eachIndex. |
2908 |
c == 0 ifTrue:[ |
|
2909 |
^ stream contents |
|
2910 |
]. |
|
2911 |
stream nextPut:(Character value:c). |
|
3459 | 2912 |
]. |
2913 |
^ stream contents |
|
2914 |
||
10676
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2915 |
" |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2916 |
#[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
|
2917 |
#[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
|
2918 |
'1234567890' stringAt:2 size:6 |
252a445bf47d
#stringAt:* now works on Strings, too
Stefan Vogel <sv@exept.de>
parents:
10675
diff
changeset
|
2919 |
" |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2920 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2921 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2922 |
zeroByteStringAt:index maximumSize:count |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2923 |
"extract a zeroByte-delimited string, given initial index and |
3433 | 2924 |
maximum number of characters (bytes). |
2925 |
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
|
2926 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2927 |
|bytes idx| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2928 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2929 |
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
|
2930 |
idx := bytes indexOf:0. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2931 |
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
|
2932 |
^ bytes asString |
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 |
"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
|
2935 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2936 |
|
12951 | 2937 |
!UninterpretedBytes methodsFor:'converting'! |
2938 |
||
2939 |
asExternalBytes |
|
2940 |
|sz bytes| |
|
2941 |
||
14142 | 2942 |
sz := self byteSize. |
12951 | 2943 |
bytes := ExternalBytes unprotectedNew:sz. |
2944 |
bytes replaceBytesFrom:1 to:sz with:self startingAt:1. |
|
2945 |
^ bytes |
|
2946 |
||
2947 |
" |
|
2948 |
#[1 2 3 4 5 6 7] asExternalBytes |
|
2949 |
'Hello World' asExternalBytes |
|
14142 | 2950 |
'Hello World' asUnicodeString asExternalBytes |
12951 | 2951 |
" |
14132 | 2952 |
! |
2953 |
||
14155 | 2954 |
asExternalBytesUnprotected |
2955 |
"Like asExternalBytes, but does not register the bytes so |
|
15836 | 2956 |
bytes are GARBAGE-COLLECTED." |
14155 | 2957 |
|
2958 |
|bytes sz| |
|
2959 |
||
2960 |
sz := self byteSize. |
|
15836 | 2961 |
bytes := ExternalBytes unprotectedNew:sz. |
14155 | 2962 |
bytes replaceFrom:1 to:sz with:self startingAt:1. |
2963 |
^ bytes |
|
2964 |
||
2965 |
" |
|
2966 |
|x| |
|
2967 |
x := 'fooBar' asExternalBytesUnprotected. |
|
2968 |
ObjectMemory garbageCollect |
|
2969 |
" |
|
2970 |
||
2971 |
"Created: / 05-06-2012 / 14:11:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15836 | 2972 |
"Modified: / 30-11-2013 / 11:42:21 / cg" |
14155 | 2973 |
! |
2974 |
||
18600 | 2975 |
asSingleByteString |
2976 |
"return the receiver converted to a 'normal' string. |
|
2977 |
Raises an error if unrepresentable characters are encountered. |
|
2978 |
See also: asSingleByteStringIfPossible and asSingleByteStringReplaceInvalidWith:" |
|
2979 |
||
2980 |
^ String fromString:self |
|
2981 |
||
2982 |
" |
|
2983 |
#[60 61 62 63] asSingleByteString |
|
18616 | 2984 |
#[60 61 62 63] asExternalBytes asSingleByteString |
18969 | 2985 |
#[67 68 69 70] asIntegerArray asSingleByteString |
18600 | 2986 |
(Unicode16String with:(Character value:16rFF)) asSingleByteString |
2987 |
(Unicode16String with:(Character value:16rFFFF)) asSingleByteString |
|
2988 |
" |
|
2989 |
! |
|
2990 |
||
18969 | 2991 |
asSingleByteStringIfPossible |
2992 |
"if possible, return the receiver converted to a 'normal' string. |
|
2993 |
It is only possible, if there are no characters with codePoints above 255 in the receiver. |
|
2994 |
If not possible, the (wideString) receiver is returned." |
|
2995 |
||
2996 |
self containsNon8BitElements ifTrue:[^ self asString]. |
|
2997 |
^ self asSingleByteString. |
|
2998 |
||
2999 |
" |
|
3000 |
#[67 68 69 70] asSingleByteStringIfPossible |
|
3001 |
#[67 68 69 70] asIntegerArray asSingleByteStringIfPossible |
|
3002 |
'hello' asUnicodeString asSingleByteStringIfPossible |
|
3003 |
" |
|
3004 |
! |
|
3005 |
||
18616 | 3006 |
asString |
3007 |
"speed up string conversions" |
|
3008 |
||
3009 |
|size cls| |
|
3010 |
||
3011 |
cls := self class. |
|
3012 |
||
3013 |
(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
|
3014 |
size := self size. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3015 |
^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1. |
18616 | 3016 |
]. |
3017 |
^ super asString. |
|
3018 |
||
3019 |
" |
|
3020 |
#[16r41 16r42 16r43] asString |
|
3021 |
#[16r41 16r42 16r43] asExternalBytes asString |
|
3022 |
" |
|
3023 |
! |
|
3024 |
||
14132 | 3025 |
asUUID |
3026 |
^ UUID fromBytes:self |
|
12951 | 3027 |
! ! |
3028 |
||
18616 | 3029 |
!UninterpretedBytes methodsFor:'encoding & decoding'! |
3030 |
||
3031 |
utf8Decoded |
|
3032 |
"Interpreting myself as an UTF-8 representation, decode and return the decoded string." |
|
3033 |
||
3034 |
^ CharacterArray decodeFromUTF8:self. |
|
3035 |
||
3036 |
" |
|
3037 |
#[16rC8 16rA0] utf8Decoded |
|
3038 |
#[16rC8 16rA0] asString utf8Decoded |
|
3039 |
#[16rC8 16rA0] asExternalBytes utf8Decoded |
|
3040 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
3041 |
||
3042 |
(Character value:16r800) utf8Encoded |
|
3043 |
(Character value:16r220) utf8Encoded utf8Decoded |
|
3044 |
" |
|
3045 |
||
3046 |
"test: |
|
3047 |
||
3048 |
|utf8Encoding original readBack| |
|
3049 |
||
3050 |
1 to:16rFFFF do:[:ascii | |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3051 |
original := (Character value:ascii) asString. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3052 |
utf8Encoding := original utf8Encoded. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3053 |
readBack := utf8Encoding utf8Decoded. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3054 |
readBack = original ifFalse:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3055 |
self halt |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3056 |
] |
18616 | 3057 |
] |
3058 |
" |
|
3059 |
! |
|
3060 |
||
3061 |
utf8DecodedWithTwoByteCharactersReplacedBy:replacementCharacter |
|
3062 |
"Interpreting myself as an UTF-8 representation, decode and return |
|
3063 |
the decoded string. Suppress all 2-byte (above 16rFF) characters, |
|
3064 |
and replace them with replacementCharacter" |
|
3065 |
||
3066 |
|in out c| |
|
3067 |
||
3068 |
self containsNon7BitAscii ifFalse:[ |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3069 |
^ self asSingleByteString |
18616 | 3070 |
]. |
3071 |
||
3072 |
out := WriteStream on:(String uninitializedNew:self size * 3 // 2). |
|
3073 |
in := self readStream. |
|
3074 |
[in atEnd] whileFalse:[ |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3075 |
c := Character utf8DecodeFrom:in. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3076 |
c codePoint > 16rFF ifTrue:[ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3077 |
c := replacementCharacter |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3078 |
]. |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3079 |
out nextPut:c. |
18616 | 3080 |
]. |
3081 |
^ out contents |
|
3082 |
||
3083 |
" |
|
3084 |
(Character value:16r220) utf8Encoded |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3085 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
18616 | 3086 |
|
3087 |
(Character value:16r220) utf8Encoded asExternalBytes copyButLast |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3088 |
utf8DecodedWithTwoByteCharactersReplacedBy:(Character space) |
18616 | 3089 |
" |
3090 |
! ! |
|
3091 |
||
4782 | 3092 |
!UninterpretedBytes methodsFor:'filling & replacing'! |
3093 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3094 |
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
|
3095 |
"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
|
3096 |
like collection. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3097 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3098 |
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
|
3099 |
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
|
3100 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3101 |
%{ /* NOCONTEXT */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3102 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3103 |
int nIndex, repNIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3104 |
int startIndex, stopIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3105 |
REGISTER unsigned char *src; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3106 |
REGISTER int repStartIndex; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3107 |
int repStopIndex, count; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3108 |
REGISTER unsigned char *dst; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3109 |
OBJ cls; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3110 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3111 |
#ifndef NO_PRIM_BYTEARR |
14082 | 3112 |
if ((__isBytes(aCollection) || __isExternalBytesLike(aCollection)) |
14142 | 3113 |
&& (__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
|
3114 |
&& __bothSmallInteger(start, stop) |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3115 |
&& __isSmallInteger(repStart)) { |
15004 | 3116 |
startIndex = __intVal(start) - 1; |
3117 |
if (startIndex >= 0) { |
|
3118 |
dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex; |
|
3119 |
nIndex = __byteArraySize(self); |
|
3120 |
||
3121 |
if ((cls = __qClass(self)) != @global(ByteArray)) { |
|
3122 |
int nInst; |
|
3123 |
||
3124 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
3125 |
dst += nInst; |
|
3126 |
nIndex -= nInst; |
|
3127 |
} |
|
3128 |
||
3129 |
stopIndex = __intVal(stop) - 1; |
|
3130 |
count = stopIndex - startIndex + 1; |
|
3131 |
if (count == 0) { |
|
3132 |
RETURN ( self ); |
|
3133 |
} |
|
3134 |
||
3135 |
if ((count > 0) && (stopIndex < nIndex)) { |
|
3136 |
repStartIndex = __intVal(repStart) - 1; |
|
3137 |
if (repStartIndex >= 0) { |
|
3138 |
if (__isExternalBytesLike(aCollection)) { |
|
3139 |
OBJ sz; |
|
3140 |
||
3141 |
src = __externalAddressVal(aCollection); |
|
3142 |
if (src == 0) goto fallBack; |
|
3143 |
||
3144 |
sz = __externalBytesSize(aCollection); |
|
3145 |
if (__isSmallInteger(sz)) { |
|
3146 |
repNIndex = __smallIntegerVal(sz); |
|
3147 |
} else { |
|
3148 |
repNIndex = repStopIndex+1; /* always enough */ |
|
3149 |
} |
|
3150 |
src = src + repStartIndex; |
|
3151 |
} else { |
|
3152 |
if (__isStringLike(aCollection)) { |
|
3153 |
repNIndex = __stringSize(aCollection); |
|
3154 |
} else { |
|
3155 |
repNIndex = __qSize(aCollection) - OHDR_SIZE; |
|
3156 |
} |
|
3157 |
src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex; |
|
3158 |
if ((cls = __qClass(aCollection)) != @global(ByteArray)) { |
|
3159 |
int nInst; |
|
3160 |
||
3161 |
nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
3162 |
src += nInst; |
|
3163 |
repNIndex -= nInst; |
|
3164 |
} |
|
3165 |
} |
|
3166 |
repStopIndex = repStartIndex + (stopIndex - startIndex); |
|
3167 |
if (repStopIndex < repNIndex) { |
|
3168 |
if (aCollection == self) { |
|
3169 |
/* take care of overlapping copy */ |
|
3170 |
if (src < dst) { |
|
3171 |
/* must do a reverse copy */ |
|
3172 |
src += count; |
|
3173 |
dst += count; |
|
3174 |
while (count-- > 0) { |
|
3175 |
*--dst = *--src; |
|
3176 |
} |
|
3177 |
RETURN ( self ); |
|
3178 |
} |
|
3179 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3180 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3181 |
# ifdef bcopy4 |
15004 | 3182 |
if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) { |
3183 |
int nW; |
|
3184 |
||
3185 |
/* copy unaligned part */ |
|
3186 |
while (count && ((unsigned INT)src & 3)) { |
|
3187 |
*dst++ = *src++; |
|
3188 |
count--; |
|
3189 |
} |
|
3190 |
||
3191 |
if (count > 0) { |
|
3192 |
/* copy aligned part */ |
|
3193 |
nW = count >> 2; |
|
3194 |
bcopy4(src, dst, nW); |
|
3195 |
if ((count = count & 3) != 0) { |
|
3196 |
/* copy any remaining part */ |
|
3197 |
src += (nW<<2); |
|
3198 |
dst += (nW<<2); |
|
3199 |
while (count--) { |
|
3200 |
*dst++ = *src++; |
|
3201 |
} |
|
3202 |
} |
|
3203 |
} |
|
3204 |
RETURN ( self ); |
|
3205 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3206 |
# else |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3207 |
# if __POINTER_SIZE__ == 8 |
15004 | 3208 |
if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) { |
3209 |
/* copy unaligned part */ |
|
3210 |
while (count && ((unsigned INT)src & 7)) { |
|
3211 |
*dst++ = *src++; |
|
3212 |
count--; |
|
3213 |
} |
|
3214 |
||
3215 |
/* copy aligned part */ |
|
3216 |
while (count >= 8) { |
|
3217 |
((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0]; |
|
3218 |
dst += 8; |
|
3219 |
src += 8; |
|
3220 |
count -= 8; |
|
3221 |
} |
|
3222 |
while (count--) { |
|
3223 |
*dst++ = *src++; |
|
3224 |
} |
|
3225 |
RETURN ( self ); |
|
3226 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3227 |
# endif /* 64bit */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3228 |
# endif /* bcopy4 */ |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3229 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3230 |
# ifdef FAST_MEMCPY |
15004 | 3231 |
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
|
3232 |
# else |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3233 |
# ifdef __UNROLL_LOOPS__ |
15004 | 3234 |
while (count >= 8) { |
3235 |
dst[0] = src[0]; dst[1] = src[1]; |
|
3236 |
dst[2] = src[2]; dst[3] = src[3]; |
|
3237 |
dst[4] = src[4]; dst[5] = src[5]; |
|
3238 |
dst[6] = src[6]; dst[7] = src[7]; |
|
3239 |
dst += 8; src += 8; |
|
3240 |
count -= 8; |
|
3241 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3242 |
# endif /* __UNROLL_LOOPS__ */ |
15004 | 3243 |
while (count-- > 0) { |
3244 |
*dst++ = *src++; |
|
3245 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3246 |
# endif |
15004 | 3247 |
RETURN ( self ); |
3248 |
} |
|
3249 |
} |
|
3250 |
} |
|
3251 |
} |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3252 |
} |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3253 |
fallBack: ; |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3254 |
#endif |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3255 |
%}. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3256 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3257 |
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
|
3258 |
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
|
3259 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3260 |
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
|
3261 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3262 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3263 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3264 |
copy |
3265 |
replaceFrom:1 to:8 |
|
3266 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3267 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3268 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3269 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3270 |
copy |
3271 |
replaceFrom:3 to:10 |
|
3272 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3273 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3274 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3275 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3276 |
copy |
3277 |
replaceFrom:3 to:4 |
|
3278 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3279 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3280 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3281 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3282 |
copy |
3283 |
replaceFrom:0 to:9 |
|
3284 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3285 |
startingAt:1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3286 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3287 |
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
15004 | 3288 |
copy |
3289 |
replaceFrom:1 to:10 |
|
3290 |
with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
3291 |
startingAt:0 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3292 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3293 |
! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3294 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3295 |
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
|
3296 |
"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
|
3297 |
byte-array-like. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3298 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3299 |
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
|
3300 |
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
|
3301 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3302 |
^ self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3303 |
replaceBytesFrom:startIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3304 |
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
|
3305 |
with:replacementCollection |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3306 |
startingAt:repStartIndex |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3307 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3308 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3309 |
args: startIndex : <integer> |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3310 |
replacementCollection : <collection of <bytes> > |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3311 |
repStartIndex : <integer> |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3312 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3313 |
returns: self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3314 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3315 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3316 |
"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
|
3317 |
"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
|
3318 |
! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3319 |
|
13902 | 3320 |
replaceBytesWith:replacementCollection |
3321 |
"replace elements from another collection, which must be byte-array-like. |
|
3322 |
Replace stops at whichever collection is smaller. |
|
3323 |
||
3324 |
Notice: This operation modifies the receiver, NOT a copy; |
|
3325 |
therefore the change may affect all others referencing the receiver." |
|
3326 |
||
3327 |
^ self |
|
15004 | 3328 |
replaceBytesFrom:1 |
3329 |
to:(replacementCollection size min:self size) |
|
3330 |
with:replacementCollection |
|
3331 |
startingAt:1 |
|
13902 | 3332 |
|
3333 |
" |
|
15004 | 3334 |
(ByteArray new:10) replaceBytesWith:'hello' |
3335 |
(ByteArray new:10) replaceBytesWith:'hello world bla bla bla' |
|
13902 | 3336 |
" |
3337 |
||
3338 |
"Created: / 09-01-2012 / 16:18:10 / cg" |
|
3339 |
! |
|
3340 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3341 |
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
|
3342 |
"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
|
3343 |
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
|
3344 |
Return the receiver. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3345 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3346 |
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
|
3347 |
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
|
3348 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
3349 |
self class isBytes ifTrue:[ |
15004 | 3350 |
((aCollection class == self class) |
3351 |
or:[aCollection isByteCollection]) ifTrue:[ |
|
3352 |
^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex |
|
3353 |
]. |
|
7252
82cd08881a2a
abstract replaceBytes fallback is required (lead to recursion)
Claus Gittinger <cg@exept.de>
parents:
7218
diff
changeset
|
3354 |
]. |
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3355 |
^ 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
|
3356 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3357 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3358 |
args: startIndex : <integer> |
15004 | 3359 |
stopIndex : <integer> |
3360 |
replacementCollection : <collection of <bytes> > |
|
3361 |
repStartIndex : <integer> |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3362 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3363 |
returns: self |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3364 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3365 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
3366 |
"Modified: / 08-05-2012 / 13:23:27 / cg" |
4782 | 3367 |
! ! |
3368 |
||
12757 | 3369 |
!UninterpretedBytes methodsFor:'hashing'! |
3370 |
||
3371 |
computeXorHashFrom:startIndex to:endIndex |
|
3372 |
"compute and answer the SmallInteger-Hash of the bytes |
|
3373 |
from startIndex to endIndex. |
|
3374 |
If endindex = 0 or endIndex > size, hash up the size. |
|
3375 |
||
3376 |
NOTE: startIndex and endIndex are only hints about what should be hashed. |
|
13575 | 3377 |
In fact, more bytes could be involved in hashing. |
3378 |
SO ARRAYS MUST BE EQUAL TO HASH TO THE SAME VALUE" |
|
12757 | 3379 |
|
3380 |
|w| |
|
3381 |
||
3382 |
%{ |
|
3383 |
if (__bothSmallInteger(startIndex, endIndex)) { |
|
13575 | 3384 |
unsigned char *cp; |
3385 |
INT sz; |
|
3386 |
||
3387 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
3388 |
if (cp) { |
|
3389 |
INT sidx = ((unsigned INT)__smallIntegerVal(startIndex)) - 1; |
|
3390 |
INT eidx = ((unsigned INT)__smallIntegerVal(endIndex)) - 1; |
|
3391 |
unsigned char *ep; |
|
3392 |
unsigned INT hash = 0, hash2 = 0, carry; |
|
3393 |
int i; |
|
3394 |
||
3395 |
if (eidx < 0 || eidx >= sz) eidx = sz - 1; |
|
3396 |
if (sidx > eidx) sidx = eidx; |
|
3397 |
if (sidx < 0) { |
|
3398 |
RETURN(__mkSmallInteger(0)); |
|
3399 |
} |
|
3400 |
||
3401 |
ep = cp + eidx; |
|
3402 |
cp += sidx; |
|
12757 | 3403 |
|
3404 |
#if 0 |
|
13575 | 3405 |
/* |
3406 |
* On LSB-First (little endian) cpus, |
|
3407 |
* this code does not produce the same result |
|
3408 |
* if the same bytes are at different positions |
|
3409 |
*/ |
|
3410 |
||
3411 |
if ((INT)cp & (sizeof(INT)-1)) { |
|
3412 |
/* not aligned */ |
|
3413 |
||
3414 |
for (i=0; cp <= ep; cp++) { |
|
3415 |
hash2 = (hash2 << 8) | *cp; |
|
3416 |
if (++i == sizeof(INT)) { |
|
3417 |
hash ^= hash2; |
|
3418 |
i = hash2 = 0; |
|
3419 |
} |
|
3420 |
} |
|
3421 |
} else { |
|
3422 |
/* aligned */ |
|
3423 |
for (; cp+sizeof(INT) <= ep; cp += sizeof(INT)) { |
|
3424 |
hash ^= *(unsigned INT *)cp; |
|
3425 |
} |
|
3426 |
for (; cp <= ep; cp++) { |
|
3427 |
hash2 = (hash2 << 8) | *cp; |
|
3428 |
} |
|
3429 |
} |
|
12757 | 3430 |
#else |
13575 | 3431 |
for (i=0; cp <= ep-sizeof(INT); cp += sizeof(INT)) { |
3432 |
hash2 = cp[0]; |
|
3433 |
hash2 = (hash2 << 8) | cp[1]; |
|
3434 |
hash2 = (hash2 << 8) | cp[2]; |
|
3435 |
hash2 = (hash2 << 8) | cp[3]; |
|
12757 | 3436 |
#if __POINTER_SIZE__ == 8 |
13575 | 3437 |
hash2 = (hash2 << 8) | cp[4]; |
3438 |
hash2 = (hash2 << 8) | cp[5]; |
|
3439 |
hash2 = (hash2 << 8) | cp[6]; |
|
3440 |
hash2 = (hash2 << 8) | cp[7]; |
|
12757 | 3441 |
#endif |
13575 | 3442 |
/* |
3443 |
* multiply by large prime to scramble bits and |
|
3444 |
* to avoid a 0 result from |
|
3445 |
* #[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8. |
|
3446 |
*/ |
|
3447 |
hash ^= (hash * 31415821) ^ hash2; |
|
3448 |
} |
|
3449 |
for (hash2 = 0; cp <= ep; cp++) { |
|
3450 |
hash2 = (hash2 << 8) | *cp; |
|
3451 |
} |
|
12757 | 3452 |
#endif |
13575 | 3453 |
hash ^= (hash * 31415821) ^ hash2; |
3454 |
||
3455 |
/* |
|
3456 |
* fold the high bits not fitting into a SmallInteger |
|
3457 |
*/ |
|
3458 |
carry = hash & ~_MAX_INT; |
|
3459 |
if (carry) { |
|
3460 |
hash = (hash & _MAX_INT) ^ (carry >> 8); |
|
3461 |
} |
|
3462 |
||
3463 |
RETURN(__mkSmallInteger(hash)); |
|
3464 |
} |
|
12757 | 3465 |
} |
3466 |
%}. |
|
3467 |
||
3468 |
^ self primitiveFailed |
|
3469 |
||
3470 |
" |
|
3471 |
#[1 2 3 4] computeXorHashFrom:1 to:4. |
|
3472 |
#[1 2 3 4] computeXorHashFrom:1 to:32. |
|
3473 |
#[1 2 3 4] computeXorHashFrom:1 to:0. |
|
3474 |
#[1 2 3 4 5] computeXorHashFrom:1 to:4. |
|
3475 |
#[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8. |
|
3476 |
#[1 2 3 4 5 6 7 8] computeXorHashFrom:2 to:8. |
|
3477 |
#[2 3 4 5 6 7 8] computeXorHashFrom:1 to:7. |
|
3478 |
" |
|
3479 |
! ! |
|
3480 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3481 |
!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
|
3482 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3483 |
copyReverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3484 |
"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
|
3485 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3486 |
^ self copy reverse |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3487 |
|
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3488 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3489 |
#[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
|
3490 |
#[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
|
3491 |
" |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3492 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3493 |
|
14131
3b0cb7751a71
changed: #replaceFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14082
diff
changeset
|
3494 |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3495 |
!UninterpretedBytes methodsFor:'misc'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3496 |
|
13575 | 3497 |
swapLongAt:byteIndex |
3433 | 3498 |
"swap the byteOrder of a long. |
3499 |
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
|
3500 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3501 |
|t| |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3502 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3503 |
t := self byteAt:byteIndex. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3504 |
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
|
3505 |
self byteAt:(byteIndex + 3) put:t. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3506 |
t := self byteAt:(byteIndex + 1). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3507 |
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
|
3508 |
self byteAt:(byteIndex + 2) put:t |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3509 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3510 |
"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
|
3511 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
3512 |
|
18664 | 3513 |
!UninterpretedBytes methodsFor:'printing & storing'! |
3514 |
||
3515 |
hexPrintOn:aStream |
|
3516 |
"print as hex string, eg: 'FF0243'. |
|
3517 |
This string can be used in #fromHexString: to recreate the byteArray" |
|
3518 |
||
3519 |
self hexPrintOn:aStream withSeparator:nil |
|
3520 |
||
3521 |
" |
|
3522 |
#[1 2 3 4 10 17] hexPrintOn:Transcript |
|
3523 |
" |
|
3524 |
||
3525 |
" |
|
3526 |
|s| |
|
3527 |
s := String streamContents:[:s | #[1 2 3 4 10 17] hexPrintOn:s]. |
|
3528 |
ByteArray fromHexString:s |
|
3529 |
" |
|
3530 |
! |
|
3531 |
||
3532 |
hexPrintOn:aStream withSeparator:aSeparatorStringOrCharacterOrNil |
|
3533 |
"print as hex string with separators, eg: 'FF:02:43'" |
|
3534 |
||
3535 |
|first| |
|
3536 |
||
3537 |
first := true. |
|
3538 |
1 to:self size do:[:idx | |
|
18666 | 3539 |
aSeparatorStringOrCharacterOrNil notNil ifTrue:[ |
3540 |
first ifFalse:[ |
|
3541 |
aSeparatorStringOrCharacterOrNil printOn:aStream |
|
3542 |
] ifTrue:[ |
|
3543 |
first := false. |
|
3544 |
]. |
|
3545 |
]. |
|
3546 |
(self byteAt:idx) printOn:aStream base:16 size:2 fill:$0. |
|
18664 | 3547 |
]. |
3548 |
||
3549 |
" |
|
3550 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:$: |
|
3551 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:(Character space) |
|
3552 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:'-' |
|
3553 |
#[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:nil |
|
3554 |
" |
|
3555 |
! |
|
3556 |
||
3557 |
hexPrintString |
|
3558 |
"print as hex string, eg: 'FF0243'. |
|
3559 |
This string can be used in #fromHexString: to recreate the byteArray" |
|
3560 |
||
3561 |
^ self hexPrintStringWithSeparator:nil |
|
3562 |
||
3563 |
" |
|
3564 |
#[1 2 3 4 10 17] hexPrintString |
|
3565 |
ByteArray fromHexString:#[1 2 3 4 10 17] hexPrintString |
|
3566 |
" |
|
3567 |
||
3568 |
"Modified: / 03-07-2010 / 01:59:19 / cg" |
|
3569 |
! |
|
3570 |
||
3571 |
hexPrintStringWithSeparator:aSeparatorStringOrCharacterOrNil |
|
3572 |
"print as hex string, eg: 'FF:02:43'." |
|
3573 |
||
3574 |
^ String |
|
18666 | 3575 |
streamContents:[:s | |
3576 |
self hexPrintOn:s withSeparator:aSeparatorStringOrCharacterOrNil. |
|
3577 |
] |
|
18664 | 3578 |
|
3579 |
" |
|
3580 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:$: |
|
3581 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:Character space |
|
3582 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:' - ' |
|
3583 |
#[1 2 3 4 10 17] hexPrintStringWithSeparator:nil |
|
3584 |
" |
|
3585 |
! ! |
|
3586 |
||
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3587 |
!UninterpretedBytes methodsFor:'private'! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3588 |
|
18969 | 3589 |
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
|
3590 |
"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
|
3591 |
|
18969 | 3592 |
|srcIdx "{ Class:SmallInteger }" |
3593 |
start "{ Class:SmallInteger }" |
|
3594 |
stop "{ Class:SmallInteger }"| |
|
3595 |
||
3596 |
start := startArg. |
|
3597 |
stop := stopArg. |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3598 |
srcIdx := sourceIndex. |
18969 | 3599 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3600 |
start to:stop do:[:dstIdx | |
18969 | 3601 |
self at:dstIdx put:(sourceBytes at:srcIdx). |
3602 |
srcIdx := srcIdx + 1 |
|
12769
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3603 |
]. |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3604 |
! ! |
435668a20ddd
Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
12757
diff
changeset
|
3605 |
|
3323 | 3606 |
!UninterpretedBytes methodsFor:'queries'! |
3607 |
||
18616 | 3608 |
containsNon7BitAscii |
18969 | 3609 |
"return true, if the underlying collection contains elements longer than 7 bits |
18616 | 3610 |
(i.e. if it is non-ascii)" |
3611 |
||
3612 |
|sz "{ Class:SmallInteger }"| |
|
3613 |
||
3614 |
sz := self size. |
|
3615 |
1 to:sz do:[:idx| |
|
18969 | 3616 |
(self at:idx) > 16r7F ifTrue:[ |
3617 |
^ true. |
|
3618 |
]. |
|
3619 |
]. |
|
3620 |
^ false. |
|
3621 |
! |
|
3622 |
||
3623 |
containsNon8BitElements |
|
3624 |
"return true, if the underlying structure contains elements larger than a single byte" |
|
3625 |
||
3626 |
|sz "{ Class:SmallInteger }"| |
|
3627 |
||
3628 |
sz := self size. |
|
3629 |
1 to:sz do:[:idx| |
|
3630 |
(self at:idx) > 16rFF ifTrue:[ |
|
3631 |
^ true. |
|
3632 |
]. |
|
18616 | 3633 |
]. |
3634 |
^ false. |
|
3635 |
! |
|
3636 |
||
7218
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
3637 |
defaultElement |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
3638 |
^ 0 |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
3639 |
! |
b798be6d632f
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
7197
diff
changeset
|
3640 |
|
18616 | 3641 |
referencesAny:aCollection |
3642 |
"redefined to speed up searching when many of my instances are present" |
|
3643 |
||
3644 |
%{ /* NOCONTEXT */ |
|
3645 |
if (__mkSmallInteger(0) == __ClassInstPtr(__qClass(self))->c_ninstvars) { |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3646 |
/* I am only bytes */ |
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3647 |
RETURN(false) |
18616 | 3648 |
} |
3649 |
%}. |
|
3650 |
^ super referencesAny:aCollection |
|
3651 |
||
3652 |
" |
|
18649
e9d831015328
fix: signedLongIntVal returns an INT
Claus Gittinger <cg@exept.de>
parents:
18633
diff
changeset
|
3653 |
'abc' referencesAny:#() |
18616 | 3654 |
" |
3655 |
! |
|
3656 |
||
3323 | 3657 |
sizeInBytes |
3658 |
"return the number of 8-bit bytes in the receiver. |
|
3659 |
This is needed since subclasse may redefine #size (TwoByteString)" |
|
3660 |
||
3661 |
^ super size |
|
3662 |
||
3663 |
"Created: / 5.3.1998 / 10:41:13 / stefan" |
|
3664 |
! ! |
|
3665 |
||
8986 | 3666 |
!UninterpretedBytes methodsFor:'testing'! |
3667 |
||
3668 |
isByteCollection |
|
3669 |
"return true, if the receiver has access methods for bytes; |
|
3670 |
true is returned here - the method is redefined from Object." |
|
3671 |
||
3672 |
^ true |
|
9005 | 3673 |
! |
3674 |
||
3675 |
isNonByteCollection |
|
3676 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
3677 |
false is returned here - the method is redefined from Collection." |
|
3678 |
||
3679 |
^ false |
|
8986 | 3680 |
! ! |
3681 |
||
11009
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
3682 |
!UninterpretedBytes methodsFor:'visiting'! |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
3683 |
|
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
3684 |
acceptVisitor:aVisitor with:aParameter |
16719 | 3685 |
"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
|
3686 |
|
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
3687 |
^ aVisitor visitByteArray:self with:aParameter |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
3688 |
! ! |
fb66915c5bb5
changed #acceptVisitor:with: - moved to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents:
10676
diff
changeset
|
3689 |
|
695 | 3690 |
!UninterpretedBytes class methodsFor:'documentation'! |
3691 |
||
3692 |
version |
|
18600 | 3693 |
^ '$Header$' |
12253
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
3694 |
! |
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
3695 |
|
c933c6fcdeef
changed: #fromHexStringWithSeparators:
Claus Gittinger <cg@exept.de>
parents:
11973
diff
changeset
|
3696 |
version_CVS |
18600 | 3697 |
^ '$Header$' |
695 | 3698 |
! ! |
15087 | 3699 |
|
18284 | 3700 |
|
3701 |
UninterpretedBytes initialize! |