[omniORB] Pointer from a _var?
Sai-Lai Lo
s.lo@uk.research.att.com
Thu, 21 Jun 2001 17:07:34 -0000
While all the suggestions so far all seem quite reasonable, I don't think
any of these are compliant usage.
It may help by remembering that all access to the sequence managed by the
_var type must be done via the operator->().
For example,
sequencedata_var s;
s = new sequencedata;
s->length(10);
The mapping does not say there is a conversion operator to convert a _var
type to a sequence pointer. Therefore, it is not compliant usage to do
something like this:
sequencedata_var s;
...
sequencedata* p = (sequencedata*)s;
omniORB does not provide a conversion operator to do this so the code will
not compile.
Coming back to the original question, how do we test if the pointer managed
by the _var type is NULL? The answer is there isn't one!
One might think that one could do somthing like this;
if (s.operator->() == 0) {
....
}
This is in fact non-compliant usage that has been explicitly pointed out in
the spec.
In the C++ mapping, section T_var Types:
"The default constructor creates a T_var containing a null T*. Compliant
applications may not attempt to convert a T_var created with the default
constructor into a T* nor use its overloaded operator-> without first
assigning to it a valid T* or another valid T_var."
May be you can rework your program logic to remove the need to check for
null in a _var type.
Sai-Lai
----- Original Message -----
From: "John Hedges" <john@drystone.co.uk>
To: <omniorb-list@uk.research.att.com>
Sent: Thursday, June 21, 2001 9:52 AM
Subject: RE: [omniORB] Pointer from a _var?
> > The pointer inside the sequence would always be valid, unless the length
> of the sequence is 0. So you could indirectly test the pointer through the
> sequence's length() metod.
> > For arithmetics inside the sequence buffer you have the [] operator.
> >
> > -Haarek-
>
> Trouble is that using length() on an unititialised sequence is dangerous.
> It would probably be best to think of a way other than testing for NULL on
> a sequence - like having zero length sequences instead as Haarek suggests.
> However using ss.operator->() returns the value of the underlying T*
> despite being a bit wierd to look at :)
>
> John
>
>
> >
> > Bruce Fountain wrote:
> >
> > > Stephen Crawley wrote:
> > > > You need to get the contents of the _var. Try this:
> > > >
> > > > // Client.cpp
> > > > Foo::ShortSeq_var ss;
> > > > if (*ss == 0)
> > > > {
> > > > std::cout << "ss is null\n";
> > > > }
> > >
> > > I just tried this. It produces the identical error on compilation
> > > (ie. still trying to find an == operator for FooShortSeq_var),
> > > which would suggest that dereferencing using * doesn't give me a
> > > (FooShortSeq*).
> > >
> > > Bruce
> >
> > --
> > Haarek Ryeng
> > Senior Software Development Engineer
> > Data Respons AS, Sandviksvn. 26,N-1323 HOEVIK, Norway.
> > Tel: +47 67112071 Mob: +47 90196734
> >
> > Embedded Computers & Realtime Professionals
> > www.datarespons.no
> >
> >
> >
>
>