kingkingyyk3
Visitor (Welcome to the Jungle, Baby!)
- Reaction score
- 216
JASS:
////////////////////////////////////////////////////////////////////
// DSS -> Dynamic Struct Storage
// v 2.0.1
//
// ============
// What's DSS?
// ============
// DSS is a struct attachment system that can make
// attaching easier. Getting tired with Table/ABC?
// Use this! =D
//
// ==================
// How to implement?
// ==================
// 1) Copy this library to your map.
// 2) Done.
//
// ==================
// How to use?
// ==================
// For timer attachment : implement DSS_vJassTimerAttachment.
// For trigger attachment : implement DSS_vJasTriggerAttachment.
//
// ===============
// How to attach?
// ===============
// set <structName>[timer] = struct instance.
// <structName>[timer] -> return attached struct
//
// ===========================================
// How to clear the attached timers/triggers?
// ===========================================
// call struct instance.flush()
//
// =====================
// Details :
// =====================
// 1) DSS uses hashtable to store attached data.
// 2) DSS will automatically remove attached data
// when the struct is destroyed.
// 3) Want unit attachment? DSS is not aimed to that. =)
// 4) The speed of this is as fast as Table.
//
// ================
// Requirements :
// ================
// Jasshelper 0.A.2.B or later.
//
//////////////////////////////////////////////////////////////////
library DSS
globals
public hashtable hasht = InitHashtable()
public integer keyz = 0
endglobals
public module vJassTimerAttachment
private static integer dss_keyz
private timer attached_timer
static method operator [] takes timer whichTimer returns thistype
return LoadInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTimer))
endmethod
static method operator []= takes timer whichTimer, thistype whichData returns nothing
call whichData.flush()
call SaveInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTimer),whichData)
set whichData.attached_timer = whichTimer
endmethod
method flush takes nothing returns nothing
call RemoveSavedInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(.attached_timer))
set .attached_timer = null
endmethod
method destroy takes nothing returns nothing
call deallocate()
endmethod
private static method onInit takes nothing returns nothing
set DSS_keyz = DSS_keyz + 1
set thistype.dss_keyz = DSS_keyz
endmethod
endmodule
public module vJassTriggerAttachment
private static integer dss_keyz
private trigger attached_trigger
static method operator [] takes trigger whichTrigger returns thistype
return LoadInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTrigger))
endmethod
static method operator []= takes trigger whichTrigger, thistype whichData returns nothing
call whichData.flush()
call SaveInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTrigger),whichData)
set whichData.attached_trigger = whichTrigger
endmethod
method flush takes nothing returns nothing
call RemoveSavedInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(.attached_trigger))
set .attached_trigger = null
endmethod
method destroy takes nothing returns nothing
call .flush()
call deallocate()
endmethod
private static method onInit takes nothing returns nothing
set DSS_keyz = DSS_keyz + 1
set thistype.dss_keyz = DSS_keyz
endmethod
endmodule
endlibrary
Zinc Plug-in :
JASS:
////////////////////////////////////////////////////////////////////
// DSS -> Dynamic Struct Storage (Zinc)
// v 2.0.1 by kingking
//
// ============
// What's DSS?
// ============
// DSS is a struct attachment system that can make
// attaching easier. Getting tired with Table/ABC?
// Use this! =D
//
// ==================
// How to implement?
// ==================
// 1) Copy this library to your map.
// 2) Done.
//
// ==================
// How to use?
// ==================
// For timer attachment : module DSS_ZincTimerAttachment.
// For trigger attachment : module DSS_ZincTriggerAttachment.
//
// ===============
// How to attach?
// ===============
// set <structName>[timer] = struct instance.
// <structName>[timer] -> return attached struct
//
// ===========================================
// How to clear the attached timers/triggers?
// ===========================================
// call struct instance.flush()
//
// =====================
// Details :
// =====================
// 1) DSS uses hashtable to store attached data.
// 2) DSS will automatically remove attached data
// when the struct is destroyed.
// 3) Want unit attachment? DSS is not aimed to that. =)
// 4) The speed of this is as fast as Table.
//
// ================
// Requirements :
// ================
// Jasshelper 0.A.2.B or later.
// Dynamic Struct Storage
//
//////////////////////////////////////////////////////////////////
//! zinc
library DSSZinc requires DSS {
public module DSS_ZincTimerAttachment {
private static integer dss_keyz;
private timer attached_timer;
static method operator [] (timer whichTimer) -> thistype {
return LoadInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTimer));
}
static method operator []= (timer whichTimer, thistype whichData) {
whichData.flush();
SaveInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTimer),whichData);
whichData.attached_timer = whichTimer;
}
method flush () {
RemoveSavedInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(this.attached_timer));
this.attached_timer = null;
}
method destroy () { deallocate(); }
private static method onInit () {
DSS_keyz += 1;
thistype.dss_keyz = DSS_keyz;
}
}
public module DSS_ZincTriggerAttachment {
private static integer dss_keyz;
private trigger attached_trigger;
static method operator [] (trigger whichTrigger) -> thistype {
return LoadInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTrigger));
}
static method operator []= (trigger whichTrigger, thistype whichData) {
whichData.flush();
SaveInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(whichTrigger),whichData);
whichData.attached_trigger = whichTrigger;
}
method flush () {
RemoveSavedInteger(DSS_hasht,thistype.dss_keyz,GetHandleId(this.attached_trigger));
this.attached_trigger = null;
}
method destroy () { deallocate(); }
private static method onInit () {
DSS_keyz += 1;
thistype.dss_keyz = DSS_keyz;
}
}
}
//! endzinc