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