Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scope of a sequence - REALLY NEED HELP

Status
Not open for further replies.

johnstv4

Programmer
Aug 20, 2002
7
0
0
GB
Hi everyone,

I currently have an object that has a sequence of
pointers to another object. Using methods I created I
can insert the pointers into the sequence which is
basically easy. When I call the function of the object
that returns the sequence (so that I can iterate
through it and display it) all goes well. The problem
is that whenever I call it a second time nothing
happens?

Is it correct to assume that once you use the sequence
it immediately goes out of scope? If so then does that
mean that the values which I filled the sequence with
no longer exist? If this is the case then how can I
keep those values and stop the ORB from erasing the
data within the sequence? I think I read somewhere
that you can initialise a sequence with something like
Seq(len,max,buffer,...) but I can't fully remember.
Can this help prevent the ORB from erasing the data so
that it's solely under my control? Has anyone got any
good examples of this?

Your help is very needed and will be much appreciated.


Thanks

John
 
hi johnstv4

for the specs of the sequence type in IDL i can point you the "IDL-C++" mapping, published by OMG as formal/99-07-41.pdf.
Anyway, the return type is an out type, which when goes out of scope can destroy all of its data, depending on the value of the release parameter in the declaration of the type. You can test this value with the accessor function release().
There are differences also depending if the return type is declared as the output of your function, or as an out parameter, or as an inout one.
As a rule of thumb, the responsibility for storage allocation is on the stubs for return types and for out parameters, and on the caller if it is an inout one.
Which means that if you want to retain previous data, you must use inout parameter.

Hope it helps
 
Thanks domenico,

Your advise was very valuable. i'm having some other trouble now regarding sequences. I'm removing elements from sequences using the following server code:


void Customer_impl::remove_account(Account_ptr ptrAccount)
{
CORBA::ULong index = 0;

// First we need to find out at which index the Account is held within the sequence
for (CORBA::ULong i = 0; i < CustomerAccountList->length(); i++)
{
if (CustomerAccountList == ptrAccount)
{
index = i;
break;
}
}

// Now that we know where abouts within the sequence the Account is we can remove it
for (CORBA::ULong j = index; j < CustomerAccountList->length() - 1; j++)
{
CustomerAccountList[j] = CustomerAccountList[j + 1];
}

CustomerAccountList->length(CustomerAccountList->length() - 1);

cout << &quot;Length is &quot; << CustomerAccountList->length() << &quot;\n&quot;;
}


At first all seems fine when the client is removing accounts from the sequence. But for some reason the accounts displayed on the client are sometimes incorrect? For example, when I remove the first account of the sequence it seems to remove the ones that come after it? Could you help me and tell me how I should properly implement code which removes entries from the sequence? Your help is very much appreciated.


Thanks

John


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top