3

I am trying to create a Ruby wrapper for dynamic *.so library which deals with image processing. One of the functions convert_x_to_z has a custom typedef input parameter. How can I pass in the vector of A objects if I mapped the A struct

typedef struct image {
    uint16_t image_width;
    uint16_t image_height;
    uint16_t image_depth;
    uint8_t* data;
} A;

into a FFI:Structure like this

 class A  < FFI::Struct
    layout :image_width , :int,
           :image_height, :int,
           :image_depth, :int,
           :data, :pointer
  end

Suppose I have a variable single which is a instance of class A. How can I wrap this into an array of class B, which will represent the vector/array of classes A and pass it as a parameter const B &x to the function int32_t convert_x_to_z?

int32_t convert_x_to_z(
    const B &x,
    uint32_t &t,
    uint8_t* z);

This is the B vector or array struct of A class.

typedef std::vector<A> B;
adamliesko
  • 1,887
  • 1
  • 14
  • 21

1 Answers1

1

You need to do it this way:

int32_t convert_x_to_z_aux(const A &a, uint32_t &t, uint8_t* z) {
    std::vector<A> b(1, a); // create a vector with 1 element
    return convert_x_to_z(b, t, z);
}
vershov
  • 928
  • 4
  • 6
  • Thanks. I do not have an access to the C++ code, it is compiled dynamic library, to which I do not have source files. So this won't really work. I need to do this on a Ruby level. – adamliesko Oct 02 '15 at 10:22
  • @adamliesko, Just create your own library on top of the legacy one. – vershov Oct 02 '15 at 10:56
  • Thanks for this. Could you point me into some kind of guide/tutorial how could I do that? Isn't this http://stackoverflow.com/a/915181/1212336 and obstacle here (if I do not have the source files)? – adamliesko Oct 02 '15 at 12:47