I am taking my first steps into XS in order to wrap a C++ library. The library implements a rather specialized compression algorithm and can be found here. I've managed to implement and successfully test the bindings using ExtUtils::XSpp. However, right now the classes and methods are just bare stubs to the C++ counterparts, and I would like to be able to make the interface more "perlish" - e.g. instead of writing
I would like to write:my $reader = Compress::DSRC::Archive->new; my $seq = Compress::DSRC::FastqRecord->new; while ($reader->next_seq($seq)) { # do something with $seq }
my $reader = Compress::DSRC::Archive->new; while (my $seq = $reader->next_seq) { # do something with $seq }
I have a lot to learn about XS and this may turn out to be a simple problem, but I would appreciate any examples or pointers to the relevant documentation (especially examples). Since this is a matter of interface rather than function it is not a high priority, but it would be nice to make the interface consistent with the most typical perl syntax. Thanks in advance for any help. A truncated snippet of my *.xsp file is below.
#include "Globals.h" #include "FastqRecord.h" #include "FastqFile.h" #include "DsrcModule.h" #include "DsrcArchive.h" #include "ns.h" %module{Compress::DSRC}; %loadplugin{feature::default_xs_typemap}; %name{Compress::DSRC::FastqRecord} class FastqRecord { %name{new} FastqRecord(); ~FastqRecord(); std::string tag %get %set; std::string sequence %get %set; std::string plus %get %set; std::string quality %get %set; }; %name{Compress::DSRC::Archive} class DsrcArchive { %name{new} DsrcArchive(); ~DsrcArchive(); %name{start_decompress} void StartDecompress(std::string& filename +_); %name{next_seq} bool ReadNextRecord(FastqRecord& rec_); %name{finish_decompress} void FinishDecompress(); [..truncated...] };
In reply to "Perlifying" an XSpp method by jdv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |