From: stephan b. <sg...@us...> - 2004-12-30 19:17:44
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25042 Added Files: proxyGen in.proxyGen Log Message: egg: experimental helper script to generate s11n proxies from a small description file --- NEW FILE: in.proxyGen --- # # format: # START CLASS: # CLASSNAME: # PROPERTIES: # = KEY GETTERFUNC SETTERFUNC # CHILDREN: # + KEY GETTERFUNC SETTERFUNC MyTestType: = name getName setName + license getLicenseText setLicenseText + authors getAuthors setAuthors + about getAboutText setAboutText --- NEW FILE: proxyGen --- #!/usr/bin/perl @sout = (); @dout = (); $classname = 'MyClass'; $SNS = "::P::s11n"; while(<>) { chomp; $orig = $_; $line = $_; next unless $line =~ m|\w|; # empty line next if( $line =~ m|^\s*#| ); # comment line if( $line =~ m|^\s*(\S+)\:\s*$| ) { # CLASSNAME: $classname = $1; $pname = $classname.'_s11n'; next; } $line =~ s|\s+| |g; $line =~ s|^\s*||; ($op,$key,$get,$set) = split( /\s+/, $line ); if( ! $set || !$get ) { die "Syntax error. Line:\n$orig\n"; } if( '=' eq $op ) { # property # print "Adding property '$key'\n"; push( @sout, "$SNS\::serialize_subnode( dest, \"$key\", src.$get\(\) ) || return false;" ); push( @gout, "$SNS\::deserialize_subnode( TR::get( src, \"$key\", dest.$get\(\) ) ) || return false" ); next; } if( '+' eq $op ) { # print "Adding child '$key'\n"; push( @sout, "TR::set( dest, \"$key\", src.$get\(\) );" ); push( @gout, "dest.$set\( TR::get( src, \"$key\", dest.$get\(\) ) );" ); next; } die "Unhandled input line:\n$line\n"; } $dser = "\t".join( "\n\t", @gout ); $sep = "\n\t\t"; print <<EOF struct $pname { // serialize template <typename NodeType> bool operator()( NodeType & dest, const $classname & src ) const { typedef $SNS\::node_traits<NodeType> TR; TR::class_name( dest, "$classname" ); EOF ; print "\t\t"; print join( $sep, @sout ); print "\n"; print <<EOF return true; } // deserialize template <typename NodeType> bool operator()( const NodeType & src, $classname & dest ) const { typedef $SNS\::node_traits<NodeType> TR; EOF ; print "\t\t"; print join( $sep, @gout ); print "\n"; print <<EOF return true; }; } EOF ; |