Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
48
Task/Singleton/PureBasic/singleton-1.basic
Normal file
48
Task/Singleton/PureBasic/singleton-1.basic
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
Global SingletonSemaphore=CreateSemaphore(1)
|
||||
|
||||
Interface OO_Interface ; Interface for any value of this type
|
||||
Get.i()
|
||||
Set(Value.i)
|
||||
Destroy()
|
||||
EndInterface
|
||||
|
||||
Structure OO_Structure ; The *VTable structure
|
||||
Get.i
|
||||
Set.i
|
||||
Destroy.i
|
||||
EndStructure
|
||||
|
||||
Structure OO_Var
|
||||
*VirtualTable.OO_Structure
|
||||
Value.i
|
||||
EndStructure
|
||||
|
||||
Procedure OO_Get(*Self.OO_Var)
|
||||
ProcedureReturn *Self\Value
|
||||
EndProcedure
|
||||
|
||||
Procedure OO_Set(*Self.OO_Var, n)
|
||||
*Self\Value = n
|
||||
EndProcedure
|
||||
|
||||
Procedure CreateSingleton()
|
||||
If TrySemaphore(SingletonSemaphore)
|
||||
*p.OO_Var = AllocateMemory(SizeOf(OO_Var))
|
||||
If *p
|
||||
*p\VirtualTable = ?VTable
|
||||
EndIf
|
||||
EndIf
|
||||
ProcedureReturn *p
|
||||
EndProcedure
|
||||
|
||||
Procedure OO_Destroy(*Self.OO_Var)
|
||||
FreeMemory(*Self)
|
||||
SignalSemaphore(SingletonSemaphore)
|
||||
EndProcedure
|
||||
|
||||
DataSection
|
||||
VTable:
|
||||
Data.i @OO_Get()
|
||||
Data.i @OO_Set()
|
||||
Data.i @OO_Destroy()
|
||||
EndDataSection
|
||||
Loading…
Add table
Add a link
Reference in a new issue