[C++-sig] handling const uint8_t* return type

Scott McKay skottmckay at gmail.com
Wed Jul 20 18:00:54 CEST 2005


I have a class with the following method:

class X {
...
  public:
    
    const uint8_t *data( size_t *length = NULL ) const;
...
}

Using pyste, I added a wrapper...

str dataWrapper( X *x ) {
    size_t len = 0;
    const uint8_t *data = x->data( &len );
    return ( str( reinterpret_cast<const char*>(data), len ) );
}

with 

set_wrapper( X.data, dataWrapper )

First question. Should pyste check for a wrapper being set before
emitting the 'Error - no policy specified' message, or are there time
when you want that error? As there's a wrapper the method is not
returning a pointer any more.

Second question. Is this the best way to handle a const uint8_t *
return which is returning an internally held buffer (that is
essentially a string), or could I do this with a more general
convertor that could be used anywhere?


FWIW The relevant bits of the generated code is the simple...

    class_< X >("X", init<  >())
        .def(init< const X& >())
        .def("data", &dataWrapper)
...
    

Thanks

S



More information about the Cplusplus-sig mailing list