ImmutableByteArray.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 22 Sep 2015 16:28:42 +0100
branchjv
changeset 18759 c1217211909c
parent 18705 843770030c5f
child 19225 9e8abf62f932
permissions -rw-r--r--
Changed identification strings to contain jv-branch ...to make explicit that this distribution is not the official one used by eXept and therefore that eXept is not to be blamed in case of any problem.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18703
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
     1
"{ Encoding: utf8 }"
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
     2
12469
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
     3
"
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
     4
 COPYRIGHT (c) 2009 by eXept Software AG
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
     5
	      All Rights Reserved
12469
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
     6
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
     7
 This software is furnished under a license and may be used
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
     8
 only in accordance with the terms of that license and with the
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    10
 be provided or otherwise made available to, or used by, any
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    11
 other person.  No title to or ownership of the software is
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    12
 hereby transferred.
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    13
"
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
    14
"{ Package: 'stx:libbasic' }"
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
17374
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    16
"{ NameSpace: Smalltalk }"
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    17
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
ByteArray variableByteSubclass:#ImmutableByteArray
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'System-Compiler-Support'
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
12465
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    25
!ImmutableByteArray class methodsFor:'documentation'!
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    26
12469
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    27
copyright
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    28
"
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    29
 COPYRIGHT (c) 2009 by eXept Software AG
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
    30
	      All Rights Reserved
12469
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    31
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    32
 This software is furnished under a license and may be used
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    33
 only in accordance with the terms of that license and with the
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    35
 be provided or otherwise made available to, or used by, any
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    36
 other person.  No title to or ownership of the software is
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    37
 hereby transferred.
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    38
"
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    39
!
bf6f0881354f added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12465
diff changeset
    40
12465
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    41
documentation
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    42
"
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    43
    By default, byte array literals in smalltalk are mutable objects. That
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    44
    may lead to some subtle (and hard to find errors), if some method passes
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    45
    a literal byte-array object as argument to someone else, who changes the
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
    46
    bytearray using at:put: like messages. Since the bytearray object is kept in
12465
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    47
    the first methods literals, the bytearray constant has now been changed without
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    48
    having the method's sourcecode reflect this. Thus, the method will
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    49
    behave differently from what its source may make you think.
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    50
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    51
    To help finding this kind of 'feature/bug', the compiler can be
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    52
    configured to create instances of this ImmutableByteArray instead of ByteArrays
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    53
    for literals. Instances of ImmutableByteArray catch storing accesses and
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    54
    enter the debugger. Although useful, this feature is disabled by default
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
    55
    for compatibility to other smalltalk implementations.
12465
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    56
    (Also, if turned on, this makes inspecting bytearray literals entered in
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    57
     a workspace somewhat strange: you cannot modify it any longer).
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    58
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    59
    Turn the ImmutableArray feature on, by setting the Parser's class variable
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    60
    'ArraysAreImmutable' to true or use the new launchers settings menu.
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    61
18545
bf6afb06b38a class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 17536
diff changeset
    62
    This class should be used only by the compiler.
bf6afb06b38a class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 17536
diff changeset
    63
12472
4538fa289fda added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12469
diff changeset
    64
    ATTENTION:
14223
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    65
        there may be still code around which checks for explicit class being ByteArray
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    66
        (both in Smalltalk and in primitive code). All code like foo 'class == ByteArray'
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    67
        or '__isByteArray()' will not work with ImmutableByteArrays - consider using '__isByteArrayLike()'.
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    68
        A somewhat better approach would be to either add a flag to the object (mutability)
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    69
        and check this dynamically (expensive) or to place immutable objects into a readonly
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    70
        memory segment (the good solution). We will eventually implement the second in the future...
12472
4538fa289fda added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12469
diff changeset
    71
12465
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    72
    [see also:]
14223
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    73
        ImmutableString
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    74
        ImmutableArray
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    75
        Parser Scanner
12465
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    76
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    77
    [author:]
14223
c785723e9f63 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14114
diff changeset
    78
        Claus Gittinger
12465
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    79
"
3ad76cb3da62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12456
diff changeset
    80
! !
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
17374
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    82
!ImmutableByteArray class methodsFor:'queries'!
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    83
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    84
mutableClass
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    85
    "answer an equivalent mustable class"
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    86
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    87
    ^ ByteArray
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    88
! !
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    89
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    90
!ImmutableByteArray class methodsFor:'testing'!
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    91
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    92
hasImmutableInstances
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    93
    ^ true
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    94
! !
a58160e9e232 initial checkin
Stefan Vogel <sv@exept.de>
parents: 16823
diff changeset
    95
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
!ImmutableByteArray methodsFor:'accessing'!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
    98
at:index put:value
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    "Trigger an error if an immutable bytearray is stored into.
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
     The store will be performed (for compatibility reasons) if you continue
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
     in the debugger."
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
   102
12493
a8a69ca4a721 Raise NoModificationError
Stefan Vogel <sv@exept.de>
parents: 12488
diff changeset
   103
    self noModificationError.
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    ^ super at:index put:value
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
   107
basicAt:index put:value
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    "Trigger an error if an immutable bytearray is stored into.
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
     The store will be performed (for compatibility reasons) if you continue
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
     in the debugger."
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
   111
12493
a8a69ca4a721 Raise NoModificationError
Stefan Vogel <sv@exept.de>
parents: 12488
diff changeset
   112
    self noModificationError.
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    ^ super basicAt:index put:value
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
! !
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
!ImmutableByteArray methodsFor:'converting'!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
12488
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   118
asByteArray
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   119
    "return the receiver as a (mutable) byteArray"
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   120
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   121
    ^ self copy changeClassTo: ByteArray
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   122
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   123
    "
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
   124
     #[1 2 3 4] asImmutableByteArray asByteArray
12488
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   125
    "
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   126
!
889416ab718a more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12472
diff changeset
   127
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
asImmutableByteArray
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    ^ self
16823
48a3b8612594 added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16749
diff changeset
   130
!
48a3b8612594 added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16749
diff changeset
   131
48a3b8612594 added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16749
diff changeset
   132
asMutableCollection
48a3b8612594 added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16749
diff changeset
   133
    "return a writable copy of myself"
48a3b8612594 added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16749
diff changeset
   134
48a3b8612594 added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16749
diff changeset
   135
    ^ self copy changeClassTo:ByteArray
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
! !
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!ImmutableByteArray methodsFor:'copying'!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
postCopy
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    "when copied, make me a real (mutable) ByteArray"
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    self changeClassTo:ByteArray.
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
postDeepCopy
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    "when copied, make me a real (mutable) ByteArray"
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    self changeClassTo:ByteArray.
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    "
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
     #[1 2 3 4] asImmutableByteArray copy          class
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
     #[1 2 3 4] asImmutableByteArray shallowCopy   class
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
     #[1 2 3 4] asImmutableByteArray deepCopy      class
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    "
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
shallowCopy
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    "when copying, return a real (mutable) ByteArray"
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    |sz|
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
    sz := self size.
16399
b8933f4d84cc class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 14388
diff changeset
   164
    ^ (ByteArray new:sz) replaceBytesFrom:1 to:sz with:self startingAt:1
14114
e18145c4ab7f comment/format in: #shallowCopy
Stefan Vogel <sv@exept.de>
parents: 14024
diff changeset
   165
e18145c4ab7f comment/format in: #shallowCopy
Stefan Vogel <sv@exept.de>
parents: 14024
diff changeset
   166
    "
e18145c4ab7f comment/format in: #shallowCopy
Stefan Vogel <sv@exept.de>
parents: 14024
diff changeset
   167
     #[1 2 3 4] asImmutableByteArray shallowCopy
e18145c4ab7f comment/format in: #shallowCopy
Stefan Vogel <sv@exept.de>
parents: 14024
diff changeset
   168
    "
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
! !
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
16749
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   171
!ImmutableByteArray methodsFor:'printing & storing'!
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   172
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   173
displayOn:aGCOrStream
17536
950f6d65e102 class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 17374
diff changeset
   174
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
950f6d65e102 class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 17374
diff changeset
   175
    "/ ST/X (and some old ST80's) mean: draw-yourself on a GC.
16749
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   176
    (aGCOrStream isStream) ifTrue:[
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   177
        self storeOn:aGCOrStream.
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   178
        aGCOrStream nextPutAll:'"immutable"'.
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   179
        ^ self.
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   180
    ].
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   181
    super displayOn:aGCOrStream.
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   182
! !
5339adc5586a class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 16399
diff changeset
   183
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
!ImmutableByteArray methodsFor:'private'!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
species
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    "Copies should be mutable"
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    ^ ByteArray
16399
b8933f4d84cc class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 14388
diff changeset
   190
!
b8933f4d84cc class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 14388
diff changeset
   191
b8933f4d84cc class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 14388
diff changeset
   192
speciesForCopy
b8933f4d84cc class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 14388
diff changeset
   193
    "Copies should be mutable"
b8933f4d84cc class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 14388
diff changeset
   194
b8933f4d84cc class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 14388
diff changeset
   195
    ^ ByteArray
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
! !
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
!ImmutableByteArray methodsFor:'queries'!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
14388
44305237837b isImmutable
Claus Gittinger <cg@exept.de>
parents: 14223
diff changeset
   200
isImmutable
44305237837b isImmutable
Claus Gittinger <cg@exept.de>
parents: 14223
diff changeset
   201
    ^ true
44305237837b isImmutable
Claus Gittinger <cg@exept.de>
parents: 14223
diff changeset
   202
!
44305237837b isImmutable
Claus Gittinger <cg@exept.de>
parents: 14223
diff changeset
   203
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
isLiteral
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    "return true, if the receiver can be used as a literal constant in ST syntax
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
     (i.e. can be used in constant arrays)"
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    "yes, I must be"
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    ^ true
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
! !
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
!ImmutableByteArray methodsFor:'specials'!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
   215
become:anotherObject
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    "trigger an error if I should become something else
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
     (this would be an even more tricky manipulation)"
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
   218
12493
a8a69ca4a721 Raise NoModificationError
Stefan Vogel <sv@exept.de>
parents: 12488
diff changeset
   219
    self noModificationError.
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    ^ super become:anotherObject
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
becomeNil
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    "trigger an error if I should become nil
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
     (this would be an even more tricky manipulation)"
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12493
diff changeset
   226
12493
a8a69ca4a721 Raise NoModificationError
Stefan Vogel <sv@exept.de>
parents: 12488
diff changeset
   227
    self noModificationError.
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    ^ super becomeNil
18703
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
   229
!
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
   230
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
   231
becomeSameAs:anotherObject
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
   232
    "trigger an error if I should become something else
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
   233
     (this would be an even more tricky manipulation)"
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
   234
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
   235
    self noModificationError.
a2887ae5eca8 class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 18614
diff changeset
   236
    ^ super becomeSameAs:anotherObject
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
! !
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
!ImmutableByteArray class methodsFor:'documentation'!
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
version_CVS
18545
bf6afb06b38a class: ImmutableByteArray
Stefan Vogel <sv@exept.de>
parents: 17536
diff changeset
   242
    ^ '$Header$'
12456
5e084695631f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
! !
16399
b8933f4d84cc class: ImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 14388
diff changeset
   244