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