用VS来使用C#的应该知道有个自动属性,类似于
public int MyProperty { get; set; }他帮你自动生成get/set方法,还帮你把这些方法绑定到该属性上,很方便的说,但是C++的IDE里没有这个功能的,而且我们C++需要写
_declspec(property(put=setJobID, get=getJobID)) unsigned long jobID; void setJobID(unsigned long inJobID); unsigned long getJobID() const;这么多代码来做这些事情,故我用perl写了个简单的脚本,根据变量类型、变量名字和变量读写属性帮我自动生成这些。
my $f = new IO::File("< field.txt");# the file contains type,name,rw/r/w if(!$f) { print("$!\n"); exit(1); }输出这块用的是输出重定向,可以 参考
# 创建STDOUT句柄的一个副本,之后可以关闭STDOUT
open my $oldout, '>&', \*STDOUT or die "Cannot dup STDOUT: $!";
# 重新将STDOUT打开为文件output.txt的句柄
# 在打开文件之前,Perl会将原来保存在STDOUT中的句柄关闭
open STDOUT, '>', 'output.txt' or die "Cannot reopen STDOUT: $!";
# 接下来的默认输出将会写入到output.txt
print "Hello, World!\n";
# 从原有的STDOUT副本中恢复默认的STDOUT
open STDOUT, '>&', $oldout or die "Cannot dup \$oldout: $!";
#!/usr/bin/perl use strict; use warnings; use IO::File; my $f = new IO::File("< field.txt");# the file contains type,name,rw/r/w if(!$f) { print("$!\n"); exit(1); } #stdout -> file open my $oldout, '>&', \*STDOUT or die "Cannot dup STDOUT: $!"; open STDOUT, '>', 'output.txt' or die "Cannot reopen STDOUT: $!"; my $line; my @array; while($line=<$f>) { chomp($line); $array[@array]=[split(/,/,$line,3)]; } my $i; #for $i ( 0 .. $#array ) #{ # print $array[$i][0]." ".$array[$i][1]." ".$array[$i][2]."\n"; #} # _declspec(property(put=setName,get=getname)) # type name; for $i (0..$#array) { my $result = "_declspec(property("; my $type = $array[$i][0]; my $name = $array[$i][1]; my $rw = $array[$i][2]; if ($rw =~ /w/) { $result = $result."put=set".$name.","; } if($rw =~ /r/) { $result = $result."get=get".$name."))"; } $result = $result."\n ".$type." ".$name.";\n"; print $result; } # void setProgress(unsigned long inPercentDone); #unsigned char getProgress() const; for $i (0..$#array) { my $type = $array[$i][0]; my $name = $array[$i][1]; my $rw = $array[$i][2]; my $result =""; if ($rw =~ /w/) { #w $result = $result."void set".$name."(".$type." in".$name.");\n"; } if($rw =~ /r/) { #r $result = $result.$type." get".$name."() const;\n"; } print $result; } #file -> stdout open STDOUT, '>&', $oldout or die "Cannot dup \$oldout: $!"; my $status = system( "notepad.exe output.txt" ); if ($status != 0) { print "Failed to open output.txt"; exit -1; } else { print "Success to open output.txt,please check it !"; } exit 0;