home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnusmalltalk / readstream.st < prev    next >
Text File  |  1992-02-15  |  2KB  |  87 lines

  1. "======================================================================
  2. |
  3. |   ReadStream Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbb         16 Mar 91      Class creation now separate statement.
  34. |
  35. | sbyrne     19 Sep 89      Converted to use real method categories.
  36. |
  37. | sbyrne     25 Apr 89      created.
  38. |
  39. "
  40.  
  41. PositionableStream subclass: #ReadStream
  42.            instanceVariableNames: ''
  43.            classVariableNames: ''
  44.            poolDictionaries: ''
  45.            category: nil
  46. !
  47.  
  48. ReadStream comment: 
  49. 'I implement the set of read-only stream objects.  You may read from
  50. my objects, but you may not write to them.' !
  51.  
  52. !ReadStream class methodsFor: 'instance creation'!
  53.  
  54. on: aCollection
  55.     ^(self new initCollection: aCollection) access: 1
  56. !!
  57.  
  58.  
  59.  
  60. !ReadStream methodsFor: 'accessing-reading'!
  61.  
  62. reverseContents
  63.     "May be faster than generic stream reverseContents."
  64.     | aCollection i numElts |
  65.     numElts _ collection size.
  66.     aCollection _ collection species new: numElts.
  67.     i _ 0.
  68.     [ i _ i + 1. 
  69.       i <= endPtr ] whileTrue:
  70.         [ aCollection at: numElts - i + 1
  71.                   put: (collection at: i) ].
  72.     ^aCollection
  73. !!
  74.  
  75.  
  76.  
  77. !ReadStream methodsFor: 'private methods'!
  78.  
  79. initCollection: aCollection
  80.     collection _ aCollection.
  81.     ptr _ 1.
  82.     endPtr _ collection size
  83.  
  84. !!
  85.