Discussion:
[omniORB] Sequence mapping to c++
Vázquez Landa, David
2008-10-02 20:39:31 UTC
Permalink
Hi,

I'm a total newb to corba, and I'm developing a little application to interact with java and a database and and and... Anyway, I was wondering if there's a way around CORBA's mapping for a sequence. I would like to be able to use a vector in c++. Is it possible to use vectors and CORBA at the same time? If so, how would I define a vector in idl?


Thanks,

David
Michael
2008-10-02 21:11:07 UTC
Permalink
Hi,

this is not possible (ICE provides sth like that but that's a different
story). There are some stunts you can pull off (like providing the
buffer for a sequence etc.) so you can use vectors internally in many
places with no or only little performance penalty, but in general
there's no way around learning how to use corba sequences and cope with
their arcane concept (CORBA's C++ mapping is pre-STL and therefore
completely agnostic).

Check the mailing list archives, this topic has been covered before

michael
Post by Vázquez Landa, David
Hi,
I'm a total newb to corba, and I'm developing a little application to interact with java and a database and and and... Anyway, I was wondering if there's a way around CORBA's mapping for a sequence. I would like to be able to use a vector in c++. Is it possible to use vectors and CORBA at the same time? If so, how would I define a vector in idl?
Thanks,
David
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
Martin Trappel
2008-10-03 11:56:20 UTC
Permalink
Post by Vázquez Landa, David
Hi,
I'm a total newb to corba, and I'm developing a little application to interact with java and a database and and and... Anyway, I was wondering if there's a way around CORBA's mapping for a sequence. I would like to be able to use a vector in c++. Is it possible to use vectors and CORBA at the same time? If so, how would I define a vector in idl?
You can't really get around the sequences on the interface side, but
there's nothing to prevent you from using vector<>s in your implementaton.
Here's what I use for conversion:

template<class SEQ_T, class COLL_T>
inline SEQ_T* assign_stl_value_sequence(SEQ_T* seq, const COLL_T& coll) {
seq->length(coll.size());
int i=0;
BOOST_FOREACH(const COLL_T::value_type& val, coll) {
(*seq)[i++] = val;
}
return seq;
}
...
std::set<double> values;
...
return assign_stl_value_sequence(new DoubleSeq, values);

coll would be a vector. BOOST_FOREACH is easily replaced by a simple for
loop if you don't want to use boost.
If you have a collection of interface pointers you need to use _this().
If you have corba strings you probably want to use
(*seq)[i++] = CORBA::string_dup(val.c_str());

br,
Martin

Loading...