 |
Changeset 4110
- Timestamp:
- 11/22/08 04:53:36
(3 hours ago)
- Author:
- kris
- Message:
added opSlice() and reserve().
Also adjusted fill(src) and read(dst) to be more careful about how they reset the buffer indices, in order to preserve slicing positions within the buffer.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3838 |
r4110 |
|
| 386 | 386 | /*********************************************************************** |
|---|
| 387 | 387 | |
|---|
| | 388 | Retrieve the valid content |
|---|
| | 389 | |
|---|
| | 390 | Returns: |
|---|
| | 391 | a void[] slice of the buffer |
|---|
| | 392 | |
|---|
| | 393 | Remarks: |
|---|
| | 394 | Return a void[] slice of the buffer, from the current position |
|---|
| | 395 | up to the limit of valid content. The content remains in the |
|---|
| | 396 | buffer for future extraction. |
|---|
| | 397 | |
|---|
| | 398 | ***********************************************************************/ |
|---|
| | 399 | |
|---|
| | 400 | void[] slice () |
|---|
| | 401 | { |
|---|
| | 402 | return data [index .. extent]; |
|---|
| | 403 | } |
|---|
| | 404 | |
|---|
| | 405 | /*********************************************************************** |
|---|
| | 406 | |
|---|
| | 407 | Return a void[] slice of the buffer from start to end, where |
|---|
| | 408 | end is exclusive |
|---|
| | 409 | |
|---|
| | 410 | ***********************************************************************/ |
|---|
| | 411 | |
|---|
| | 412 | final void[] opSlice (uint start, uint end) |
|---|
| | 413 | { |
|---|
| | 414 | assert (start <= extent && end <= extent && start <= end); |
|---|
| | 415 | return data [start .. end]; |
|---|
| | 416 | } |
|---|
| | 417 | |
|---|
| | 418 | /*********************************************************************** |
|---|
| | 419 | |
|---|
| 388 | 420 | Access buffer content |
|---|
| 389 | 421 | |
|---|
| … | … | |
| 431 | 463 | // in the buffer as possible, such that entire records may |
|---|
| 432 | 464 | // be aliased directly from within. |
|---|
| 433 | | if (size > writable) |
|---|
| | 465 | if (size > (dimension - index)) |
|---|
| 434 | 466 | { |
|---|
| 435 | 467 | if (size > dimension) |
|---|
| … | … | |
| 619 | 651 | /*********************************************************************** |
|---|
| 620 | 652 | |
|---|
| 621 | | Retrieve the valid content |
|---|
| 622 | | |
|---|
| 623 | | Returns: |
|---|
| 624 | | a void[] slice of the buffer |
|---|
| 625 | | |
|---|
| 626 | | Remarks: |
|---|
| 627 | | Return a void[] slice of the buffer, from the current position |
|---|
| 628 | | up to the limit of valid content. The content remains in the |
|---|
| 629 | | buffer for future extraction. |
|---|
| 630 | | |
|---|
| 631 | | ***********************************************************************/ |
|---|
| 632 | | |
|---|
| 633 | | void[] slice () |
|---|
| 634 | | { |
|---|
| 635 | | return data [index .. extent]; |
|---|
| 636 | | } |
|---|
| 637 | | |
|---|
| 638 | | /*********************************************************************** |
|---|
| 639 | | |
|---|
| 640 | 653 | Move the current read location |
|---|
| 641 | 654 | |
|---|
| … | … | |
| 773 | 786 | /*********************************************************************** |
|---|
| 774 | 787 | |
|---|
| | 788 | Reserve the specified space within the buffer, compressing |
|---|
| | 789 | existing content as necessary to make room |
|---|
| | 790 | |
|---|
| | 791 | Returns the current read point, after compression if that |
|---|
| | 792 | was required |
|---|
| | 793 | |
|---|
| | 794 | ***********************************************************************/ |
|---|
| | 795 | |
|---|
| | 796 | final uint reserve (uint space) |
|---|
| | 797 | { |
|---|
| | 798 | assert (space < dimension); |
|---|
| | 799 | |
|---|
| | 800 | if ((dimension - index) < space) |
|---|
| | 801 | compress; |
|---|
| | 802 | return index; |
|---|
| | 803 | } |
|---|
| | 804 | |
|---|
| | 805 | /*********************************************************************** |
|---|
| | 806 | |
|---|
| 775 | 807 | Write into this buffer |
|---|
| 776 | 808 | |
|---|
| … | … | |
| 855 | 887 | |
|---|
| 856 | 888 | IBuffer compress () |
|---|
| 857 | | { |
|---|
| 858 | | uint r = readable (); |
|---|
| | 889 | { |
|---|
| | 890 | uint r = readable; |
|---|
| 859 | 891 | |
|---|
| 860 | 892 | if (index > 0 && r > 0) |
|---|
| … | … | |
| 887 | 919 | if (src is null) |
|---|
| 888 | 920 | return IConduit.Eof; |
|---|
| 889 | | |
|---|
| | 921 | /+ |
|---|
| | 922 | // should not reset here, since we're only filling! |
|---|
| 890 | 923 | if (readable is 0 && canCompress) |
|---|
| 891 | 924 | index = extent = 0; // same as clear(), without call-chain |
|---|
| … | … | |
| 893 | 926 | if (writable is 0) |
|---|
| 894 | 927 | return 0; |
|---|
| 895 | | |
|---|
| | 928 | +/ |
|---|
| 896 | 929 | return write (&src.read); |
|---|
| 897 | 930 | } |
|---|
| … | … | |
| 1321 | 1354 | content = source.read (dst); |
|---|
| 1322 | 1355 | else |
|---|
| | 1356 | { |
|---|
| | 1357 | if (writable is 0) |
|---|
| | 1358 | index = extent = 0; // same as clear(), without call-chain |
|---|
| | 1359 | |
|---|
| 1323 | 1360 | // keep buffer partially populated |
|---|
| 1324 | 1361 | if ((content = fill(source)) != IConduit.Eof && content > 0) |
|---|
| 1325 | 1362 | content = read (dst); |
|---|
| | 1363 | } |
|---|
| 1326 | 1364 | } |
|---|
| 1327 | 1365 | else |
|---|
| … | … | |
| 1624 | 1662 | } |
|---|
| 1625 | 1663 | } |
|---|
| | 1664 | |
|---|
| | 1665 | |
|---|
| | 1666 | /****************************************************************************** |
|---|
| | 1667 | |
|---|
| | 1668 | ******************************************************************************/ |
|---|
| | 1669 | |
|---|
| | 1670 | debug (Buffer) |
|---|
| | 1671 | { |
|---|
| | 1672 | void main() |
|---|
| | 1673 | { |
|---|
| | 1674 | auto b = new Buffer(6); |
|---|
| | 1675 | b.append ("fubar"); |
|---|
| | 1676 | b.reserve (1); |
|---|
| | 1677 | b.slice (5); |
|---|
| | 1678 | b.reserve (4); |
|---|
| | 1679 | } |
|---|
| | 1680 | } |
|---|
| r3598 |
r4110 |
|
| 78 | 78 | /*********************************************************************** |
|---|
| 79 | 79 | |
|---|
| 80 | | Return a void[] slice of the buffer up to the limit of |
|---|
| 81 | | valid content. |
|---|
| 82 | | |
|---|
| 83 | | ***********************************************************************/ |
|---|
| 84 | | |
|---|
| 85 | | abstract void[] slice (); |
|---|
| 86 | | |
|---|
| 87 | | /*********************************************************************** |
|---|
| 88 | | |
|---|
| 89 | 80 | Set the backing array with all content readable. Writing |
|---|
| 90 | 81 | to this will either flush it to an associated conduit, or |
|---|
| … | … | |
| 169 | 160 | |
|---|
| 170 | 161 | abstract void consume (void[] src); |
|---|
| | 162 | |
|---|
| | 163 | /*********************************************************************** |
|---|
| | 164 | |
|---|
| | 165 | Return a void[] slice of the buffer up to the limit of |
|---|
| | 166 | valid content. |
|---|
| | 167 | |
|---|
| | 168 | ***********************************************************************/ |
|---|
| | 169 | |
|---|
| | 170 | abstract void[] slice (); |
|---|
| | 171 | |
|---|
| | 172 | /*********************************************************************** |
|---|
| | 173 | |
|---|
| | 174 | Return a void[] slice of the buffer from start to end, where |
|---|
| | 175 | end is exclusive |
|---|
| | 176 | |
|---|
| | 177 | ***********************************************************************/ |
|---|
| | 178 | |
|---|
| | 179 | abstract void[] opSlice (uint start, uint end); |
|---|
| 171 | 180 | |
|---|
| 172 | 181 | /*********************************************************************** |
|---|
| … | … | |
| 363 | 372 | |
|---|
| 364 | 373 | /*********************************************************************** |
|---|
| | 374 | |
|---|
| | 375 | Reserve the specified space within the buffer, compressing |
|---|
| | 376 | existing content as necessary to make room |
|---|
| | 377 | |
|---|
| | 378 | Returns the current read point, after compression if that |
|---|
| | 379 | was required |
|---|
| | 380 | |
|---|
| | 381 | ***********************************************************************/ |
|---|
| | 382 | |
|---|
| | 383 | abstract uint reserve (uint space); |
|---|
| | 384 | |
|---|
| | 385 | /*********************************************************************** |
|---|
| 365 | 386 | |
|---|
| 366 | 387 | Returns the limit of readable content within this buffer. |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic