[C++-sig] issues wrapping a template class
Roman Yakovenko
roman.yakovenko at gmail.com
Wed Dec 5 07:34:36 CET 2007
On Dec 5, 2007 12:53 AM, Tim Spens <t_spens at yahoo.com> wrote:
>
>
> I've never wrapped a template class before and I'm running into issues.
> I followed the examples at http://language-binding.net/pyplusplus/documentation/how_to.html#how-to-automatically-export-template-functions-class
>
> Here's the template class I'm trying to wrap using boost python:
> namespace C4
> {
> namespace ZEE
> {
> template <class T>
> class u255_buff
> {
> PUBLIC:
> void write(const T * contents, size_t length)
> {
> if (length_ > sizeof(contents_))
> return;
>
> length_ = length;
> ::memcpy(contents_, contents, length);
> }
>
> PROTECTED:
> T contents_[UCHAR_MAX];
> size_t length_;
>
> };
> }
> }
>
> BOOST_PYTHON_MODULE(libzeepy)
> {
> implicitly_convertible<uint8_t const, u255_buff<unsigned char> >();
> implicitly_convertible<std::string const &, u255_buff<unsigned char> >();
>
> class_<u255_buff<unsigned char> >("u255_buff", init<optional<unsigned char> >())
> .def(init<uint8_t const *, size_t>())
> .def(init<std::string const &>())
> .def("write", &u255_buff<unsigned char>::write)
> ;
> }
>
> >>> ...
> I'm not really sure which parameter(s) are incorrect when calling the write function?
>
It has nothing to do with template classes. Next link contains
explanation & solution to your problem
http://language-binding.net/pyplusplus/documentation/functions/transformation/built_in/input_c_buffer.html
http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/code_repository/convenience.py?revision=1032&view=markup
- contains source code for __convenience.pypp.hpp file
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list