[omniORB] anys in version 280
Barend Gehrels
barend@geodan.nl
Wed, 20 Oct 1999 15:12:57 +0200
--------------DBA84156A9662441ECEC3157
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
hi,
I've used the code fragments below in omniOrb 2.7.1, which worked. I'm
now porting to 2.8.0, but it results in a crash. It has something to do
with the new any-extraction and/or insertion. I'm using structures of
which one field is an Any field, and sequences of those structures.
Can anyone tell me what I'm doing wrong?
Thanks, Barend
// ----------------------------------
// idl
module OGIS
{
struct NVPair
{
string name;
any value;
};
typedef sequence<NVPair> NVPairSeq;
};
// ----------------------------------
// ----------------------------------
// cpp
ostream& operator<< (ostream &s, const CORBA::Any &a);
ostream& operator<< (ostream &s, const OGIS::NVPair &nv)
{
return s << "<" << nv.name << ">" << nv.value << "</" << nv.name <<
">";
}
ostream& operator<< (ostream &s, const OGIS::NVPairSeq &nv)
{
for (int i = 0; i < nv.length(); i++)
{
s << nv[i] << endl;
}
return s;
}
ostream& operator<< (ostream &s, const CORBA::Any &a)
{
CORBA::Long vl;
CORBA::Double vd;
const char* vs;
const OGIS::NVPairSeq* nvs;
const OGIS::NVPair* nv;
if (a >>= vl) s << vl;
else if (a >>= vd) s << vd;
else if (a >>= vs) s << vs;
else if (a >>= nv) s << (* nv);
else if (a >>= nvs) s << (* nvs);
else
{
s << "Unknown type" << endl;
}
return s;
}
int main(int argc, char **argv)
{
g_Orb = CORBA::ORB_init(argc, argv, "omniORB2");
g_boa = g_Orb->BOA_init(argc, argv, "omniORB2_BOA");
//omniORB::omniORB_27_CompatibleAnyExtraction = true; // makes no
difference
{
OGIS::NVPair Nv;
const char* n = "name";
const char* s = "contents";
//CORBA::Long s = 3; // this instead of previous line goes also wrong
Nv.name = n;
Nv.value <<= s;
OGIS::NVPairSeq Seq;
Seq.length(1);
Seq[0].name = n;
Seq[0].value <<= Nv;
cout << Nv << endl;
cout << Seq << endl; // if I remove this line it does NOT crash
}
return 1;
}
------------------------------
Barend Gehrels
Geodan IT bv, the Netherlands
tel: +31 20 570 7300
fax: +31 20 570 7333
E-mail: barend@geodan.nl
http://www.geodan.nl
------------------------------
--------------DBA84156A9662441ECEC3157
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
hi,
<p>I've used the code fragments below in omniOrb 2.7.1, which worked. I'm
now porting to 2.8.0, but it results in a crash. It has something to do
with the new any-extraction and/or insertion. I'm using structures of which
one field is an Any field, and sequences of those structures.
<br>Can anyone tell me what I'm doing wrong?
<p>Thanks, Barend
<br>
<br>
<p><tt>// ----------------------------------</tt>
<br><tt>// idl</tt>
<br><tt>module OGIS</tt>
<br><tt>{</tt>
<br><tt> struct NVPair</tt>
<br><tt> {</tt>
<br><tt> string name;</tt>
<br><tt> any value;</tt>
<br><tt> };</tt>
<p><tt> typedef sequence<NVPair> NVPairSeq;</tt>
<br><tt>};</tt>
<br><tt>// ----------------------------------</tt>
<br>
<br>
<p><tt>// ----------------------------------</tt>
<br><tt>// cpp</tt>
<br><tt>ostream& operator<< (ostream &s, const CORBA::Any
&a);</tt>
<p><tt>ostream& operator<< (ostream &s, const OGIS::NVPair
&nv)</tt>
<br><tt>{</tt>
<br><tt> return s << "<" << nv.name << ">" <<
nv.value << "</" << nv.name << ">";</tt>
<br><tt>}</tt>
<p><tt>ostream& operator<< (ostream &s, const OGIS::NVPairSeq
&nv)</tt>
<br><tt>{</tt>
<br><tt> for (int i = 0; i < nv.length(); i++)</tt>
<br><tt> {</tt>
<br><tt> s << nv[i] << endl;</tt>
<br><tt> }</tt>
<br><tt> return s;</tt>
<br><tt>}</tt>
<p><tt>ostream& operator<< (ostream &s, const CORBA::Any
&a)</tt>
<br><tt>{</tt>
<br><tt> CORBA::Long vl;</tt>
<br><tt> CORBA::Double vd;</tt>
<br><tt> const char* vs;</tt>
<br><tt> const OGIS::NVPairSeq* nvs;</tt>
<br><tt> const OGIS::NVPair* nv;</tt>
<p><tt> if (a >>= vl) s << vl;</tt>
<br><tt> else if (a >>= vd) s << vd;</tt>
<br><tt> else if (a >>= vs) s << vs;</tt>
<br><tt> else if (a >>= nv) s << (* nv);</tt>
<br><tt> else if (a >>= nvs) s << (* nvs);</tt>
<br><tt> else</tt>
<br><tt> {</tt>
<br><tt> s << "Unknown type" << endl;</tt>
<br><tt> }</tt>
<br><tt> return s;</tt>
<br><tt>}</tt>
<p><tt>int main(int argc, char **argv)</tt>
<br><tt>{</tt>
<br><tt> g_Orb = CORBA::ORB_init(argc, argv, "omniORB2");</tt>
<br><tt> g_boa = g_Orb->BOA_init(argc, argv, "omniORB2_BOA");</tt>
<p><tt> //omniORB::omniORB_27_CompatibleAnyExtraction = true; // makes
no difference</tt>
<p><tt> {</tt>
<br><tt> OGIS::NVPair Nv;</tt>
<p><tt> const char* n = "name";</tt>
<br><tt> const char* s = "contents";</tt>
<br><tt> //CORBA::Long s = 3; // this instead of previous line goes
also wrong</tt>
<br><tt> Nv.name = n;</tt>
<br><tt> Nv.value <<= s;</tt>
<p><tt> OGIS::NVPairSeq Seq;</tt>
<p><tt> Seq.length(1);</tt>
<br><tt> Seq[0].name = n;</tt>
<br><tt> Seq[0].value <<= Nv;</tt>
<p><tt> cout << Nv << endl;</tt>
<br><tt> cout << Seq << endl; // if I remove this line
it does NOT crash</tt>
<br><tt> }</tt>
<p><tt> return 1;</tt>
<p><tt>}</tt>
<p>------------------------------
<br>Barend Gehrels
<br>Geodan IT bv, the Netherlands
<br>tel: +31 20 570 7300
<br>fax: +31 20 570 7333
<br>E-mail: barend@geodan.nl
<br><A HREF="http://www.geodan.nl">http://www.geodan.nl</A>
<br>------------------------------
<br> </html>
--------------DBA84156A9662441ECEC3157--