Object.Clone Method

BlitzMax Forums/BlitzMax Module Tweaks/Object.Clone Method

N(Posted 2006) [#1]
There are some undesirable consequences of using this. My advice? Don't use it unless you feel like going through it and finding out what's wrong.

Added...

blitz_object.c


blitz_object.h


blitz_string.c


blitz_string.h


Edit: I neglected to mention you will have to modify the blitz_classes.i to look like this:

Object^Null{

	-New()="bbObjectCtor"
	-Delete()="bbObjectDtor"
    -Clone:Object()="bbObjectClone"
	-ToString:String()="bbObjectToString"
	-Compare:Int( otherObject:Object )="bbObjectCompare"
	-SendMessage:Object( message:Object,source:object )="bbObjectSendMessage"
	-_reserved1_()="bbObjectReserved"
	-_reserved2_()="bbObjectReserved"
	-_reserved3_()="bbObjectReserved"
	
}="bbObjectClass"

String^Object{

	.length:Int

    -Clone:Object()="bbStringClone"
    
	-ToString:String()="bbStringToString"
	-Compare:Int(otherObject:Object)="bbStringCompare"
	
	-Find:Int( subString:String,startIndex=0 )="bbStringFind"
	-FindLast:Int( subString:String,startIndex=0 )="bbStringFindLast"
	
	-Trim:String()="bbStringTrim"
	-Replace:String( substring:String,withString:String )="bbStringReplace"

	-ToLower:String()="bbStringToLower"
	-ToUpper:String()="bbStringToUpper"
	
	-ToInt:Int()="bbStringToInt"
	-ToLong:Long()="bbStringToLong"
	-ToFloat:Float()="bbStringToFloat"
	-ToDouble:Double()="bbStringToDouble"
	-ToCString:Byte Ptr()="bbStringToCString"
	-ToWString:Short Ptr()="bbStringToWString"
	
	+FromInt:String( intValue:Int)="bbStringFromInt"
	+FromLong:String( longValue:Long )="bbStringFromLong"
	+FromFloat:String( floatValue:Float )="bbStringFromFloat"
	+FromDouble:String( doubleValue:Double )="bbStringFromDouble"
	+FromCString:String( cString:Byte Ptr )="bbStringFromCString"
	+FromWString:String( wString:short ptr )="bbStringFromWString"
	
	+FromBytes:String( bytes:Byte Ptr,count )="bbStringFromBytes"
	+FromShorts:String( shorts:Short Ptr,count )="bbStringFromShorts"

}AF="bbStringClass"

Array^Object{

	.elementTypeEncoding:Byte Ptr
	.numberOfDimensions:Int
	.sizeMinusHeader:Int
	.length:Int
	
	-Sort( ascending=1 )="bbArraySort"
	-Dimensions:Int[]()="bbArrayDimensions"
	
}AF="bbArrayClass"



Note the addition of the Clone methods to the String and Object classes. It is not added to the Array class because it is already implemented in its base class (which is, obviously, Object).

Have fun.


Hotcakes(Posted 2006) [#2]
Adding this to the BRL mods officially will result in BRL employees having one less topic to ignore whenever I bump it. =]


Dreamora(Posted 2006) [#3]
Great addition :-)
Thanks for sharing it Noel :)
(tried to do it myself but struggled because I didn't know that I had to manually modify the classes.i ... thought all of them were created automatically on build modules)


Dreamora(Posted 2006) [#4]
Warning:
Do not add clone to your BM if you need to use TMap. It won't be able to return anything anymore if clone is added. Don't ask me for the reason ...


Jay Kyburz(Posted 2006) [#5]
I agree, this would be awsome if it was made official.


N(Posted 2006) [#6]
I wouldn't recommend adding it at all. At least not this way. There are some unusual consequences for doing so, and I promise you'll notice them.


Dreamora(Posted 2006) [#7]
Would have been nice if you added that upfront that it is only to look good but not for usage, which is what module tweaks are for ... would have saved me 2 days where I tried to find out why TMap fails to find anything although Keys clearly showed the searched key ...


N(Posted 2006) [#8]
I only found it out recently, so don't blame me.

Edit: Frankly, this is a tweak to the official modules. There is no guarantee of it working or that it won't mess something up. So, once again, don't blame me for your code not working when you decide to use a tweak that isn't part of the official code.