struct operatortest
string str=""
method operator [] takes integer i returns string
return SubString(.str,i,i+1)
endmethod
method operator[]= takes integer i, string ch returns nothing
set .str=SubString(.str,0,i)+ch+SubString(.str,i+1,StringLength(.str)-i)
endmethod
endstruct
function test takes nothing returns nothing
local operatortest x=operatortest.create()
set x.str="Test"
call BJDebugMsg( x[1])
call BJDebugMsg( x[0]+x[3])
set x[1] = "."
call BJDebugMsg( x.str)
endfunction
struct operatortest
string str=""
method operator [] takes integer i returns string
return SubString(.str,i,i+1)
endmethod
method operator[]= takes integer i, string ch returns nothing
set .str=SubString(.str,0,i)+ch+SubString(.str,i+1,StringLength(.str)-i)
endmethod
method operator< takes operatortest b returns boolean
return StringLength(this.str) < StringLength(b.str)
endmethod
endstruct
function test takes nothing returns nothing
local operatortest x=operatortest.create()
local operatortest y=operatortest.create()
set x.str="Test..."
set y.str=".Test"
if (x<y) then
call BJDebugMsg("Less than")
endif
if (x>y) then
call BJDebugMsg("Greater than")
endif
endfunction
interface ordered
method operator <
endinterface
interface indexed
method operator [] takes integer index returns ordered
method operator []= takes integer index, ordered v returns nothing
endinterface
function sort takes indexed a, integer from, integer to returns nothing
local integer i
local integer j
local ordered aux
set i=from
loop
exitwhen (i>=to)
set j=i+1
loop
exitwhen (j>to)
if (a[j]<a<i>) then
set aux = a<i>
set a<i> = a[j]
set a[j] = aux
endif
set j=j+1
endloop
set i=i+1
endloop
endfunction</i></i></i>
struct integerpair extends ordered
integer x
integer y
method operator< takes integerpair b returns boolean
if (b.x==this.x) then
return (this.y<b.y)
endif
return (this.x<b.x)
endmethod
endstruct
type ipairarray extends integerpair array [400]
struct integerpairarray extends indexed
ipairarray data
method operator[] takes integer index returns ordered
return ordered( this.data[index] )
endmethod
method operator[]= takes integer index, ordered value returns nothing
set this.data[index] = integerpair( value)
endmethod
endstruct
struct X
integer a=2
integer b=2
method operator x takes nothing returns integer
return this.a*this.b
endmethod
method operator x= takes integer v returns nothing
set this.a=v/this.b
endmethod
endstruct
function test takes nothing returns nothing
local X obj= X.create()
set obj.x= obj.x + 4
call BJDebugMsg(I2S( obj.x) ) //outputs 8
set obj.b=4
call BJDebugMsg(I2S( obj.x) ) //outputs 16
endfunction
You can use this to implement read only fields:
struct X
private integer va=2
method operator a takes nothing returns integer
return this.a
endmethod
endstruct
function test takes nothing returns nothing
local X obj= X.create()
call BJDebugMsg(I2S( obj.a) ) //This is legal
set obj.a=2 //this is not
endfunction
struct movableEffect
private unit dummy
private string rfx
private effect uniteffect
//...
//(A lot of code implementing other actions and creation)
//...
method operator x takes nothing returns real
return GetUnitX(this.dummy)
endmethod
method operator y takes nothing returns real
return GetUnitY(this.dummy)
endmethod
method operator x= takes real value returns nothing
call SetUnitX(this.dummy, value)
endmethod
method operator y= takes real value returns nothing
call SetUnitY(this.dummy, value)
endmethod
method operator effectpath takes nothing returns string
return this.rfx
endmethod
method operator effectpath= takes string path returns nothing
set this.rfx=path
call DestroyEffect( this.uniteffect)
set this.uniteffect = AddSpecialEffectTarget(this.dummy, path, "origin")
endmethod
endstruct
function moveRandom takes movableEffect me returns nothing
set me.x= me.x + GetRandomReal(-50,50)
set me.y= me.y + GetRandomReal(-50,50)
endfunction
function toFire takes movableEffect me returns nothing
set me.effectpath ="war3mapimporte\\cutefireeffect.mdl"
endfunction
Class Person
Private sFirstName As String
Private sLastName As String
Public Property FirstName As String
Get
return sFirstName
End Get
Set (value As String)
sFirstName = value
End Set
End Property
Public Property LastName As String
Get
return sLastName
End Get
Set (value As String)
sLastName = value
End Set
End Property
Public ReadOnly Property FullName As String
Get
return sFirstName + " " + sLastName
End Get
End Property
End Class
Dim oPerson As New Person
oPerson.sFirstName = "Brock" 'ERROR! sFirstName is private you can't access it.
oPerson.sLastName = "Lesnar" 'ERROR! sLastName is private you can't access it.
oPerson.FirstName = "Randy" 'No error. It calls the "Set" in the "FirstName" property using the "Randy" as the value
oPerson.LastName = "Couture" 'No error. It calls the "Set" in the "LastName" property using the "Couture" as the value
MessageBox.Show(oPerson.FullName) 'No error. It will display a messagebox that says "Randy Couture"
struct Person
private string sFirstName
private string sLastName
method operator FirstName takes nothing returns string
return sFirstName
endmethod
method operator FirstName= takes string sName returns nothing
set .sFirstName = sName
endmethod
method operator LastName takes nothing returns string
return sLastName
endmethod
method operator FirstName= takes string sName returns nothing
set .sLastName = sName
endmethod
method operator FullName takes nothing rturns string
return .sFirstName + " " + .sLastName
endmethod
endstruct
local Person p = Person.create()
set p.sFirstName = "Brock" //ERROR! sFirstName is private you can't access it.
set p.sLastName = "Lesnar" //ERROR! sLastName is private you can't access it.
set p.FirstName = "Randy" //No error. It calls the FirstName= operator using "Randy" as the sName
set p.LastName = "Couture" //No error. It calls the LastName= operator using "Couture" as the sName
call BJDebugMsg(p.FullName) //No error. It will display a message that says "Randy Couture"
*disgusted*.NET
Not my fault.ey I started with normal C++ but in my job search I noticed *everyone* that was hiring wanted people that know C# or VB.NET.
Myth..NET isn't all bad. It might have a lot of unnecessary things in it, but given the same project, 1 using .NET and 1 not using .NET, the one that uses .NET will be way easier and faster to finish.
struct GC
static method operator [] takes handle h returns integer
//You could probably just use a constant key for otherKey there
return GetStoredInteger (myCache, I2S (H2I (h)), otherKey)
endmethod
static method operator []= takes handle h, integer i returns nothing
call StoreInteger (myCache, I2S (H2I (h)), otherKey, i)
endmethod
endstruct
...
local StructName data = StructName.create ()
local timer t = CreateTimer ()
set GC[t] = data
...
local StructName data = GC[GetExpiredTimer ()]