Index: Makefile.in =================================================================== diff -u -r67c92d72f53bd368ff0fce6555ec803e859d7300 -r8f14fdaf0de110b56e3132a178267f3372a32235 --- Makefile.in (.../Makefile.in) (revision 67c92d72f53bd368ff0fce6555ec803e859d7300) +++ Makefile.in (.../Makefile.in) (revision 8f14fdaf0de110b56e3132a178267f3372a32235) @@ -489,6 +489,7 @@ $(TCLSH) $(src_test_dir_native)/destroy.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/methods.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/method-parameter.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) + $(TCLSH) $(src_test_dir_native)/cget.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/var-access.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/varresolution.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_test_dir_native)/info-method.test -libdir $(PLATFORM_DIR) $(TESTFLAGS) Index: TODO =================================================================== diff -u -rba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd -r8f14fdaf0de110b56e3132a178267f3372a32235 --- TODO (.../TODO) (revision ba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd) +++ TODO (.../TODO) (revision 8f14fdaf0de110b56e3132a178267f3372a32235) @@ -4091,13 +4091,19 @@ accessor methods. - fixed regression test to run all test again correctly + +nsf.c: +- made argument of cget required + +nx.tcl: +- added Tk-style methods "configure" and "cget" +- added additional regression test set for cget and configure ======================================================================== TODO: -- handling of "-cget" without methods -- register cget per default in nx +- why is parametersyntax of famnam incorrect in cget.test - use cget per default instead of accessor methods -- default menchanism for accessor methods +- default mechanism for accessor methods - handling of method names in error messages from nsfAPI.h. The following ? {o __alloc x} {method __alloc not dispatched on valid class} Index: generic/nsf.c =================================================================== diff -u -rba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd -r8f14fdaf0de110b56e3132a178267f3372a32235 --- generic/nsf.c (.../nsf.c) (revision ba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd) +++ generic/nsf.c (.../nsf.c) (revision 8f14fdaf0de110b56e3132a178267f3372a32235) @@ -22014,7 +22014,7 @@ /* objectMethod cget NsfOCgetMethod { - {-argName "name" -type tclobj} + {-argName "name" -type tclobj -required 1} } */ static int Index: generic/nsfAPI.decls =================================================================== diff -u -rba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd -r8f14fdaf0de110b56e3132a178267f3372a32235 --- generic/nsfAPI.decls (.../nsfAPI.decls) (revision ba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd) +++ generic/nsfAPI.decls (.../nsfAPI.decls) (revision 8f14fdaf0de110b56e3132a178267f3372a32235) @@ -246,7 +246,7 @@ } objectMethod cget NsfOCgetMethod { - {-argName "name" -type tclobj} + {-argName "name" -type tclobj -required 1} } objectMethod configure NsfOConfigureMethod { Index: generic/nsfAPI.h =================================================================== diff -u -rba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd -r8f14fdaf0de110b56e3132a178267f3372a32235 --- generic/nsfAPI.h (.../nsfAPI.h) (revision ba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd) +++ generic/nsfAPI.h (.../nsfAPI.h) (revision 8f14fdaf0de110b56e3132a178267f3372a32235) @@ -1856,7 +1856,7 @@ if (unlikely(obj == NULL)) return NsfDispatchClientDataError(interp, clientData, "object", "cget"); - if (objc < 1 || objc > 2) { + if (objc != 2) { return NsfArgumentError(interp, "wrong # of arguments:", method_definitions[NsfOCgetMethodIdx].paramDefs, NULL, objv[0]); @@ -2804,7 +2804,7 @@ {"name", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, {"::nsf::methods::object::cget", NsfOCgetMethodStub, 1, { - {"name", 0, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} + {"name", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, {"::nsf::methods::object::class", NsfOClassMethodStub, 1, { {"class", 0, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} Index: library/nx/nx.tcl =================================================================== diff -u -rba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd -r8f14fdaf0de110b56e3132a178267f3372a32235 --- library/nx/nx.tcl (.../nx.tcl) (revision ba42e7d2b911f631d2bd104eb2e22a9da6f7e1bd) +++ library/nx/nx.tcl (.../nx.tcl) (revision 8f14fdaf0de110b56e3132a178267f3372a32235) @@ -639,6 +639,23 @@ } ###################################################################### + # Provide Tk-style methods for configure and cget + ###################################################################### + Object eval { + :public alias cget ::nsf::methods::object::cget + + :protected alias __configure ::nsf::methods::object::configure + :public method configure {args} { + if {[llength $args] == 0} { + [:info class] info parameter syntax + } else { + : __configure {*}$args + return + } + } + } + + ###################################################################### # Info definition ###################################################################### Index: tests/cget.test =================================================================== diff -u --- tests/cget.test (revision 0) +++ tests/cget.test (revision 8f14fdaf0de110b56e3132a178267f3372a32235) @@ -0,0 +1,167 @@ +# -*- Tcl -*- +package req nx + +package require nx::test +namespace import ::nx::* + +# +# The first test set checks just the basic behavior: +# +Test case cget-simple { + + nx::Class create Person { + :property famnam:required + :property {age:integer,required 0} + :property {friends:0..n ""} + :property sex + + # Create an instance of the class + :create p1 -famnam hugo -age 25 + } + + # + # first, check basic provided values and default + # + ? {p1 cget -age} 25 + ? {p1 cget -famnam} hugo + ? {p1 cget -friends} "" + + # + # error handling: + # - wrong # args + # - wrong parameter + # - parameter without a value + # + ? {p1 cget} {wrong # of arguments: should be "cget name"} + ? {p1 cget -foo} {cannot lookup parameter value for -foo} + ? {p1 cget foo} {cannot lookup parameter value for foo} + ? {p1 cget -class} {cannot lookup parameter value for -class} + ? {p1 cget -sex} {can't read "sex": no such variable} + + # + # Reconfigure the object + # + ? {p1 configure -famnam joe -age 27} "" + + # + # check the new values + # + ? {p1 cget -age} 27 + ? {p1 cget -famnam} joe + + # + # configure without arguments + # + ? {p1 configure} "?-sex value? -famnam ?-age integer? ?-friends value ...? ?-volatile? ?-properties value? ?-noinit? ?-mixin mixinreg ...? ?-class class? ?-filter filterreg ...? ?__initcmd?" + +} + +# +# The second test set checks redirection of configure / cget to slot +# methods "assign" and "get". +# + +Test parameter count 1 +Test case cget-via-slot { + + nx::Class create C { + + # Define a property with a "get" method + :property bar1 { + :public method get { object property} { + incr ::count(cget) + nsf::var::set $object $property + } + } + + # Define a property with a "get" and "assign" method + :property bar2 { + :public method get { object property} { + incr ::count(cget) + nsf::var::set $object $property + } + :public method assign { object property value } { + incr ::count(assign) + nsf::var::set $object $property $value + } + } + + # Create an instance of the class + :create p1 + } + + # + # configure without arguments + # + ? {p1 configure} "?-bar1 value? ?-bar2 value? ?-volatile? ?-properties value? ?-noinit? ?-mixin mixinreg ...? ?-class class? ?-filter filterreg ...? ?__initcmd?" + + # + # test gettin/setting via slots + # + # just a getter: + # + array unset ::count + ? {p1 configure -bar1 100} "" + ? {array get ::count} "" + + ? {p1 cget -bar1} 100 + ? {array get ::count} "cget 1" + + # a getter and a setter: + # + array unset ::count + ? {p1 configure -bar2 100} "" + ? {array get ::count} "assign 1" + + ? {p1 cget -bar2} 100 + ? {array get ::count} "assign 1 cget 1" + +} + +# +# The third test set checks performance of "cget" and "configure". +# +nx::Test parameter count 10000 +Test case cget-performance { + + nx::Class create Person { + :property famnam:required + :property {age:integer,required 0} + :property {friends:0..n ""} + :property sex + + # Define a property with a "get" and "assign" method + :property bar { + :public method get { object property } { + nsf::var::set $object $property + } + :public method assign { object property value } { + nsf::var::set $object $property $value + } + } + + # Create an instance of the class + :create p1 -famnam hugo -age 25 -bar 101 + } + + # + # read properties + # - built-in getter + # - cget + # - dispatch of cget method with full path + # - cget via slot method + ? {p1 age} 25 + ? {p1 cget -age} 25 + ? {p1 ::nsf::methods::object::cget -age} 25 + ? {p1 cget -bar} 101 + + # + # write properties: + # - built-in setter + # - configure + # - configure via slot method + ? {p1 age 27} 27 + ? {p1 configure -age 27} "" + ? {p1 configure -bar 102} "" + +} \ No newline at end of file Index: tests/info-method.test =================================================================== diff -u -r1f666096846419774da5ef6c42150ae1388ba3cd -r8f14fdaf0de110b56e3132a178267f3372a32235 --- tests/info-method.test (.../info-method.test) (revision 1f666096846419774da5ef6c42150ae1388ba3cd) +++ tests/info-method.test (.../info-method.test) (revision 8f14fdaf0de110b56e3132a178267f3372a32235) @@ -128,8 +128,8 @@ ? {::nx::Object info lookup methods -source application} "" ? {::nx::Class info lookup methods -source application} "" - set object_methods "alias contains copy delete destroy eval filter forward info method mixin move private property protected public require variable volatile" - set class_methods "alias class contains copy create delete destroy eval filter forward info method mixin move new private property protected public require variable volatile" + set object_methods "alias cget configure contains copy delete destroy eval filter forward info method mixin move private property protected public require variable volatile" + set class_methods "alias cget class configure contains copy create delete destroy eval filter forward info method mixin move new private property protected public require variable volatile" ? {lsort [::nx::Object info lookup methods -source baseclasses]} $class_methods ? {lsort [::nx::Class info lookup methods -source baseclasses]} $class_methods