[ome-users] Inconsistency in C++ gateway interface

josh.moore at gmx.de josh.moore at gmx.de
Tue Apr 21 20:12:24 BST 2009


Hi Mario,

so I'm afraid you're being bitten by a quirk of the C++ Ice
objects. As you know, they're all smart pointers (e.g. RLongPtr) to
prevent memory leaks, which is why you must always dereference them
via "->".

omero::api::LongList in include/omero/Collections.ice is defined as:

        ["java:type:java.util.ArrayList<Long>:java.util.List<Long>"]
            sequence<long> LongList;

so it contains only longs. When you try to add the RLongPtrs to it:

  ids.push_back( rlong(someLongValue) )

what's happening is that a conversion from RLongPtr to long is taking
place. *Unfortunately* this doesn't do what one might expect. All Ice
smart points return true or false (1 or 0) when used as above, for
whether or not the smart pointer has a value (is not null). If you
check the contents of ids, you'll see that it's all 1s, meaning that
the smart points which you tried to add could be dereferenced.

Instead, use:

  pids.push_back(omero::rtypes::rlong((*ip)->getId()->getValue()));

to get the results you want.

Best wishes,
~Josh



Mario Valle writes:
 > I noticed a small inconsistency in the Gateway C++ object.
 > 
 > While getProjects(), getDatasets() and getImages() need a list of RLong values like:
 >       omero::api::LongList ids;
 >       ids.push_back(omero::rtypes::rlong(loginId));
 >       omero::api::ProjectList proj = gateway->getProjects(ids, false);
 > 
 > getPixels() instead needs a single value (obviously), but of type int (or long):
 >       omero::model::PixelsPtr pix = gateway->getPixels(selected_image_idx);
 > 
 > Why are not all the id values passed as int? Or all as Rlong? Or is there a fundamental 
 > difference when using LongLists instead of single values?
 > If you pass the wrong type, there is no compilation error, no runtime error, but nothing
 > is found (by both sets of functions). The real problem is this, otherwise the 
 > inconsistency is really minor.
 > 



More information about the ome-users mailing list