[omniORB] Sequence mapping to c++
    Martin Trappel 
    0xCDCDCDCD at gmx.at
       
    Fri Oct  3 08:55:47 BST 2008
    
    
  
Vázquez Landa wrote:
> 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
    
    
More information about the omniORB-list
mailing list