chaos.clone: | Functions | Types | Modinfo | Source |
{Example: Type TTest field bla:Tanothertype {clone}' field blub:int field blobber:Tthirdone {noclone}' field blubber:Tquad end type bla will be cloned. blub gets copied, it's not an object. blobber will be ignored. blubber will be reference-copied.}
|
{Example:
Type Ttest field bla:Tanothertype {clone}' field blub:int {keep}' end type erg:ttest=TTest(combine(source,target))
|
{Example:
type Ttest {savemethod}' field path:string field obj:object method save(url:object) local s:TStream = WriteFile(url) 'do save stuff s.close() end method
|
{Example:
type Ttest {init}' field path:string{nosave}' field obj:object{save}' method init() print "ho, I'm gettin' Initialized." print obj.tostring() end method end type}
|
{Example:
type Ttest field path:string{save}' field sound:TSound{loadurlpath}' end type} |
Enjoy.
Hi!
Dieses
Modul ist Donationware. Benutz es wie Du willst, gib es auch gerne an
andere weiter. Wenn Du das Modul gelungen findest und es gern oder
regelmäßig verwendest möchte ich Dich bitten mir eine kleine Spende als
Anerkennung zukommen zu lassen.
Den Link zur Spendeseite findest Du in
der module-info. Desweiteren bitte ich Dich meinen Namen oder den des
Modules in den Credits deiner App einzutragen.
Wenn Du das Modul weiterreichst verändere es bitte NICHT - gebe es
weiter wie es ist.
Wenn Du Fragen betreffend des Modules hast, kontaktiere mich: bladerunner@chaosinteractive.de - www.chaosinteractive.de
{Beispiel: Type Ttest field bla:Tanothertype {clone}' field blub:int field blobber:Tthirdone {noclone}' field blubber:Tquad end type bla wird als neuer Clone mit angelegt. blub wird kopiert, da es kein Objekt ist. blobber wird bei der Kopie ignoriert. blubber wird als Referenz kopiert, da keine Anweisung vorliegt.} |
{Beispiel:
Type Ttest field bla:Tanothertype {clone}' field blub:int {keep}' end type erg:ttest=TTest(combine(source,target)) bla wird als neuer Clone von Source mit angelegt. blub wird behalten, da es mit keep markiert ist.} |
{Beispiel:
type Ttest {savemethod}' field path:string field obj:object method save(url:object) local s:TStream = WriteFile(url) 'do save stuff s.close() end method method load(url:object) local s:TStream = ReadFile(url) 'do load stuff s.close() end method end type} |
{Beispiel:
type Ttest {init}' field path:string{nosave}' field obj:object{save}' method init() print "ho, I'm gettin' Initialized." print obj.tostring() end method end type} |
{Beispiel:
type Ttest field path:string{save}' field sound:TSound{loadurlpath}' end type} |
CloneObject | Clones an object and returns the clone. Any fields that reference an object only get the reference copied unless MetaData contains {Clone} |
CombineObject | Combines two objects (from source-> target). Fields marked with 'keep' will keep what target has in them. Fields marked with 'clone' will get a clone instead of a copie. |
LoadUDObject | This loads a previously saved object from a file or stream. |
LoadUserDefinedObject | Loads an Object from the given stream. Any fields that reference an object (strings and arrays are objects, too!) only get loaded if MetaData contains {Save}. {NoSave} prevents the field from being saved/loaded. |
SaveUDObject | This saves an object to a file or stream. Using metadata it can be specified which fields get saved. All objects (and strings are objects, too!) need to be marked seperately. |
SaveUserDefinedObject | Saves an Object to the given stream. Any fields that reference an object (strings and arrays are objects, too!) only get saved if MetaData contains {Save}. {NoSave} prevents the field from being saved. |
TChaosClone |
Function CloneObject:Object(obj:Object) | |
Description | Clones an object and returns the clone. Any fields that reference an object only get the reference copied unless MetaData contains {Clone} |
Example | SuperStrict Import Chaos.clone Type TMyTest Field a:Int Field b:TMyTest {clone} 'if you clone ist it will be a new instance. Otherwise you get the reference copied. Field c:String Field id:Int {noclone} 'fields that should not get copied at all have to be marked. Global idcount:Int 'Globals don't need to get cloned ;) Method New() a = Rand(6) c = "Hello World!" id = idcount idcount:+ 1 End Method End Type Local instance:TMyTest = New TMyTest instance.b = New TmyTest Local clone:TMyTest = TMyTest(TChaosClone.CloneObject(instance) ) 'no alternative metadata defined, as it is not needed. 'I'm using the TChaosClone method, the wrapped function works the same. instance.c = "Hello Clone!" DebugStop 'now, take a loog at the debugger and see the result. Try it again without the {clone}-Metadata |
Function CombineObject:Object(source:Object , target:Object) | |
Description | Combines two objects (from source-> target). Fields marked with 'keep' will keep what target has in them. Fields marked with 'clone' will get a clone instead of a copie. |
Example | SuperStrict Import Chaos.clone Type TMyTest Field _a:String {keep} 'this field will be kept in the target. Field _b:String Field _obj:TMyTest {clone} 'this field will be cloned to the target Method Set(a:String , b:String) _a = a _b = b End Method End Type Local source:TMyTest = New TMyTest source.Set("Hello" , "World") Local target:TMyTest = New TMyTest target.Set("Goodbye" , "Moon") source._obj = target 'Warning: setting source._obj to source would be cyclic as every new instance would clone itself into itself. 'But: You could add source as source._obj if you didn't {clone} it. Local result:TMyTest = TMyTest(CombineObject(source , target)) DebugStop 'now look at the result |
Function LoadUDObject:Object(url:Object,obj:Object) | |
Description | This loads a previously saved object from a file or stream. |
Function LoadUserDefinedObject:Object(Stream:TStream,obj:Object,loadtype:Int=False,load:String="save",noload:String="nosave",wholeload:String="wholesave",nullinst:Int = False,map:TMap=Null) | |
Description | Loads an Object from the given stream. Any fields that reference an object (strings and arrays are objects, too!) only get loaded if MetaData contains {Save}. {NoSave} prevents the field from being saved/loaded. |
Information | Usage: bla:object = LoadObject(stream,bla). returns: the loaded object. |
Function SaveUDObject(url:Object , obj:Object) | |
Description | This saves an object to a file or stream. Using metadata it can be specified which fields get saved. All objects (and strings are objects, too!) need to be marked seperately. |
Function SaveUserDefinedObject:Object(Stream:TStream,obj:Object,SaveType:Int = False,save:String="save",nosave:String="nosave",wholesave:String="wholesave",map:TMap=Null) | |
Returns | the stored object. |
Description | Saves an Object to the given stream. Any fields that reference an object (strings and arrays are objects, too!) only get saved if MetaData contains {Save}. {NoSave} prevents the field from being saved. |
Type TChaosClone |
Functions Summary | |
---|---|
CloneObject | Clones an object and returns the clone. Any fields that reference an object only get the reference copied unless MetaData contains {Clone} |
Combine | Combines two objects (from source-> target). Fields marked with 'keep' will keep what target has in them. Fields marked with 'clone' will get a clone instead of a copie. |
KeepMode | Sets the overwriting on load and the adjuvant metatags. |
LoadUDObject | This loads a previously saved object from a file or stream. |
Reset | This resets The internal storage. |
ResetMode | Sets wether the internal storage will be automatically reset or not. |
SaveUDObject | This saves an object to a file or stream. Using metadata it can be specified which fields get saved. All objects (and strings are objects, too!) need to be marked seperately. |
SetSaveMethodTags | Sets the tags that manage the automatic method calling. |
Function CloneObject:Object(obj:Object) | |
Description | Clones an object and returns the clone. Any fields that reference an object only get the reference copied unless MetaData contains {Clone} |
Example | SuperStrict Import Chaos.clone Type TMyTest Field a:Int Field b:TMyTest {clone} 'if you clone ist it will be a new instance. Otherwise you get the reference copied. Field c:String Field id:Int {noclone} 'fields that should not get copied at all have to be marked. Global idcount:Int 'Globals don't need to get cloned ;) Method New() a = Rand(6) c = "Hello World!" id = idcount idcount:+ 1 End Method End Type Local instance:TMyTest = New TMyTest instance.b = New TmyTest Local clone:TMyTest = TMyTest(TChaosClone.CloneObject(instance) ) 'no alternative metadata defined, as it is not needed. 'I'm using the TChaosClone method, the wrapped function works the same. instance.c = "Hello Clone!" DebugStop 'now, take a loog at the debugger and see the result. Try it again without the {clone}-Metadata |
Function Combine:Object(source:Object , target:Object) | |
Description | Combines two objects (from source-> target). Fields marked with 'keep' will keep what target has in them. Fields marked with 'clone' will get a clone instead of a copie. |
Function KeepMode(mode:Int = False,keep:String="keep",clone:String="clone",noclone:String = "noclone") | |
Description | Sets the overwriting on load and the adjuvant metatags. |
Function LoadUDObject:Object(url:Object,obj:Object) | |
Description | This loads a previously saved object from a file or stream. |
Function Reset() | |
Description | This resets The internal storage. |
Function ResetMode(mode:Int = True) | |
Description | Sets wether the internal storage will be automatically reset or not. |
Function SaveUDObject:Object(url:Object , obj:Object) | |
Description | This saves an object to a file or stream. Using metadata it can be specified which fields get saved. All objects (and strings are objects, too!) need to be marked seperately. |
Function SetSaveMethodTags(save:String = "savemethod" , loadurl:String = "loadurl" , init:String = "init") | |
Description | Sets the tags that manage the automatic method calling. |
About | Clone and storage functions for objects |
---|---|
License | Donationware. Feel free to contact me @ www.blitzforum.de. Credits are welcome. |
Donate | https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LX2X9TLEHGPKU - Thank you. |
Spenden | https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LAWKKVVJTERHG - Herzlichen Dank. |
Author | Andreas 'BladeRunner' Brennecke |
Version | 1.50, 07.02.10 - Minor changes in interface. Documentation added. Savemethods etc. First release. |
Version | 1.30, 02.02.10 - Multidimensional Arrays supported. Arrays in Arrays supported. Combining of Objects added. |
Version | 1.20, 01.02.10 - Packed into TChaosClone. Added support for TImage, TMap, TList, TBank. Bugfixing. |
Version | 1.10, 30.01.10 - added SaveUserDefinedObject and LoadUserDefinedObject. |
Version | 1.00, 27.03.09 |
Website | Visit www.chaosinteractive.de |