[C++-sig] byte containers

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Oct 4 00:24:52 CEST 2002


--- Leonardo Rochael Almeida <leo at hiper.com.br> wrote:
> 
> I'm officially working with the TerraLib mantainers
> (http://www.terralib.org/) to make Python bindings for it (Dave, you can
> count this one as another boost.python project :-). 
> 
> Part of the functionality of that library concerns map tiling: large
> geo-referenced images are sliced and the tiles are stored in a Database.
> Later on, you can ask the library to return the map of an area and it
> will reassemble the image and return it. What is the best way to pass a
> lump of bytes (with nulls in it) back and forth? Something that I could
> get as a Python String would be nice, but std::string doesn't seem null
> friendly... Ultimately I'll probably be feeding this lump of bytes to
> PIL (Python Imaging Library) to make some final tweaks to the image
> before publishing it on the Web (it's actually a Zope project).
> 
> Any tips?

For prototyping you could use the "flex" type of the scitbx array family to
make pickleable 2-D arryas of "char" or "signed char" or "unsigned char",
whatever is most appropriate. If using the scitbx is to heavy-weight as a final
solution you can later rip out what you need.

To make the flex.char type:

cd scitbx/array_family/boost_python
cp flex_bool.cpp flex_char.cpp

Replace "bool" by "char". Add this near the top of flex_char.cpp (untested):

namespace scitbx { namespace boost_python { namespace pickle_single_buffered {

  inline
  char* to_string(char* start, char const& value)
  {
    *start = value;
    return start + 1;
  }

  template <>
  struct from_string<char>
  {
    from_string(const char* start) : end(start)
    {
      value = *end++;
    }

    char value;
    const char* end;
  };

}}}

Add "flex_char.cpp" to the SConscript and recompile with

libtbx_scons .

as shown in

http://cci.lbl.gov/~rwgk/scitbx/cold_start_redhat_73_csh

You might have to modify the cvs checkout of boost to use the RC_1_29_0 branch
if the trunk turns out to be broken.

HTH,
        Ralf


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com




More information about the Cplusplus-sig mailing list