Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: sdk/lib/typeddata/typeddata.dart

Issue 14426006: Rename dart:typeddata to dart:typed_data. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library dart.typeddata;
6
7 import 'dart:collection';
8 import 'dart:_collection-dev';
9
10 /**
11 * A sequence of bytes underlying a typed data object.
12 * Used to process large quantities of binary or numerical data
13 * more efficiently using a typed view.
14 */
15 abstract class ByteBuffer {
16 /**
17 * Returns the length of this byte buffer, in bytes.
18 */
19 int get lengthInBytes;
20
21 }
22
23
24 /**
25 * A typed view of a sequence of bytes.
26 */
27 abstract class TypedData {
28 /**
29 * Returns the number of bytes in the representation of each element in this
30 * list.
31 */
32 int get elementSizeInBytes;
33
34 /**
35 * Returns the offset in bytes into the underlying byte buffer of this view.
36 */
37 int get offsetInBytes;
38
39 /**
40 * Returns the length of this view, in bytes.
41 */
42 int get lengthInBytes;
43
44 /**
45 * Returns the byte buffer associated with this object.
46 */
47 ByteBuffer get buffer;
48 }
49
50
51 /**
52 * Describes endianness to be used when accessing or updating a
53 * sequence of bytes.
54 */
55 class Endianness {
56 const Endianness._(this._littleEndian);
57
58 static const Endianness BIG_ENDIAN = const Endianness._(false);
59 static const Endianness LITTLE_ENDIAN = const Endianness._(true);
60 static final Endianness HOST_ENDIAN =
61 (new ByteData.view(new Uint16List.fromList([1]).buffer)).getInt8(0) == 1 ?
62 LITTLE_ENDIAN : BIG_ENDIAN;
63
64 final bool _littleEndian;
65 }
66
67
68 /**
69 * A fixed-length, random-access sequence of bytes that also provides random
70 * and unaligned access to the fixed-width integers and floating point
71 * numbers represented by those bytes.
72 * ByteData may be used to pack and unpack data from external sources
73 * (such as networks or files systems), and to process large quantities
74 * of numerical data more efficiently than would be possible
75 * with ordinary [List] implementations. ByteData can save space, by
76 * eliminating the need for object headers, and time, by eliminating the
77 * need for data copies. Finally, ByteData may be used to intentionally
78 * reinterpret the bytes representing one arithmetic type as another.
79 * For example this code fragment determine what 32-bit signed integer
80 * is represented by the bytes of a 32-bit floating point number:
81 *
82 * var buffer = new Uint8List(8).buffer;
83 * var bdata = new ByteData.view(buffer);
84 * bdata.setFloat32(0, 3.04);
85 * int huh = bdata.getInt32(0);
86 */
87 abstract class ByteData implements TypedData {
88 /**
89 * Creates a [ByteData] of the specified length (in elements), all of
90 * whose elements are initially zero.
91 */
92 external factory ByteData(int length);
93
94 /**
95 * Creates an [ByteData] _view_ of the specified region in the specified
96 * byte buffer. Changes in the [ByteData] will be visible in the byte
97 * buffer and vice versa. If the [offsetInBytes] index of the region is not
98 * specified, it defaults to zero (the first byte in the byte buffer).
99 * If the length is not specified, it defaults to null, which indicates
100 * that the view extends to the end of the byte buffer.
101 *
102 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
103 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
104 * the length of [buffer].
105 */
106 external factory ByteData.view(ByteBuffer buffer,
107 [int offsetInBytes = 0, int length]);
108
109 /**
110 * Returns the (possibly negative) integer represented by the byte at the
111 * specified [byteOffset] in this object, in two's complement binary
112 * representation. The return value will be between -128 and 127, inclusive.
113 *
114 * Throws [RangeError] if [byteOffset] is negative, or
115 * greater than or equal to the length of this object.
116 */
117 int getInt8(int byteOffset);
118
119 /**
120 * Sets the byte at the specified [byteOffset] in this object to the
121 * two's complement binary representation of the specified [value], which
122 * must fit in a single byte. In other words, [value] must be between
123 * -128 and 127, inclusive.
124 *
125 * Throws [RangeError] if [byteOffset] is negative, or
126 * greater than or equal to the length of this object.
127 */
128 void setInt8(int byteOffset, int value);
129
130 /**
131 * Returns the positive integer represented by the byte at the specified
132 * [byteOffset] in this object, in unsigned binary form. The
133 * return value will be between 0 and 255, inclusive.
134 *
135 * Throws [RangeError] if [byteOffset] is negative, or
136 * greater than or equal to the length of this object.
137 */
138 int getUint8(int byteOffset);
139
140 /**
141 * Sets the byte at the specified [byteOffset] in this object to the
142 * unsigned binary representation of the specified [value], which must fit
143 * in a single byte. in other words, [value] must be between 0 and 255,
144 * inclusive.
145 *
146 * Throws [RangeError] if [byteOffset] is negative,
147 * or greater than or equal to the length of this object.
148 */
149 void setUint8(int byteOffset, int value);
150
151 /**
152 * Returns the (possibly negative) integer represented by the two bytes at
153 * the specified [byteOffset] in this object, in two's complement binary
154 * form.
155 * The return value will be between 2<sup>15</sup> and 2<sup>15</sup> - 1,
156 * inclusive.
157 *
158 * Throws [RangeError] if [byteOffset] is negative, or
159 * `byteOffset + 2` is greater than the length of this object.
160 */
161 int getInt16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
162
163 /**
164 * Sets the two bytes starting at the specified [byteOffset] in this
165 * object to the two's complement binary representation of the specified
166 * [value], which must fit in two bytes. In other words, [value] must lie
167 * between 2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive.
168 *
169 * Throws [RangeError] if [byteOffset] is negative, or
170 * `byteOffset + 2` is greater than the length of this object.
171 */
172 void setInt16(int byteOffset,
173 int value,
174 [Endianness endian = Endianness.BIG_ENDIAN]);
175
176 /**
177 * Returns the positive integer represented by the two bytes starting
178 * at the specified [byteOffset] in this object, in unsigned binary
179 * form.
180 * The return value will be between 0 and 2<sup>16</sup> - 1, inclusive.
181 *
182 * Throws [RangeError] if [byteOffset] is negative, or
183 * `byteOffset + 2` is greater than the length of this object.
184 */
185 int getUint16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
186
187 /**
188 * Sets the two bytes starting at the specified [byteOffset] in this object
189 * to the unsigned binary representation of the specified [value],
190 * which must fit in two bytes. in other words, [value] must be between
191 * 0 and 2<sup>16</sup> - 1, inclusive.
192 *
193 * Throws [RangeError] if [byteOffset] is negative, or
194 * `byteOffset + 2` is greater than the length of this object.
195 */
196 void setUint16(int byteOffset,
197 int value,
198 [Endianness endian = Endianness.BIG_ENDIAN]);
199
200 /**
201 * Returns the (possibly negative) integer represented by the four bytes at
202 * the specified [byteOffset] in this object, in two's complement binary
203 * form.
204 * The return value will be between 2<sup>31</sup> and 2<sup>31</sup> - 1,
205 * inclusive.
206 *
207 * Throws [RangeError] if [byteOffset] is negative, or
208 * `byteOffset + 4` is greater than the length of this object.
209 */
210 int getInt32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
211
212 /**
213 * Sets the four bytes starting at the specified [byteOffset] in this
214 * object to the two's complement binary representation of the specified
215 * [value], which must fit in four bytes. In other words, [value] must lie
216 * between 2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive.
217 *
218 * Throws [RangeError] if [byteOffset] is negative, or
219 * `byteOffset + 4` is greater than the length of this object.
220 */
221 void setInt32(int byteOffset,
222 int value,
223 [Endianness endian = Endianness.BIG_ENDIAN]);
224
225 /**
226 * Returns the positive integer represented by the four bytes starting
227 * at the specified [byteOffset] in this object, in unsigned binary
228 * form.
229 * The return value will be between 0 and 2<sup>32</sup> - 1, inclusive.
230 *
231 */
232 int getUint32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
233
234 /**
235 * Sets the four bytes starting at the specified [byteOffset] in this object
236 * to the unsigned binary representation of the specified [value],
237 * which must fit in four bytes. in other words, [value] must be between
238 * 0 and 2<sup>32</sup> - 1, inclusive.
239 *
240 * Throws [RangeError] if [byteOffset] is negative, or
241 * `byteOffset + 4` is greater than the length of this object.
242 */
243 void setUint32(int byteOffset,
244 int value,
245 [Endianness endian = Endianness.BIG_ENDIAN]);
246
247 /**
248 * Returns the (possibly negative) integer represented by the eight bytes at
249 * the specified [byteOffset] in this object, in two's complement binary
250 * form.
251 * The return value will be between 2<sup>63</sup> and 2<sup>63</sup> - 1,
252 * inclusive.
253 *
254 * Throws [RangeError] if [byteOffset] is negative, or
255 * `byteOffset + 8` is greater than the length of this object.
256 */
257 int getInt64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
258
259 /**
260 * Sets the eight bytes starting at the specified [byteOffset] in this
261 * object to the two's complement binary representation of the specified
262 * [value], which must fit in eight bytes. In other words, [value] must lie
263 * between 2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive.
264 *
265 * Throws [RangeError] if [byteOffset] is negative, or
266 * `byteOffset + 8` is greater than the length of this object.
267 */
268 void setInt64(int byteOffset,
269 int value,
270 [Endianness endian = Endianness.BIG_ENDIAN]);
271
272 /**
273 * Returns the positive integer represented by the eight bytes starting
274 * at the specified [byteOffset] in this object, in unsigned binary
275 * form.
276 * The return value will be between 0 and 2<sup>64</sup> - 1, inclusive.
277 *
278 * Throws [RangeError] if [byteOffset] is negative, or
279 * `byteOffset + 8` is greater than the length of this object.
280 */
281 int getUint64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]);
282
283 /**
284 * Sets the eight bytes starting at the specified [byteOffset] in this object
285 * to the unsigned binary representation of the specified [value],
286 * which must fit in eight bytes. in other words, [value] must be between
287 * 0 and 2<sup>64</sup> - 1, inclusive.
288 *
289 * Throws [RangeError] if [byteOffset] is negative, or
290 * `byteOffset + 8` is greater than the length of this object.
291 */
292 void setUint64(int byteOffset,
293 int value,
294 [Endianness endian = Endianness.BIG_ENDIAN]);
295
296 /**
297 * Returns the floating point number represented by the four bytes at
298 * the specified [byteOffset] in this object, in IEEE 754
299 * single-precision binary floating-point format (binary32).
300 *
301 * Throws [RangeError] if [byteOffset] is negative, or
302 * `byteOffset + 4` is greater than the length of this object.
303 */
304 double getFloat32(int byteOffset,
305 [Endianness endian = Endianness.BIG_ENDIAN]);
306
307 /**
308 * Sets the four bytes starting at the specified [byteOffset] in this
309 * object to the IEEE 754 single-precision binary floating-point
310 * (binary32) representation of the specified [value].
311 *
312 * **Note that this method can lose precision.** The input [value] is
313 * a 64-bit floating point value, which will be converted to 32-bit
314 * floating point value by IEEE 754 rounding rules before it is stored.
315 * If [value] cannot be represented exactly as a binary32, it will be
316 * converted to the nearest binary32 value. If two binary32 values are
317 * equally close, the one whose least significant bit is zero will be used.
318 * Note that finite (but large) values can be converted to infinity, and
319 * small non-zero values can be converted to zero.
320 *
321 * Throws [RangeError] if [byteOffset] is negative, or
322 * `byteOffset + 4` is greater than the length of this object.
323 */
324 void setFloat32(int byteOffset,
325 double value,
326 [Endianness endian = Endianness.BIG_ENDIAN]);
327
328 /**
329 * Returns the floating point number represented by the eight bytes at
330 * the specified [byteOffset] in this object, in IEEE 754
331 * double-precision binary floating-point format (binary64).
332 *
333 * Throws [RangeError] if [byteOffset] is negative, or
334 * `byteOffset + 8` is greater than the length of this object.
335 */
336 double getFloat64(int byteOffset,
337 [Endianness endian = Endianness.BIG_ENDIAN]);
338
339 /**
340 * Sets the eight bytes starting at the specified [byteOffset] in this
341 * object to the IEEE 754 double-precision binary floating-point
342 * (binary64) representation of the specified [value].
343 *
344 * Throws [RangeError] if [byteOffset] is negative, or
345 * `byteOffset + 8` is greater than the length of this object.
346 */
347 void setFloat64(int byteOffset,
348 double value,
349 [Endianness endian = Endianness.BIG_ENDIAN]);
350 }
351
352
353 /**
354 * A fixed-length list of 8-bit signed integers.
355 * For long lists, this implementation can be considerably
356 * more space- and time-efficient than the default [List] implementation.
357 */
358 abstract class Int8List implements List<int>, TypedData {
359 /**
360 * Creates an [Int8List] of the specified length (in elements), all of
361 * whose elements are initially zero.
362 */
363 external factory Int8List(int length);
364
365 /**
366 * Creates a [Int8List] with the same size as the [elements] list
367 * and copies over the elements.
368 */
369 external factory Int8List.fromList(List<int> elements);
370
371 /**
372 * Creates an [Int8List] _view_ of the specified region in the specified
373 * byte buffer. Changes in the [Int8List] will be visible in the byte
374 * buffer and vice versa. If the [offsetInBytes] index of the region is not
375 * specified, it defaults to zero (the first byte in the byte buffer).
376 * If the length is not specified, it defaults to null, which indicates
377 * that the view extends to the end of the byte buffer.
378 *
379 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
380 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
381 * the length of [buffer].
382 */
383 external factory Int8List.view(ByteBuffer buffer,
384 [int offsetInBytes = 0, int length]);
385
386 static const int BYTES_PER_ELEMENT = 1;
387 }
388
389
390 /**
391 * A fixed-length list of 8-bit unsigned integers.
392 * For long lists, this implementation can be considerably
393 * more space- and time-efficient than the default [List] implementation.
394 */
395 abstract class Uint8List implements List<int>, TypedData {
396 /**
397 * Creates a [Uint8List] of the specified length (in elements), all of
398 * whose elements are initially zero.
399 */
400 external factory Uint8List(int length);
401
402 /**
403 * Creates a [Uint8List] with the same size as the [elements] list
404 * and copies over the elements.
405 */
406 external factory Uint8List.fromList(List<int> elements);
407
408 /**
409 * Creates a [Uint8List] _view_ of the specified region in the specified
410 * byte buffer. Changes in the [Uint8List] will be visible in the byte
411 * buffer and vice versa. If the [offsetInBytes] index of the region is not
412 * specified, it defaults to zero (the first byte in the byte buffer).
413 * If the length is not specified, it defaults to null, which indicates
414 * that the view extends to the end of the byte buffer.
415 *
416 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
417 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
418 * the length of [buffer].
419 */
420 external factory Uint8List.view(ByteBuffer buffer,
421 [int offsetInBytes = 0, int length]);
422
423 static const int BYTES_PER_ELEMENT = 1;
424 }
425
426
427 /**
428 * A fixed-length list of 8-bit unsigned integers.
429 * For long lists, this implementation can be considerably
430 * more space- and time-efficient than the default [List] implementation.
431 * Indexed store clamps the value to range 0..0xFF.
432 */
433 abstract class Uint8ClampedList implements List<int>, TypedData {
434 /**
435 * Creates a [Uint8ClampedList] of the specified length (in elements), all of
436 * whose elements are initially zero.
437 */
438 external factory Uint8ClampedList(int length);
439
440 /**
441 * Creates a [Uint8ClampedList] of the same size as the [elements]
442 * list and copies over the values clamping when needed.
443 */
444 external factory Uint8ClampedList.fromList(List<int> elements);
445
446 /**
447 * Creates a [Uint8ClampedList] _view_ of the specified region in the
448 * specified byte [buffer]. Changes in the [Uint8List] will be visible in the
449 * byte buffer and vice versa. If the [offsetInBytes] index of the region is
450 * not specified, it defaults to zero (the first byte in the byte buffer).
451 * If the length is not specified, it defaults to null, which indicates that
452 * the view extends to the end of the byte buffer.
453 *
454 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
455 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
456 * the length of [buffer].
457 */
458 external factory Uint8ClampedList.view(ByteBuffer buffer,
459 [int offsetInBytes = 0, int length]);
460
461 static const int BYTES_PER_ELEMENT = 1;
462 }
463
464
465 /**
466 * A fixed-length list of 16-bit signed integers that is viewable as a
467 * [TypedData]. For long lists, this implementation can be considerably
468 * more space- and time-efficient than the default [List] implementation.
469 */
470 abstract class Int16List implements List<int>, TypedData {
471 /**
472 * Creates an [Int16List] of the specified length (in elements), all of
473 * whose elements are initially zero.
474 */
475 external factory Int16List(int length);
476
477 /**
478 * Creates a [Int16List] with the same size as the [elements] list
479 * and copies over the elements.
480 */
481 external factory Int16List.fromList(List<int> elements);
482
483 /**
484 * Creates an [Int16List] _view_ of the specified region in the specified
485 * byte buffer. Changes in the [Int16List] will be visible in the byte
486 * buffer and vice versa. If the [offsetInBytes] index of the region is not
487 * specified, it defaults to zero (the first byte in the byte buffer).
488 * If the length is not specified, it defaults to null, which indicates
489 * that the view extends to the end of the byte buffer.
490 *
491 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
492 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
493 * the length of [buffer].
494 *
495 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
496 * BYTES_PER_ELEMENT.
497 */
498 external factory Int16List.view(ByteBuffer buffer,
499 [int offsetInBytes = 0, int length]);
500
501 static const int BYTES_PER_ELEMENT = 2;
502 }
503
504
505 /**
506 * A fixed-length list of 16-bit unsigned integers that is viewable as a
507 * [TypedData]. For long lists, this implementation can be considerably
508 * more space- and time-efficient than the default [List] implementation.
509 */
510 abstract class Uint16List implements List<int>, TypedData {
511 /**
512 * Creates a [Uint16List] of the specified length (in elements), all
513 * of whose elements are initially zero.
514 */
515 external factory Uint16List(int length);
516
517 /**
518 * Creates a [Uint16List] with the same size as the [elements] list
519 * and copies over the elements.
520 */
521 external factory Uint16List.fromList(List<int> elements);
522
523 /**
524 * Creates a [Uint16List] _view_ of the specified region in
525 * the specified byte buffer. Changes in the [Uint16List] will be
526 * visible in the byte buffer and vice versa. If the [offsetInBytes] index
527 * of the region is not specified, it defaults to zero (the first byte in
528 * the byte buffer). If the length is not specified, it defaults to null,
529 * which indicates that the view extends to the end of the byte buffer.
530 *
531 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
532 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
533 * the length of [buffer].
534 *
535 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
536 * BYTES_PER_ELEMENT.
537 */
538 external factory Uint16List.view(ByteBuffer buffer,
539 [int offsetInBytes = 0, int length]);
540
541 static const int BYTES_PER_ELEMENT = 2;
542 }
543
544
545 /**
546 * A fixed-length list of 32-bit signed integers that is viewable as a
547 * [TypedData]. For long lists, this implementation can be considerably
548 * more space- and time-efficient than the default [List] implementation.
549 */
550 abstract class Int32List implements List<int>, TypedData {
551 /**
552 * Creates an [Int32List] of the specified length (in elements), all of
553 * whose elements are initially zero.
554 */
555 external factory Int32List(int length);
556
557 /**
558 * Creates a [Int32List] with the same size as the [elements] list
559 * and copies over the elements.
560 */
561 external factory Int32List.fromList(List<int> elements);
562
563 /**
564 * Creates an [Int32List] _view_ of the specified region in the specified
565 * byte buffer. Changes in the [Int32List] will be visible in the byte
566 * buffer and vice versa. If the [offsetInBytes] index of the region is not
567 * specified, it defaults to zero (the first byte in the byte buffer).
568 * If the length is not specified, it defaults to null, which indicates
569 * that the view extends to the end of the byte buffer.
570 *
571 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
572 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
573 * the length of [buffer].
574 *
575 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
576 * BYTES_PER_ELEMENT.
577 */
578 external factory Int32List.view(ByteBuffer buffer,
579 [int offsetInBytes = 0, int length]);
580
581 static const int BYTES_PER_ELEMENT = 4;
582 }
583
584
585 /**
586 * A fixed-length list of 32-bit unsigned integers that is viewable as a
587 * [TypedData]. For long lists, this implementation can be considerably
588 * more space- and time-efficient than the default [List] implementation.
589 */
590 abstract class Uint32List implements List<int>, TypedData {
591 /**
592 * Creates a [Uint32List] of the specified length (in elements), all
593 * of whose elements are initially zero.
594 */
595 external factory Uint32List(int length);
596
597 /**
598 * Creates a [Uint32List] with the same size as the [elements] list
599 * and copies over the elements.
600 */
601 external factory Uint32List.fromList(List<int> elements);
602
603 /**
604 * Creates a [Uint32List] _view_ of the specified region in
605 * the specified byte buffer. Changes in the [Uint32] will be
606 * visible in the byte buffer and vice versa. If the [offsetInBytes] index
607 * of the region is not specified, it defaults to zero (the first byte in
608 * the byte buffer). If the length is not specified, it defaults to null,
609 * which indicates that the view extends to the end of the byte buffer.
610 *
611 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
612 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
613 * the length of [buffer].
614 *
615 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
616 * BYTES_PER_ELEMENT.
617 */
618 external factory Uint32List.view(ByteBuffer buffer,
619 [int offsetInBytes = 0, int length]);
620
621 static const int BYTES_PER_ELEMENT = 4;
622 }
623
624
625 /**
626 * A fixed-length list of 64-bit signed integers that is viewable as a
627 * [TypedData]. For long lists, this implementation can be considerably
628 * more space- and time-efficient than the default [List] implementation.
629 */
630 abstract class Int64List implements List<int>, TypedData {
631 /**
632 * Creates an [Int64List] of the specified length (in elements), all of
633 * whose elements are initially zero.
634 */
635 external factory Int64List(int length);
636
637 /**
638 * Creates a [Int64List] with the same size as the [elements] list
639 * and copies over the elements.
640 */
641 external factory Int64List.fromList(List<int> elements);
642
643 /**
644 * Creates an [Int64List] _view_ of the specified region in the specified
645 * byte buffer. Changes in the [Int64List] will be visible in the byte buffer
646 * and vice versa. If the [offsetInBytes] index of the region is not
647 * specified, it defaults to zero (the first byte in the byte buffer).
648 * If the length is not specified, it defaults to null, which indicates that
649 * the view extends to the end of the byte buffer.
650 *
651 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
652 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
653 * the length of [buffer].
654 *
655 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
656 * BYTES_PER_ELEMENT.
657 */
658 external factory Int64List.view(ByteBuffer buffer,
659 [int offsetInBytes = 0, int length]);
660
661 static const int BYTES_PER_ELEMENT = 8;
662 }
663
664
665 /**
666 * A fixed-length list of 64-bit unsigned integers that is viewable as a
667 * [TypedData]. For long lists, this implementation can be considerably
668 * more space- and time-efficient than the default [List] implementation.
669 */
670 abstract class Uint64List implements List<int>, TypedData {
671 /**
672 * Creates a [Uint64List] of the specified length (in elements), all
673 * of whose elements are initially zero.
674 */
675 external factory Uint64List(int length);
676
677 /**
678 * Creates a [Uint64List] with the same size as the [elements] list
679 * and copies over the elements.
680 */
681 external factory Uint64List.fromList(List<int> elements);
682
683 /**
684 * Creates an [Uint64List] _view_ of the specified region in
685 * the specified byte buffer. Changes in the [Uint64List] will be
686 * visible in the byte buffer and vice versa. If the [offsetInBytes]
687 * index of the region is not specified, it defaults to zero (the first
688 * byte in the byte buffer). If the length is not specified, it defaults
689 * to null, which indicates that the view extends to the end of the byte
690 * buffer.
691 *
692 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
693 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
694 * the length of [buffer].
695 *
696 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
697 * BYTES_PER_ELEMENT.
698 */
699 external factory Uint64List.view(ByteBuffer buffer,
700 [int offsetInBytes = 0, int length]);
701
702 static const int BYTES_PER_ELEMENT = 8;
703 }
704
705
706 /**
707 * A fixed-length list of IEEE 754 single-precision binary floating-point
708 * numbers that is viewable as a [TypedData]. For long lists, this
709 * implementation can be considerably more space- and time-efficient than
710 * the default [List] implementation.
711 */
712 abstract class Float32List implements List<double>, TypedData {
713 /**
714 * Creates a [Float32List] of the specified length (in elements), all of
715 * whose elements are initially zero.
716 */
717 external factory Float32List(int length);
718
719 /**
720 * Creates a [Float32List] with the same size as the [elements] list
721 * and copies over the elements.
722 */
723 external factory Float32List.fromList(List<double> elements);
724
725 /**
726 * Creates a [Float32List] _view_ of the specified region in the specified
727 * byte buffer. Changes in the [Float32List] will be visible in the byte
728 * buffer and vice versa. If the [offsetInBytes] index of the region is not
729 * specified, it defaults to zero (the first byte in the byte buffer).
730 * If the length is not specified, it defaults to null, which indicates
731 * that the view extends to the end of the byte buffer.
732 *
733 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
734 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
735 * the length of [buffer].
736 *
737 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
738 * BYTES_PER_ELEMENT.
739 */
740 external factory Float32List.view(ByteBuffer buffer,
741 [int offsetInBytes = 0, int length]);
742
743 static const int BYTES_PER_ELEMENT = 4;
744 }
745
746
747 /**
748 * A fixed-length list of IEEE 754 double-precision binary floating-point
749 * numbers that is viewable as a [TypedData]. For long lists, this
750 * implementation can be considerably more space- and time-efficient than
751 * the default [List] implementation.
752 */
753 abstract class Float64List implements List<double>, TypedData {
754 /**
755 * Creates a [Float64List] of the specified length (in elements), all of
756 * whose elements are initially zero.
757 */
758 external factory Float64List(int length);
759
760 /**
761 * Creates a [Float64List] with the same size as the [elements] list
762 * and copies over the elements.
763 */
764 external factory Float64List.fromList(List<double> elements);
765
766 /**
767 * Creates a [Float64List] _view_ of the specified region in the specified
768 * byte buffer. Changes in the [Float64List] will be visible in the byte
769 * buffer and vice versa. If the [offsetInBytes] index of the region is not
770 * specified, it defaults to zero (the first byte in the byte buffer).
771 * If the length is not specified, it defaults to null, which indicates
772 * that the view extends to the end of the byte buffer.
773 *
774 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
775 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
776 * the length of [buffer].
777 *
778 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
779 * BYTES_PER_ELEMENT.
780 */
781 external factory Float64List.view(ByteBuffer buffer,
782 [int offsetInBytes = 0, int length]);
783
784 static const int BYTES_PER_ELEMENT = 8;
785 }
786
787
788 /**
789 * A fixed-length list of Float32x4 numbers that is viewable as a
790 * [TypedData]. For long lists, this implementation will be considerably more
791 * space- and time-efficient than the default [List] implementation.
792 */
793 abstract class Float32x4List implements List<Float32x4>, TypedData {
794 /**
795 * Creates a [Float32x4List] of the specified length (in elements),
796 * all of whose elements are initially zero.
797 */
798 external factory Float32x4List(int length);
799
800 /**
801 * Creates a [Float32x4List] _view_ of the specified region in the specified
802 * byte buffer. Changes in the [Float32x4List] will be visible in the byte
803 * buffer and vice versa. If the [offsetInBytes] index of the region is not
804 * specified, it defaults to zero (the first byte in the byte buffer).
805 * If the length is not specified, it defaults to null, which indicates
806 * that the view extends to the end of the byte buffer.
807 *
808 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
809 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
810 * the length of [buffer].
811 *
812 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of
813 * BYTES_PER_ELEMENT.
814 */
815 external factory Float32x4List.view(ByteBuffer buffer,
816 [int offsetInBytes = 0, int length]);
817
818 static const int BYTES_PER_ELEMENT = 16;
819 }
820
821
822 /**
823 * Interface of Dart Float32x4 immutable value type and operations.
824 * Float32x4 stores 4 32-bit floating point values in "lanes".
825 * The lanes are "x", "y", "z", and "w" respectively.
826 */
827 abstract class Float32x4 {
828 external factory Float32x4(double x, double y, double z, double w);
829 external factory Float32x4.zero();
830
831 /// Addition operator.
832 Float32x4 operator+(Float32x4 other);
833 /// Negate operator.
834 Float32x4 operator-();
835 /// Subtraction operator.
836 Float32x4 operator-(Float32x4 other);
837 /// Multiplication operator.
838 Float32x4 operator*(Float32x4 other);
839 /// Division operator.
840 Float32x4 operator/(Float32x4 other);
841
842 /// Relational less than.
843 Uint32x4 lessThan(Float32x4 other);
844 /// Relational less than or equal.
845 Uint32x4 lessThanOrEqual(Float32x4 other);
846 /// Relational greater than.
847 Uint32x4 greaterThan(Float32x4 other);
848 /// Relational greater than or equal.
849 Uint32x4 greaterThanOrEqual(Float32x4 other);
850 /// Relational equal.
851 Uint32x4 equal(Float32x4 other);
852 /// Relational not-equal.
853 Uint32x4 notEqual(Float32x4 other);
854
855 /// Returns a copy of [this] each lane being scaled by [s].
856 Float32x4 scale(double s);
857 /// Returns the absolute value of this [Float32x4].
858 Float32x4 abs();
859 /// Clamps [this] to be in the range [lowerLimit]-[upperLimit].
860 Float32x4 clamp(Float32x4 lowerLimit,
861 Float32x4 upperLimit);
862
863 /// Extracted x value.
864 double get x;
865 /// Extracted y value.
866 double get y;
867 /// Extracted z value.
868 double get z;
869 /// Extracted w value.
870 double get w;
871
872 /// Returns a new [Float32x4] with [this]' x value in all four lanes.
873 Float32x4 get xxxx;
874 /// Returns a new [Float32x4] with [this]' y value in all four lanes.
875 Float32x4 get yyyy;
876 /// Returns a new [Float32x4] with [this]' z value in all four lanes.
877 Float32x4 get zzzz;
878 /// Returns a new [Float32x4] with [this]' w value in all four lanes.
879 Float32x4 get wwww;
880 // TODO(johnmccutchan): Add all 256 possible combinations.
881
882 /// Returns a new [Float32x4] copied from [this] with a new x value.
883 Float32x4 withX(double x);
884 /// Returns a new [Float32x4] copied from [this] with a new y value.
885 Float32x4 withY(double y);
886 /// Returns a new [Float32x4] copied from [this] with a new z value.
887 Float32x4 withZ(double z);
888 /// Returns a new [Float32x4] copied from [this] with a new w value.
889 Float32x4 withW(double w);
890
891 /// Returns the lane-wise minimum value in [this] or [other].
892 Float32x4 min(Float32x4 other);
893
894 /// Returns the lane-wise maximum value in [this] or [other].
895 Float32x4 max(Float32x4 other);
896
897 /// Returns the square root of [this].
898 Float32x4 sqrt();
899
900 /// Returns the reciprocal of [this].
901 Float32x4 reciprocal();
902
903 /// Returns the square root of the reciprocal of [this].
904 Float32x4 reciprocalSqrt();
905
906 /// Returns a bit-wise copy of [this] as a [Uint32x4].
907 Uint32x4 toUint32x4();
908 }
909
910
911 /**
912 * Interface of Dart Uint32x4 and operations.
913 * Uint32x4 stores 4 32-bit bit-masks in "lanes".
914 * The lanes are "x", "y", "z", and "w" respectively.
915 */
916 abstract class Uint32x4 {
917 external factory Uint32x4(int x, int y, int z, int w);
918 external factory Uint32x4.bool(bool x, bool y, bool z, bool w);
919
920 /// The bit-wise or operator.
921 Uint32x4 operator|(Uint32x4 other);
922 /// The bit-wise and operator.
923 Uint32x4 operator&(Uint32x4 other);
924 /// The bit-wise xor operator.
925 Uint32x4 operator^(Uint32x4 other);
926
927 /// Extract 32-bit mask from x lane.
928 int get x;
929 /// Extract 32-bit mask from y lane.
930 int get y;
931 /// Extract 32-bit mask from z lane.
932 int get z;
933 /// Extract 32-bit mask from w lane.
934 int get w;
935
936 /// Returns a new [Uint32x4] copied from [this] with a new x value.
937 Uint32x4 withX(int x);
938 /// Returns a new [Uint32x4] copied from [this] with a new y value.
939 Uint32x4 withY(int y);
940 /// Returns a new [Uint32x4] copied from [this] with a new z value.
941 Uint32x4 withZ(int z);
942 /// Returns a new [Uint32x4] copied from [this] with a new w value.
943 Uint32x4 withW(int w);
944
945 /// Extracted x value. Returns false for 0, true for any other value.
946 bool get flagX;
947 /// Extracted y value. Returns false for 0, true for any other value.
948 bool get flagY;
949 /// Extracted z value. Returns false for 0, true for any other value.
950 bool get flagZ;
951 /// Extracted w value. Returns false for 0, true for any other value.
952 bool get flagW;
953
954 /// Returns a new [Uint32x4] copied from [this] with a new x value.
955 Uint32x4 withFlagX(bool x);
956 /// Returns a new [Uint32x4] copied from [this] with a new y value.
957 Uint32x4 withFlagY(bool y);
958 /// Returns a new [Uint32x4] copied from [this] with a new z value.
959 Uint32x4 withFlagZ(bool z);
960 /// Returns a new [Uint32x4] copied from [this] with a new w value.
961 Uint32x4 withFlagW(bool w);
962
963 /// Merge [trueValue] and [falseValue] based on [this]' bit mask:
964 /// Select bit from [trueValue] when bit in [this] is on.
965 /// Select bit from [falseValue] when bit in [this] is off.
966 Float32x4 select(Float32x4 trueValue, Float32x4 falseValue);
967
968 /// Returns a bit-wise copy of [this] as a [Float32x4].
969 Float32x4 toFloat32x4();
970 }
OLDNEW
« no previous file with comments | « sdk/lib/typeddata/dart2js/typeddata_dart2js.dart ('k') | sdk/lib/typeddata/typeddata_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698