ExternalLong.st
author Claus Gittinger <cg@exept.de>
Mon, 20 Dec 2010 16:29:36 +0100
changeset 2517 5a6c9b79c66a
parent 2462 07457221fd73
child 2519 6267de81a0e4
permissions -rw-r--r--
comments in: #new #unprotectedNew
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1926
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     1
"
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     2
 COPYRIGHT (c) 1998 by eXept Software AG
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     3
              All Rights Reserved
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     4
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     5
 This software is furnished under a license and may be used
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     6
 only in accordance with the terms of that license and with the
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     8
 be provided or otherwise made available to, or used by, any
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
     9
 other person.  No title to or ownership of the software is
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    10
 hereby transferred.
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    11
"
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    13
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    14
ExternalBytes subclass:#ExternalLong
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    15
	instanceVariableNames:''
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    16
	classVariableNames:''
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    17
	poolDictionaries:''
623
cd16d122c83e category change
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
    18
	category:'System-Support'
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    19
!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    20
1926
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    21
!ExternalLong class methodsFor:'documentation'!
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    22
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    23
copyright
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    24
"
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    25
 COPYRIGHT (c) 1998 by eXept Software AG
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    26
              All Rights Reserved
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    27
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    28
 This software is furnished under a license and may be used
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    29
 only in accordance with the terms of that license and with the
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    31
 be provided or otherwise made available to, or used by, any
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    32
 other person.  No title to or ownership of the software is
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    33
 hereby transferred.
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    34
"
2329
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
    35
!
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
    36
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
    37
documentation
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
    38
"
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
    39
    mostly added for odbc
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
    40
"
1926
b7740748e15c copyright
Claus Gittinger <cg@exept.de>
parents: 623
diff changeset
    41
! !
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    42
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    43
!ExternalLong class methodsFor:'instance creation'!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    44
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    45
new
2517
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    46
    "allocate some memory usable for data;
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    47
     the memory is not controlled by the garbage collector.
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    48
     Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    49
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    50
     Use this, if you have to pass a block of bytes to some
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    51
     external destination (such as a C function) which does not copy the
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    52
     data, but instead keeps a reference to it. For example, many functions
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    53
     which expect strings simply keep a ref to the passed string - for those,
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    54
     an ST/X string-pointer is not the right thing to pass, since ST/X objects
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    55
     may change their address.
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    56
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    57
     DANGER ALERT: the memory is NOT automatically freed until it is either
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    58
                   MANUALLY freed (see #free) or the returned externalBytes object
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    59
                   is unprotected or the classes releaseAllMemory method is called."
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    60
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    61
    ^ super new:4
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    62
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    63
    "
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    64
     ExternalLong new
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    65
    "
2517
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    66
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    67
    "Modified: / 20-12-2010 / 16:22:51 / cg"
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    68
!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    69
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    70
unprotectedNew
2517
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    71
    "allocate some memory usable for data;
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    72
     the memory is under the control of the garbage collector.
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    73
     Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    74
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    75
     DANGER ALERT: the memory block as allocated will be automatically freed
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    76
                   as soon as the reference to the returned externalBytes object
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    77
                   is gone (by the next garbage collect).
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    78
                   If the memory has been passed to a C-function which
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    79
                   remembers this pointer, bad things may happen ...."
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    80
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    81
    ^ super unprotectedNew:4
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    82
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    83
    "
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    84
     ExternalLong new
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    85
    "
2517
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    86
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
    87
    "Modified: / 20-12-2010 / 16:22:39 / cg"
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    88
! !
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    89
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    90
!ExternalLong methodsFor:'accessing'!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    91
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    92
asBoolean
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    93
    |result|
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    94
609
2a4ed61bf78b Updates from Tests, i.e. bug fixes
dq
parents: 605
diff changeset
    95
    result := self byteAt:1.
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    96
    result = 0 ifTrue:[
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    97
        ^ false.
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    98
    ].
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
    99
    ^ true.
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   100
!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   101
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   102
asInteger
609
2a4ed61bf78b Updates from Tests, i.e. bug fixes
dq
parents: 605
diff changeset
   103
    ^ self signedWordAt:1 MSB:false
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   104
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   105
    "
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   106
     ODBCLibrary::ExternalLong new value:10
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   107
    "
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   108
!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   109
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   110
asNullStatus
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   111
    |result|
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   112
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   113
    result := self wordAt:1 MSB:false.
2329
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   114
    result = 0 ifTrue:[ ^ #SQL_NO_NULLS ].
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   115
    result = 1 ifTrue:[ ^ #SQL_NULLABLE ].
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   116
    ^ #SQL_NULLABLE_UNKNOWN
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   117
!
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   118
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   119
asPointer
2330
2d8b961f62dc changed: #asPointer
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   120
    ^ ExternalAddress new setAddress:(self value)
2329
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   121
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   122
    "
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   123
     (ExternalLong new value:10) asPointer
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   124
    "
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   125
!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   126
609
2a4ed61bf78b Updates from Tests, i.e. bug fixes
dq
parents: 605
diff changeset
   127
boolean:bool
2a4ed61bf78b Updates from Tests, i.e. bug fixes
dq
parents: 605
diff changeset
   128
    bool ifTrue:[self byteAt:1 put:1].
2a4ed61bf78b Updates from Tests, i.e. bug fixes
dq
parents: 605
diff changeset
   129
    self byteAt:1 put:0.
2a4ed61bf78b Updates from Tests, i.e. bug fixes
dq
parents: 605
diff changeset
   130
!
2a4ed61bf78b Updates from Tests, i.e. bug fixes
dq
parents: 605
diff changeset
   131
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   132
value
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   133
    ^ self doubleWordAt:1
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   134
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   135
    "
623
cd16d122c83e category change
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   136
     ExternalLong new value:10
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   137
    "
623
cd16d122c83e category change
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   138
cd16d122c83e category change
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   139
    "Modified: / 30.3.1998 / 17:07:57 / cg"
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   140
!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   141
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   142
value:anInteger
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   143
    self doubleWordAt:1 put:anInteger
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   144
! !
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   145
2462
07457221fd73 added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2330
diff changeset
   146
!ExternalLong methodsFor:'printing & storing'!
07457221fd73 added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2330
diff changeset
   147
07457221fd73 added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2330
diff changeset
   148
printOn:aStream
07457221fd73 added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2330
diff changeset
   149
    aStream nextPutAll:self className; nextPut:$(.
07457221fd73 added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2330
diff changeset
   150
    self asInteger printOn:aStream.
07457221fd73 added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2330
diff changeset
   151
    aStream nextPut:$)
07457221fd73 added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2330
diff changeset
   152
! !
07457221fd73 added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 2330
diff changeset
   153
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   154
!ExternalLong class methodsFor:'documentation'!
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   155
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   156
version
2517
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
   157
    ^ '$Header: /cvs/stx/stx/libbasic2/ExternalLong.st,v 1.8 2010-12-20 15:29:36 cg Exp $'
2329
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   158
!
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   159
63e0cb1a051e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1926
diff changeset
   160
version_CVS
2517
5a6c9b79c66a comments in:
Claus Gittinger <cg@exept.de>
parents: 2462
diff changeset
   161
    ^ '$Header: /cvs/stx/stx/libbasic2/ExternalLong.st,v 1.8 2010-12-20 15:29:36 cg Exp $'
605
3826bf1e9c23 intitial checkin
dq
parents:
diff changeset
   162
! !