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