I have an idl definition as follow
typedef sequence<octet> ByteArray;
interface Connection {
ByteArray get_id ();
}
And there is this client side code
ByteArray * idToEncrypt = connection->get_id();
encryptId(idToEncrypt);
... // rest of code
The function encryptId() has the signature ByteArray* encryptId(ByteArray* idToEncrypt). I cannot change this signature.
For automatic memory handling, the type of idToEncrypt was changed to ByteArray_var. The problem is I dont know how to get 'ByteArray *' from ByteArray_var and pass it to encryptId().
Is there a way to automatically handle memory allocated "idToEncrypt" and still pass it to encryptId() as "ByteArray *"?
You should look at the
_varC++ mapping in the CORBA specs.For a sequence type var, I think the best approach might be to use the
inout()member, i.e.:inoutreturns a non-const reference and you're just taking the address of the underlying object with&.Do note:
inoutdoes dereference the internal pointer, so it would be illegal to callinout()on a_varthat doesn't hold a pointer. However, the call to get_id() must always return a valid pointer, so the code is OK without checking.If you need a generic approach where you don't know if the
_varis initialized, you could use:as
operator->seems to be the only way to directly get at the pointer.