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