Boost logo

Boost Users :

From: jhr.walter_at_[hidden]
Date: 2002-11-17 03:07:41


----- Original Message -----
From: Nick Toze
To: Boost-Users_at_[hidden]
Sent: Thursday, November 14, 2002 3:32 PM
Subject: [Boost-Users] Using multi_array/matrix to wrap a SAFEARRAY

> Hello,
>
> I haven't really used C++ much (more Java and Eiffel), but now I am
> helping develop a C++ dll that will use matrices alot and will
> probably need to use SAFEARRAY to interface with Visual Basic (either
> directly or via COM). Also the group I'm in need to standardize on a
> matrix representation and it needs to be compatible with NAG.
>
> I've been trying to wrap a SAFEARRAY using a multi_array and I've got
> something that seems to work (see attached), but :-) I'm not sure how
> to go about passing these (i.e. multi_array, multi_array_ref,
> const_multi_array_ref) around as function arguments since they don't
> have any inheritance relationship. Do you have any suggestions on
> that? Maybe template functions could be used, but I'd like to keep my
> code fairly simple since I'm no expert. As an alternative the uBLAS
> container classes look very appropriate since I'll only be passing
> numbers and some of the algorithms could be useful (although I'll
> mostly be using NAG), but I couldn't quite see whether it is possible
> to use a uBLAS matrix as a view onto the data in a SAFEARRAY. Is it
> possible to attach a pointer to an array to a uBLAS matrix?

Yes. We needed to adapt raw pointers in our CLAPACK tests and did this with
the (undocumented) array_adaptor class in storage.hpp. It works along the
lines of Kresimir Fresl's sample:

    double b[] = { 1., 2. };
    array_adaptor<double> aa1 (2, b); // `2' is array size
    vector<double, array_adaptor<double> > v1 (2, aa1);

    double *c = new double[2];
    array_adaptor<double> aa2 (2, c);
    vector<double, array_adaptor<double> > v2 (2, aa2);
    c[0] = 1.; c[1] = 2.;
    cout << v2 (0) << " " << v2 (1) << endl;

Array adaptor uses shared pointers internally, so there are some subtle
semantic differences compared to the other storage containers.

I imagine that it would be another solution to write your own safe_array<>
class along the lines of (un)bounded_array<>.

[snip code]

HTH

Joerg


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net