[omniORB] Looking for examples of sequence manipulation

Carlos carlos at canama.net
Fri Mar 30 01:55:07 BST 2007


El jue, 29-03-2007 a las 08:37 -0700, Perham, David A. (Mission Systems)
escribió:
> Thanks for the post. 
> 
> I must still be doing something wrong.
> 
> This is a sample of the code I am trying to implement:
> 
> // IDL
> 
> typedef sequence <EntityInventoryType, 10> EntityInventorySequence ;
> 
> // Impl
> 
> bool ObjectServerImpl::RequestEntityInventory( long EntityId,				                    EntityInventorySequence_out	 EntityInventory ) 
> {
> 	EntityInventorySequence*& ptr =  EntityInventory.ptr() ;
>       (*ptr)[0].InventoryCode = 5 ;
> }

// At first you must allocate memory for the sequence

EntityInventorySequence*& ptr =  EntityInventory.ptr() ;
ptr = new EntityInventorySequence;

// or directly

EntityInventory.ptr() = new EntityInventorySequence;

// Second you must set the sequence length, because is a bounded
// sequence length must be less or equal than the limit
// (10 in your case), I only set an element
// In my previous message I did a mistake if the sequence is unbounded
// the contructor Seq(ULong) sets the maximum sequence length,
// but not the current length so you must indicate the current
// length like to bounded sequence.

ptr->length(1);

// Now you can assign the InventoryCode

(*ptr)[0].InventoryCode = 5;

// and at last because your function is bool f(...)

return true;

I expect this help you.

Cheers

> 
> This builds, however I am not very confident that it is correct, because the .NET intellisensor tool is not filling out the "InventoryCode" when I type "(*ptr)[0].".
> 
> Am I still missing something?
> 
> Thanks again for the help, I still haven't found any examples on the net.
> 
> Take care 
> 
> -----Original Message-----
> From: Carlos [mailto:carlos at canama.net] 
> Sent: Wednesday, March 28, 2007 4:04 PM
> To: Perham, David A. (Mission Systems)
> Cc: omniorb-list at omniorb-support.com
> Subject: Re: [omniORB] Looking for examples of sequence manipulation
> 
> El mié, 28-03-2007 a las 10:48 -0700, Perham, David A. (Mission Systems)
> escribió:
> > Howdy:
> > 
> > Looking for tips on how to manipulate sequences I came across this 
> > example in the mailing list archives.
> > The example demonstrates how to create the sequence in idl, and how to 
> > pass a pointer to the sequence in the implementation code.
> > Unfortunately, it does not show the syntax required to access this 
> > pointer within the implementation after it is created.  In other 
> > words, after
> > 
> >  ptx = new MyInterface::randSeq(len,len,p);
> > 
> > I'd like to do something with the sequence, like assign a value to 
> > something within it.
> > For example if I have declared a sequence like this in IDL Typedef 
> > struct theStruct {
> >         short x ; 
> >         short y ;
> > } theStructType ;
> > Typedef sequence <theStructType> theStructSeq ; Boolean 
> > DoSomethingWithTheStructSeq( out theStructSeq myStructSeq) ;
> > 
> > And the implementation has
> > Bool DoSomethingWithTheStructSeq( theStructSeq_out ss ) {
> >    theStructSeq *& ptx = ss.ptr() ; 
> >    ptx = new theStructSeq(3) ;
> > 
> > }
> > 
> > What is the syntax to assign a value to 'x' within an element of the 
> > sequence?
> 
> (*ptx)[0].x = 29;
> 
> for example
> 
> and if you want to populate all the sequence
> 
> for (CORBA::ULong i = 0; i < ptx->length(); i++) {
> 	(*ptx)[i].x = ...;
> 	(*ptx)[i].y = ...;
> }
> 
> I expect this helps you.
> 
> Cheers.
> 
> > Thanks,
> > Dave P
> > > Howdy,
> > > Hope the following sample helps you.  
> > > 
> > > IDL: > interface MyInterface
> > > {
> > > typedef sequence<octet> randSeq;
> > > void getRandSeq( out randSeq tx ); }
> > > 
> > > Object Implementation:  
> > > void MyInterface_i::getRandSeq( randSeq_out tx )
> >  > {
> > > MyInterface::randSeq*& ptx = tx.ptr(); //.... > CORBA::Octet* p = 
> > > new CORBA::Octet[ len ]; //....
> > > ptx = new MyInterface::randSeq(len,len,p); }
> >  >
> > > Client: > void hello( MyInterface_ptr e ) { MyInterface::randSeq_var 
> > > tx;
> > > e->getRandSeq( tx.out() );
> > > long len = tx.length();
> > > for ( i = 0; i < len; i++ )
> > > {
> > > cout << tx[i] << endl; // access
> >  > }
> > > } 
> > 
> > _______________________________________________
> > omniORB-list mailing list
> > omniORB-list at omniorb-support.com
> > http://www.omniorb-support.com/mailman/listinfo/omniorb-list
> 
> 
> 




More information about the omniORB-list mailing list