On 08.10.2010 08:21, Sebastian Hoffmann wrote:
> Hi.
> 
> As mentioned earlier on IRC, parameter blocks don't seem to behave as
> they should. I wrote a little test case:
> 
>     def pccommandinput_testmsg1(self,celEntity,args):
>         params = parblock({"string": "foo", "int": 23, "vector":
> csVector3(1,2,3)})
>         print("parameter object             : ", params)
>         print("parameterCount               : ", params.GetParameterCount())
>         print("parameter ID index 0         : ",
> params.GetParameterIDByIndex(0))
>         print("parameter value index 0 val 0: ", params.GetParameterValue(0))
>         print("parameter.keys()             : ", params.keys())
>         print("params[\"string\"]             : ", params["string"])

Note for readers: accessing params by string (params["foo"]) is made
possible by the hack I attached. However, I don't really know if that
'hack' is correct either ;p

> Its output is this:
> 
> ('parameter object             : ', <blcelc.celGenericParameterBlock;
> proxy of <Swig Object of type 'celGenericParameterBlock *' at
> 0x7f1d258b8f88> >)
> ('parameterCount               : ', 3)
> ('parameter ID index 0         : ', 232L)
> ('parameter value index 0 val 0: ', None)
> ('parameter.keys()             : ', [232L, 233L, 234L])
> ('params["string"]             : ', None)
> 
> What I'd expect would be something like:
> 
> ('parameter ID index 0         : ', "string")
> ('parameter value index 0 val 0: ', "foo")
> ('parameter.keys()             : ', ["string", "int", "vector")
> ('params["string"]             : ', "foo")
> 
> Anything else I can help to shed some light on this?

That you see numbers instead of strings for IDs and such is expected -
after all string IDs _are_ just numbers.

Values turning up as 'None' is, of course, wrong.

-f.r.
Index: include/bindings/python/parblock.i
===================================================================
--- include/bindings/python/parblock.i	(revision 4131)
+++ include/bindings/python/parblock.i	(working copy)
@@ -43,8 +43,13 @@
 			return self.value_iterator()
 		def iterkeys(self):
 			return self.key_iterator()
-		def __getitem__(self,i):
-			return self.GetParameter(i)
+		def __getitem__(self, key):
+			# Convenience: allow a string key, fetch string ID for it
+			if isinstance (key, str):
+				keyid = StringSet.Request (key)
+			else:
+				keyid = key
+			return self.GetParameter (keyid)
 		def keys(self):
 			keys = []
 			for idx in xrange(len(self)):
@@ -52,6 +57,15 @@
 			return keys
 		def has_key(self,id):
 			return self.__contains__(id)
+		# Override __contains__ from C++ with a version that accepts strings
+		_old__contains__ = __contains__
+		def _new__contains__(self, key):
+			if isinstance (key, str):
+				keyid = StringSet.Request (key)
+			else:
+				keyid = key
+			return self._old__contains__(keyid)
+		__contains__ = _new__contains__
 		%}
 	CEL_PAR_SET(bool,bool);
 	CEL_PAR_SET(int8,int8);

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Cel-main mailing list
Cel-main@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cel-main

Reply via email to