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