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

  1. "======================================================================
  2. |
  3. |   ByteArray 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         14 Dec 91      Added asString -- generally useful functionality, but
  34. |              especially for STIX.
  35. |
  36. | sbb         28 Nov 91      Added growSize method -- 10 wasn't right, and we
  37. |              should probably base the grow size on the size of the
  38. |              object in question.
  39. |
  40. | sbb         28 Nov 91      Switched shallowCopy to use faster primitives.
  41. |
  42. | sbb         16 Mar 91      Class creation now separate statement.
  43. |
  44. | sbyrne     25 Apr 89      created.
  45. |
  46. "
  47.  
  48. ArrayedCollection variableByteSubclass: #ByteArray
  49.           instanceVariableNames: ''
  50.           classVariableNames: ''
  51.           poolDictionaries: ''
  52.           category: nil
  53. !
  54.  
  55. ByteArray comment: 
  56. 'My instances are similar to strings in that they are both represented as
  57. a sequence of bytes, but my individual elements are integers, where as
  58. a String''s elements are characters.' !
  59.  
  60. !ByteArray methodsFor: 'copying'!
  61.  
  62. shallowCopy
  63.     | newArray |
  64.     newArray _ self species new: self size.
  65.     newArray replaceFrom: 1 to: self size with: self.
  66.     " Off the top of my head, I can't think why we need to use the code below
  67.       instead of the faster code above
  68.       1 to: self size do:
  69.           [ :i | newArray at: i put: (self at: i) ].
  70.     "
  71.     ^newArray
  72. !
  73.  
  74. deepCopy
  75.     ^self shallowCopy
  76.  
  77. ! !
  78.  
  79.  
  80.  
  81. !ByteArray methodsFor: 'converting'!
  82.  
  83. asString
  84.     | string size |
  85.     size _ self size.
  86.     string _ String new: size.
  87.     string replaceFrom: 1 to: size withByteArray: self startingAt: 1.
  88.     ^string
  89. ! !
  90.  
  91.  
  92.  
  93. "!ByteArray methodsFor: 'replacing'!
  94.  
  95. replaceFrom: start to: stop with: replacementByteArray startingAt: repStart
  96.     ^self primReplaceFrom: start to: stop with: replacementByteArray
  97.       startingAt: repStart
  98. ! !
  99.  
  100. "
  101.  
  102. !ByteArray methodsFor: 'private'!
  103.  
  104. growSize
  105.     ^40
  106. ! !
  107.