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