summaryrefslogtreecommitdiff
path: root/TAO/tao/Any.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tao/Any.cpp')
-rw-r--r--TAO/tao/Any.cpp1944
1 files changed, 660 insertions, 1284 deletions
diff --git a/TAO/tao/Any.cpp b/TAO/tao/Any.cpp
index 9c936af9a8e..91d8d2aefb7 100644
--- a/TAO/tao/Any.cpp
+++ b/TAO/tao/Any.cpp
@@ -65,10 +65,11 @@ CORBA_Any::value (void) const
CORBA_Any::CORBA_Any (void)
: type_ (CORBA::TypeCode::_duplicate (CORBA::_tc_null)),
- value_ (0),
byte_order_ (TAO_ENCAP_BYTE_ORDER),
cdr_ (0),
- any_owns_data_ (0)
+ any_owns_data_ (0),
+ value_ (0),
+ destructor_ (0)
{
}
@@ -76,42 +77,64 @@ CORBA_Any::CORBA_Any (void)
// and either holds or "consumes" an arbitrary data value satisfying
// the normal binary interface rules.
-CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr tc,
- void *value,
- CORBA::Boolean any_owns_data)
- : type_ (CORBA::TypeCode::_duplicate (tc)),
- value_ (value),
+#if 0
+CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr,
+ void *,
+ CORBA::Environment &ACE_TRY_ENV)
+ : type_ (CORBA::TypeCode::_duplicate (CORBA::_tc_null)),
byte_order_ (TAO_ENCAP_BYTE_ORDER),
cdr_ (0),
- any_owns_data_ (any_owns_data)
+ any_owns_data_ (0),
+ value_ (0),
+ destructor_ (0)
{
- ACE_DECLARE_NEW_CORBA_ENV;
+ ACE_THROW (CORBA::NO_IMPLEMENT ());
+}
- ACE_TRY
- {
- if (this->value_ != 0)
- {
- TAO_OutputCDR stream;
+CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr,
+ void *,
+ CORBA::Boolean,
+ CORBA::Environment &ACE_TRY_ENV)
+ : type_ (CORBA::TypeCode::_duplicate (CORBA::_tc_null)),
+ byte_order_ (TAO_ENCAP_BYTE_ORDER),
+ cdr_ (0),
+ any_owns_data_ (0),
+ value_ (0),
+ destructor_ (0)
+{
+ ACE_THROW (CORBA::NO_IMPLEMENT ());
+}
- // Encode the value.
- stream.encode (this->type_,
- this->value_,
- 0,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
+// All-at-once replacement of the contents of an "Any."
- // Retrieve the start of the message block chain and save it.
- this->byte_order_ = TAO_ENCAP_BYTE_ORDER;
- ACE_NEW (this->cdr_, ACE_Message_Block);
- ACE_CDR::consolidate (this->cdr_, stream.begin ());
- }
- }
- ACE_CATCHANY
- {
- // do nothing
- }
- ACE_ENDTRY;
- ACE_CHECK;
+void
+CORBA_Any::replace (CORBA::TypeCode_ptr,
+ const void *,
+ CORBA::Boolean,
+ CORBA::Environment &ACE_TRY_ENV)
+{
+ ACE_THROW (CORBA::NO_IMPLEMENT ());
+}
+
+void
+CORBA_Any::replace (CORBA::TypeCode_ptr,
+ const void *,
+ CORBA::Environment &ACE_TRY_ENV)
+{
+ ACE_THROW (CORBA::NO_IMPLEMENT ());
+}
+#endif /* 0 */
+
+CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr tc,
+ CORBA::Environment &)
+ : type_ (CORBA::TypeCode::_duplicate (tc)),
+ byte_order_ (TAO_ENCAP_BYTE_ORDER),
+ cdr_ (0),
+ any_owns_data_ (0),
+ value_ (0),
+ destructor_ (0)
+{
+ // ACE_THROW (CORBA::NO_IMPLEMENT ());
}
// Constructor using a message block.
@@ -120,9 +143,10 @@ CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr type,
int byte_order,
const ACE_Message_Block* mb)
: type_ (CORBA::TypeCode::_duplicate (type)),
- value_ (0),
byte_order_ (byte_order),
- any_owns_data_ (0)
+ any_owns_data_ (0),
+ value_ (0),
+ destructor_ (0)
{
ACE_NEW (this->cdr_, ACE_Message_Block);
ACE_CDR::consolidate (this->cdr_, mb);
@@ -130,9 +154,10 @@ CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr type,
// Copy constructor for "Any".
CORBA_Any::CORBA_Any (const CORBA_Any &src)
- : value_ (0),
- cdr_ (0),
- any_owns_data_ (0)
+ : cdr_ (0),
+ any_owns_data_ (0),
+ value_ (0),
+ destructor_ (0)
{
if (src.type_ != 0)
this->type_ =
@@ -155,56 +180,39 @@ CORBA_Any::CORBA_Any (const CORBA_Any &src)
CORBA_Any &
CORBA_Any::operator= (const CORBA_Any &src)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- // check if it is a self assignment
- if (this == &src)
- {
- return *this;
- }
+ // check if it is a self assignment
+ if (this == &src)
+ return *this;
- // Decrement the refcount on the Message_Block we hold, it does not
- // matter if we own the data or not, because we always own the
- // message block (i.e. it is always cloned or duplicated.
- ACE_Message_Block::release ((ACE_Message_Block *) this->cdr_);
- this->cdr_ = 0;
-
- // If we own any previous data, deallocate it.
- this->free_value (ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (this->type_ != 0)
- {
- CORBA::release (this->type_);
- }
+ // Decrement the refcount on the Message_Block we hold, it does not
+ // matter if we own the data or not, because we always own the
+ // message block (i.e. it is always cloned or duplicated.
+ ACE_Message_Block::release ((ACE_Message_Block *) this->cdr_);
+ this->cdr_ = 0;
- // Now copy the contents of the source to ourselves.
- if (src.type_ != 0)
- {
- this->type_ =
- CORBA::TypeCode::_duplicate (src.type_);
- }
- else
- {
- this->type_ =
- CORBA::TypeCode::_duplicate (CORBA::_tc_null);
- }
+ // If we own any previous data, deallocate it.
+ this->free_value ();
- this->any_owns_data_ = 0;
+ if (this->type_ != 0)
+ {
+ CORBA::release (this->type_);
+ }
- this->byte_order_ = src.byte_order_;
- ACE_NEW_RETURN (this->cdr_, ACE_Message_Block, *this);
- ACE_CDR::consolidate (this->cdr_, src.cdr_);
- // Simply duplicate the cdr string here. We can save the decode
- // operation if there's no need to extract the object.
+ // Now copy the contents of the source to ourselves.
+ if (src.type_ != 0)
+ {
+ this->type_ =
+ CORBA::TypeCode::_duplicate (src.type_);
}
- ACE_CATCHANY
+ else
{
- return *this;
+ this->type_ =
+ CORBA::TypeCode::_duplicate (CORBA::_tc_null);
}
- ACE_ENDTRY;
+
+ this->byte_order_ = src.byte_order_;
+ ACE_NEW_RETURN (this->cdr_, ACE_Message_Block, *this);
+ ACE_CDR::consolidate (this->cdr_, src.cdr_);
return *this;
}
@@ -213,84 +221,26 @@ CORBA_Any::operator= (const CORBA_Any &src)
CORBA_Any::~CORBA_Any (void)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- // decrement the refcount on the Message_Block we hold, it does not
- // matter if we own the data or not, because we always own the
- // message block (i.e. it is always cloned or duplicated.
-
- ACE_Message_Block::release (this->cdr_);
- this->cdr_ = 0;
-
- this->free_value (ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (this->type_)
- CORBA::release (this->type_);
- }
- ACE_CATCHANY
- {
- // do nothing
- }
- ACE_ENDTRY;
- ACE_CHECK;
-}
-
-// All-at-once replacement of the contents of an "Any."
-
-void
-CORBA_Any::replace (CORBA::TypeCode_ptr tc,
- const void *value,
- CORBA::Boolean any_owns_data,
- CORBA::Environment &ACE_TRY_ENV)
-{
- // Decrement the refcount on the Message_Block we hold, it does not
+ // decrement the refcount on the Message_Block we hold, it does not
// matter if we own the data or not, because we always own the
- // message block (i.e. it is always cloned or duplicated).
- ACE_Message_Block::release (this->cdr_);
- this->cdr_ = 0;
-
- this->free_value (ACE_TRY_ENV);
- ACE_CHECK;
-
- // Duplicate tc and then release this->type_, just in case tc and
- // type_ are the same thing.
- CORBA::TypeCode_ptr tmp =
- CORBA::TypeCode::_duplicate (tc);
- CORBA::release (this->type_);
- this->type_ = tmp;
+ // message block (i.e. it is always cloned or duplicated.
- this->value_ = ACE_const_cast (void *, value);
- this->any_owns_data_ = any_owns_data;
+ ACE_Message_Block::release (this->cdr_);
this->cdr_ = 0;
- if (value)
- {
- // @@ NW: I think an Any should alway owns the CDR stream,
- // so I removed the check here.
- // if the Any owns the data, we encode the "value" into a CDR stream
- // and store it. We also destroy the "value" since we own it.
- TAO_OutputCDR stream;
- stream.encode (tc,
- value,
- 0,
- ACE_TRY_ENV);
- ACE_CHECK;
+ this->free_value ();
- // Retrieve the start of the message block chain and duplicate it.
- this->byte_order_ = TAO_ENCAP_BYTE_ORDER;
- ACE_NEW (this->cdr_, ACE_Message_Block);
- ACE_CDR::consolidate (this->cdr_, stream.begin ());
- }
+ if (this->type_)
+ CORBA::release (this->type_);
}
+// TAO proprietary methods, used in the implementation of the >>= and
+// <<= operators.
+
void
CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
int byte_order,
- const ACE_Message_Block *mb,
- CORBA::Environment &ACE_TRY_ENV)
+ const ACE_Message_Block *mb)
{
// Decrement the refcount on the Message_Block we hold, it does not
// matter if we own the data or not, because we always own the
@@ -298,8 +248,7 @@ CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
ACE_Message_Block::release (this->cdr_);
this->cdr_ = 0;
- this->free_value (ACE_TRY_ENV);
- ACE_CHECK;
+ this->free_value ();
// Duplicate tc and then release this->type_, just in case tc and
// type_ are the same thing.
@@ -307,8 +256,6 @@ CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
CORBA::release (this->type_);
this->type_ = tmp;
- this->any_owns_data_ = 0;
-
this->byte_order_ = byte_order;
ACE_NEW (this->cdr_, ACE_Message_Block);
ACE_CDR::consolidate (this->cdr_, mb);
@@ -322,7 +269,7 @@ CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
const ACE_Message_Block *mb,
CORBA::Boolean any_owns_data,
void* value,
- CORBA::Environment &ACE_TRY_ENV)
+ CORBA::Any::_tao_destructor destructor)
{
// Decrement the refcount on the Message_Block we hold, it does not
// matter if we own the data or not, because we always own the
@@ -330,9 +277,9 @@ CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
ACE_Message_Block::release (this->cdr_);
this->cdr_ = 0;
- this->free_value (ACE_TRY_ENV);
- ACE_CHECK;
+ this->free_value ();
+ this->any_owns_data_ = any_owns_data;
this->value_ = value;
// Duplicate tc and then release this->type_, just in case tc and
@@ -341,24 +288,24 @@ CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
CORBA::release (this->type_);
this->type_ = tmp;
- this->any_owns_data_ = any_owns_data;
-
this->byte_order_ = byte_order;
ACE_NEW (this->cdr_, ACE_Message_Block);
ACE_CDR::consolidate (this->cdr_, mb);
// We can save the decode operation if there's no need to extract
// the object.
+
+ this->destructor_ = destructor;
}
void
CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
CORBA::Boolean any_owns_data,
void* value,
- CORBA::Environment &ACE_TRY_ENV)
+ CORBA::Any::_tao_destructor destructor)
{
- this->free_value (ACE_TRY_ENV);
- ACE_CHECK;
+ this->free_value ();
+ this->any_owns_data_ = any_owns_data;
this->value_ = value;
// Duplicate tc and then release this->type_, just in case tc and
@@ -367,22 +314,23 @@ CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
CORBA::release (this->type_);
this->type_ = tmp;
- this->any_owns_data_ = any_owns_data;
+ this->destructor_ = destructor;
}
// Free internal data.
void
-CORBA_Any::free_value (CORBA::Environment &ACE_TRY_ENV)
+CORBA_Any::free_value (void)
{
- if (this->any_owns_data_ && this->value_ != 0)
+ if (this->any_owns_data_
+ && this->value_ != 0
+ && this->destructor_ != 0)
{
- // This is not exception safe.
- DEEP_FREE (this->type_, this->value_, 0, ACE_TRY_ENV);
- ACE_CHECK;
- ::operator delete (this->value_);
+ (*this->destructor_) (this->value_);
}
+ this->any_owns_data_ = 0;
this->value_ = 0;
+ this->destructor_ = 0;
}
void
@@ -390,15 +338,9 @@ CORBA_Any::_tao_encode (TAO_OutputCDR &cdr,
TAO_ORB_Core *orb_core,
CORBA::Environment &ACE_TRY_ENV)
{
- // If the Any owns the data, then we have allocated space.
- if (this->value_ != 0)
- {
- (void) cdr.encode (this->type_,
- this->value_,
- 0,
- ACE_TRY_ENV);
- return;
- }
+ // Always append the CDR stream, even when the value_.
+ if (this->cdr_ == 0)
+ ACE_THROW (CORBA::NO_IMPLEMENT ());
TAO_InputCDR in (this->cdr_,
this->byte_order_,
@@ -412,15 +354,7 @@ void
CORBA_Any::_tao_decode (TAO_InputCDR &cdr,
CORBA::Environment &ACE_TRY_ENV)
{
- if (this->value_ != 0)
- {
- // @@ Should we free that value first?
- cdr.decode (this->type_,
- this->value_,
- 0,
- ACE_TRY_ENV);
- return;
- }
+ // Just read into the CDR stream...
// @@ (JP) The following code depends on the fact that
// TAO_InputCDR does not contain chained message blocks,
@@ -454,9 +388,7 @@ CORBA_Any::_tao_decode (TAO_InputCDR &cdr,
// Stick it into the Any. It gets duplicated there.
this->_tao_replace (this->type_,
cdr.byte_order (),
- &mb,
- ACE_TRY_ENV);
- ACE_CHECK;
+ &mb);
}
// insertion operators
@@ -464,264 +396,123 @@ CORBA_Any::_tao_decode (TAO_InputCDR &cdr,
void
CORBA_Any::operator<<= (CORBA::Short s)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::Short *ns;
- ACE_NEW (ns,
- CORBA::Short (s));
- this->replace (CORBA::_tc_short,
- ns,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Short insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << s;
+ this->_tao_replace (CORBA::_tc_short,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (CORBA::UShort s)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::UShort *ns;
- ACE_NEW (ns,
- CORBA::UShort (s));
- this->replace (CORBA::_tc_ushort,
- ns,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::UShort insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << s;
+ this->_tao_replace (CORBA::_tc_ushort,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (CORBA::Long l)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::Long *nl;
- ACE_NEW (nl,
- CORBA::Long (l));
- this->replace (CORBA::_tc_long,
- nl,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Long insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << l;
+ this->_tao_replace (CORBA::_tc_long,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (CORBA::ULong l)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::ULong *nl;
- ACE_NEW (nl,
- CORBA::ULong (l));
- this->replace (CORBA::_tc_ulong,
- nl,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::ULong insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << l;
+ this->_tao_replace (CORBA::_tc_ulong,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (CORBA::LongLong l)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::LongLong *nl;
- ACE_NEW (nl,
- CORBA::LongLong (l));
- this->replace (CORBA::_tc_longlong,
- nl,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::LongLong insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << l;
+ this->_tao_replace (CORBA::_tc_longlong,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (CORBA::ULongLong l)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::ULongLong *nl;
- ACE_NEW (nl,
- CORBA::ULongLong (l));
- this->replace (CORBA::_tc_ulonglong,
- nl,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::ULongLong insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << l;
+ this->_tao_replace (CORBA::_tc_ulonglong,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (CORBA::Float f)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::Float *nf;
- ACE_NEW (nf,
- CORBA::Float (f));
- this->replace (CORBA::_tc_float,
- nf,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Float insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << f;
+ this->_tao_replace (CORBA::_tc_float,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (CORBA::Double d)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::Double *nd;
- ACE_NEW (nd,
- CORBA::Double (d));
- this->replace (CORBA::_tc_double,
- nd,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Double insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << d;
+ this->_tao_replace (CORBA::_tc_double,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
-CORBA_Any::operator<<= (CORBA::LongDouble ld)
+CORBA_Any::operator<<= (CORBA::LongDouble d)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::LongDouble *nld;
- ACE_NEW (nld,
- CORBA::LongDouble (ld));
- this->replace (CORBA::_tc_longdouble,
- nld,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::LongDouble insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << d;
+ this->_tao_replace (CORBA::_tc_longdouble,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
// insertion of Any - copying
void
CORBA_Any::operator<<= (const CORBA_Any& a)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA_Any_ptr na;
- ACE_NEW (na,
- CORBA::Any (a));
- this->replace (CORBA::_tc_any,
- na,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Any copying insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << a;
+ this->_tao_replace (CORBA::_tc_any,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
// insertion of Any - non-copying
void
-CORBA::Any::operator<<= (CORBA::Any_ptr anyptr)
+CORBA::Any::_tao_any_destructor (void *x)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- this->replace (CORBA::_tc_any,
- anyptr,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Any non-copying insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ CORBA::Any *tmp = ACE_static_cast (CORBA::Any*,x);
+ delete tmp;
+}
+
+void
+CORBA::Any::operator<<= (CORBA::Any* a)
+{
+ TAO_OutputCDR stream;
+ stream << *a;
+ this->_tao_replace (CORBA::_tc_any,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin (),
+ 1,
+ a,
+ CORBA::Any::_tao_any_destructor);
}
// implementing the special types
@@ -729,125 +520,51 @@ CORBA::Any::operator<<= (CORBA::Any_ptr anyptr)
void
CORBA_Any::operator<<= (from_boolean b)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::Boolean *nb;
- ACE_NEW (nb,
- CORBA::Boolean (b.val_));
- this->replace (CORBA::_tc_boolean,
- nb,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Boolean insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << b;
+ this->_tao_replace (CORBA::_tc_boolean,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (from_octet o)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::Octet *no;
- ACE_NEW (no,
- CORBA::Octet (o.val_));
- this->replace (CORBA::_tc_octet,
- no,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Octet insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << o;
+ this->_tao_replace (CORBA::_tc_octet,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (from_char c)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::Char *nc;
- ACE_NEW (nc,
- CORBA::Char (c.val_));
- this->replace (CORBA::_tc_char,
- nc,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Char insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << c;
+ this->_tao_replace (CORBA::_tc_char,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (from_wchar wc)
{
- ACE_DECLARE_NEW_CORBA_ENV;
- ACE_TRY
- {
- CORBA::WChar *nwc;
- ACE_NEW (nwc,
- CORBA::WChar (wc.val_));
- this->replace (CORBA::_tc_wchar,
- nwc,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::WChar insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << wc;
+ this->_tao_replace (CORBA::_tc_wchar,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
CORBA_Any::operator<<= (CORBA::TypeCode_ptr tc)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- CORBA::TypeCode_ptr *_tao_tc;
-
- ACE_NEW (_tao_tc,
- CORBA::TypeCode_ptr);
-
- *_tao_tc = CORBA::TypeCode::_duplicate (tc);
- this->replace (CORBA::_tc_TypeCode,
- _tao_tc,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::TypeCode_ptr insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << tc;
+ this->_tao_replace (CORBA::_tc_TypeCode,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
void
@@ -863,9 +580,7 @@ CORBA_Any::operator<<= (const CORBA_Exception &exception)
this->_tao_replace (exception._type (),
TAO_ENCAP_BYTE_ORDER,
- stream.begin (),
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
+ stream.begin ());
}
ACE_CATCHANY
{
@@ -893,29 +608,15 @@ CORBA::Any::operator<<= (const CORBA::Object_ptr obj)
void
CORBA::Any::operator<<= (CORBA::Object_ptr *objptr)
{
- ACE_DECLARE_NEW_CORBA_ENV;
+ if (objptr == 0)
+ return; // @@ Should we raise an exception?
- ACE_TRY
- {
- CORBA::Object_ptr *_tao_object_ptr;
-
- ACE_NEW (_tao_object_ptr,
- CORBA::Object_ptr);
-
- *_tao_object_ptr = *objptr;
- this->replace (CORBA::_tc_Object,
- _tao_object_ptr,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Object_ptr insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << *objptr;
+ delete objptr;
+ this->_tao_replace (CORBA::_tc_Object,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
// Insertion of from_string.
@@ -923,125 +624,105 @@ CORBA::Any::operator<<= (CORBA::Object_ptr *objptr)
void
CORBA_Any::operator<<= (from_string s)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- // If the inserted string is bounded, we create a typecode.
- static CORBA::Long _oc_string [] =
- {
- // CDR typecode octets
- TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky"
- 0 // ... unbounded string to start with
- };
+ TAO_OutputCDR stream;
+ stream << s;
- CORBA::TypeCode_ptr tc = 0;
+ // If the inserted string is bounded, we create a typecode.
+ static CORBA::Long _oc_string [] =
+ {
+ // CDR typecode octets
+ TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky"
+ 0 // ... unbounded string to start with
+ };
- if (s.bound_ > 0)
- {
- // Bounded string.
- _oc_string [1] = s.bound_;
- ACE_NEW (tc,
- CORBA::TypeCode (CORBA::tk_string,
- sizeof _oc_string,
- (char *) &_oc_string,
- 1,
- sizeof (CORBA::String_var)));
- }
- else
- {
- tc = CORBA::_tc_string; // unbounded.
- }
+ CORBA::TypeCode_ptr tc = 0;
- char **tmp;
- // Non-copying.
- if (s.nocopy_)
- {
- ACE_NEW (tmp,
- char* (s.val_));
- }
- // Copying.
- else
- {
- ACE_NEW (tmp,
- char* (CORBA::string_dup (s.val_)));
- }
+ if (s.bound_ > 0)
+ {
+ // Bounded string.
+ _oc_string [1] = s.bound_;
+ // @@ It seems like this could be leaked!
+ ACE_NEW (tc,
+ CORBA::TypeCode (CORBA::tk_string,
+ sizeof _oc_string,
+ (char *) &_oc_string,
+ 1,
+ sizeof (CORBA::String_var)));
+ }
+ else
+ {
+ tc = CORBA::_tc_string; // unbounded.
+ }
- this->replace (tc,
- tmp,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
+ char *tmp;
+ // Non-copying.
+ if (s.nocopy_)
+ {
+ tmp = s.val_;
}
- ACE_CATCHANY
+ else
{
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in bounded string insertion\n")));
+ tmp = CORBA::string_dup (s.val_);
}
- ACE_ENDTRY;
- ACE_CHECK;
+
+ this->_tao_replace (tc,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin (),
+ 1,
+ tmp,
+ CORBA::Any::_tao_any_string_destructor);
}
void
CORBA_Any::operator<<= (from_wstring ws)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- // If the inserted string is bounded, we create a typecode.
- static CORBA::Long _oc_wstring [] =
- {
- // CDR typecode octets
- TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky"
- 0 // ... unbounded string to start with
- };
+ TAO_OutputCDR stream;
+ stream << ws;
- CORBA::TypeCode_ptr tc = 0;
+ // If the inserted string is bounded, we create a typecode.
+ static CORBA::Long _oc_wstring [] =
+ {
+ // CDR typecode octets
+ TAO_ENCAP_BYTE_ORDER, // native endian + padding; "tricky"
+ 0 // ... unbounded string to start with
+ };
- if (ws.bound_ > 0)
- {
- // Bounded string.
- _oc_wstring [1] = ws.bound_;
- ACE_NEW (tc,
- CORBA::TypeCode (CORBA::tk_wstring,
- sizeof _oc_wstring,
- (char *) &_oc_wstring,
- 1,
- sizeof (CORBA::WString_var)));
- }
- else
- {
- tc = CORBA::_tc_wstring; // unbounded.
- }
+ CORBA::TypeCode_ptr tc = 0;
- CORBA::WChar **tmp;
- // Non-copying.
- if (ws.nocopy_)
- {
- ACE_NEW (tmp,
- CORBA::WChar* (ws.val_));
- }
- // Copying.
- else
- {
- ACE_NEW (tmp,
- CORBA::WChar* (CORBA::wstring_dup (ws.val_)));
- }
+ if (ws.bound_ > 0)
+ {
+ // Bounded string.
+ _oc_wstring [1] = ws.bound_;
+ // @@ TODO It seems like this is leaked!
+ ACE_NEW (tc,
+ CORBA::TypeCode (CORBA::tk_wstring,
+ sizeof _oc_wstring,
+ (char *) &_oc_wstring,
+ 1,
+ sizeof (CORBA::WString_var)));
+ }
+ else
+ {
+ tc = CORBA::_tc_wstring; // unbounded.
+ }
- this->replace (tc,
- tmp,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
+ CORBA::WChar *tmp;
+ // Non-copying.
+ if (ws.nocopy_)
+ {
+ tmp = ws.val_;
}
- ACE_CATCHANY
+ else
{
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in bounded wstring insertion\n")));
+ tmp = CORBA::wstring_dup (ws.val_);
}
- ACE_ENDTRY;
- ACE_CHECK;
+
+ this->_tao_replace (tc,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin (),
+ 1,
+ tmp,
+ CORBA::Any::_tao_any_wstring_destructor);
}
// Extraction: these are safe and hence we have to check that the
@@ -1060,24 +741,12 @@ CORBA_Any::operator>>= (CORBA::Short &s) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- s = *(CORBA::Short *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- return stream.read_short (s);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ return stream.read_short (s);
}
ACE_CATCHANY
{
@@ -1101,24 +770,12 @@ CORBA_Any::operator>>= (CORBA::UShort &s) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- s = *(CORBA::UShort *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- return stream.read_ushort (s);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ return stream.read_ushort (s);
}
ACE_CATCHANY
{
@@ -1142,24 +799,12 @@ CORBA_Any::operator>>= (CORBA::Long &l) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- l = *(CORBA::Long *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- return stream.read_long (l);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ return stream.read_long (l);
}
ACE_CATCHANY
{
@@ -1183,24 +828,12 @@ CORBA_Any::operator>>= (CORBA::ULong &l) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- l = *(CORBA::ULong *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- return stream.read_ulong (l);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ return stream.read_ulong (l);
}
ACE_CATCHANY
{
@@ -1224,24 +857,12 @@ CORBA_Any::operator>>= (CORBA::LongLong &l) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- l = *(CORBA::LongLong *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- return stream.read_longlong (l);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ return stream.read_longlong (l);
}
ACE_CATCHANY
{
@@ -1306,24 +927,12 @@ CORBA_Any::operator>>= (CORBA::Float &f) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- f = *(CORBA::Float *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- return stream.read_float (f);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ return stream.read_float (f);
}
ACE_CATCHANY
{
@@ -1347,24 +956,12 @@ CORBA_Any::operator>>= (CORBA::Double &d) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- d = *(CORBA::Double *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- return stream.read_double (d);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ return stream.read_double (d);
}
ACE_CATCHANY
{
@@ -1388,24 +985,12 @@ CORBA_Any::operator>>= (CORBA::LongDouble &ld) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- ld = *(CORBA::LongDouble *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- return stream.read_longdouble (ld);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ return stream.read_longdouble (ld);
}
ACE_CATCHANY
{
@@ -1429,34 +1014,16 @@ CORBA_Any::operator>>= (CORBA::Any &a) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- a = *(CORBA::Any *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- // decode the CDR
- CORBA::TypeCode::traverse_status retval =
- stream.decode (CORBA::_tc_any,
- &a,
- 0,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- return (CORBA::Boolean) ((retval == CORBA::TypeCode::TRAVERSE_CONTINUE)
- ? 1
- : 0);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ if (stream >> a)
+ return 1;
}
ACE_CATCHANY
{
@@ -1475,55 +1042,47 @@ CORBA_Any::operator>>= (const CORBA::Any *&a) const
ACE_TRY
{
- CORBA::Boolean result =
+ a = 0;
+ CORBA::Boolean equivalent =
this->type_->equivalent (CORBA::_tc_any,
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
+ if (!equivalent)
+ return 0;
+
+ if (this->any_owns_data_ && this->value_)
{
- if (this->any_owns_data_ && this->value_)
- {
- a = (CORBA::Any *) this->value_;
- return 1;
- }
- else
- {
- ACE_NEW_RETURN (a,
- CORBA::Any,
- 0);
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- // decode the CDR
- CORBA::TypeCode::traverse_status retval =
- stream.decode (CORBA::_tc_any,
- a,
- 0,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (retval == CORBA::TypeCode::TRAVERSE_CONTINUE)
- {
- return 1;
- }
- else
- {
- delete ACE_const_cast (CORBA::Any *&, a);
- a = 0;
- return 0;
- }
- }
+ a = (CORBA::Any *) this->value_;
+ return 1;
}
else
{
- a = 0;
- return 0;
+ CORBA::Any *x;
+ ACE_NEW_RETURN (x, CORBA::Any, 0);
+ CORBA::Any_var tmp = x;
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ if (!(stream >> tmp.inout ()))
+ return 0;
+
+ ACE_const_cast(CORBA::Any*,
+ this)->_tao_replace (CORBA::_tc_any,
+ 1,
+ ACE_static_cast(CORBA::Any*,tmp),
+ CORBA::Any::_tao_any_destructor);
+
+ ACE_const_cast (CORBA::Any *&, a) = tmp._retn ();
+ return 1;
}
}
ACE_CATCHANY
{
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in CORBA::Any extraction\n")));
+ if (TAO_debug_level > 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("Exception in CORBA::Any extraction\n")));
+ }
}
ACE_ENDTRY;
@@ -1532,63 +1091,46 @@ CORBA_Any::operator>>= (const CORBA::Any *&a) const
}
CORBA::Boolean
-CORBA_Any::operator>>= (char *&s) const
+CORBA_Any::operator>>= (const char *&s) const
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
+ s = 0;
+
CORBA::Boolean result =
this->type_->equivalent (CORBA::_tc_string,
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- s = *(char **) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- if (stream.read_string (s))
- {
- ACE_const_cast (CORBA_Any *,
- this)->any_owns_data_ = 1;
+ if (!result)
+ return 0;
- char **tmp;
+ if (this->any_owns_data_ && this->value_)
+ {
+ s = ACE_static_cast (char *,this->value_);
+ return 1;
+ }
- ACE_NEW_RETURN (tmp,
- char *,
- 0);
- *tmp = s;
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ CORBA::String_var tmp;
+ if (!stream.read_string (tmp.out ()))
+ return 0;
- ACE_const_cast (CORBA_Any *,
- this)->value_ = tmp;
+ ACE_const_cast(CORBA::Any*,
+ this)->_tao_replace (CORBA::_tc_string,
+ 1,
+ tmp.inout (),
+ CORBA::Any::_tao_any_string_destructor);
- return 1;
- }
- else
- {
- s = 0;
- return 0;
- }
- }
- }
- else
- {
- s = 0;
- return 0;
- }
+ s = tmp._retn ();
+ return 1;
}
ACE_CATCHANY
{
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in unbounded string extraction\n")));
}
ACE_ENDTRY;
@@ -1596,124 +1138,57 @@ CORBA_Any::operator>>= (char *&s) const
return 0;
}
-CORBA::Boolean
-CORBA_Any::operator>>= (const char *&s) const
+void
+CORBA_Any::_tao_any_string_destructor (void *x)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- CORBA::Boolean result =
- this->type_->equivalent (CORBA::_tc_string,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- s = *(char **) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- if (stream.read_string ((char *&)s))
- {
- ACE_const_cast (CORBA_Any *,
- this)->any_owns_data_ = 1;
-
- char **tmp;
-
- ACE_NEW_RETURN (tmp,
- char *,
- 0);
-
- *tmp = (char *)s;
-
- ACE_const_cast (CORBA_Any *,
- this)->value_ = tmp;
-
- return 1;
- }
- else
- {
- s = 0;
- return 0;
- }
- }
- }
- else
- {
- s = 0;
- return 0;
- }
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in unbounded string extraction\n")));
- }
- ACE_ENDTRY;
+ char *tmp = ACE_static_cast (char*,x);
+ CORBA::string_free (tmp);
+}
- s = 0;
- return 0;
+void
+CORBA::Any::_tao_any_wstring_destructor (void *x)
+{
+ CORBA::WChar *tmp = ACE_static_cast (CORBA::WChar*,x);
+ CORBA::wstring_free (tmp);
}
CORBA::Boolean
-CORBA_Any::operator>>= (CORBA::WChar *&ws) const
+CORBA_Any::operator>>= (const CORBA::WChar *&s) const
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
+ s = 0;
+
CORBA::Boolean result =
this->type_->equivalent (CORBA::_tc_wstring,
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- ws = *(CORBA::WChar **) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- if (stream.read_wstring (ws))
- {
- ACE_const_cast (CORBA_Any *,
- this)->any_owns_data_ = 1;
-
- CORBA::WChar **tmp;
+ if (!result)
+ return 0;
- ACE_NEW_RETURN (tmp,
- CORBA::WChar *,
- 0);
+ if (this->any_owns_data_ && this->value_)
+ {
+ s = ACE_static_cast (CORBA::WChar *,this->value_);
+ return 1;
+ }
- *tmp = ws;
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_);
+ CORBA::WString_var tmp;
+ if (!stream.read_wstring (tmp.out ()))
+ return 0;
- ACE_const_cast (CORBA_Any *,
- this)->value_ = tmp;
+ ACE_const_cast(CORBA::Any*,
+ this)->_tao_replace (CORBA::_tc_wstring,
+ 1,
+ tmp.inout (),
+ CORBA::Any::_tao_any_wstring_destructor);
- return 1;
- }
- else
- {
- ws = 0;
- return 0;
- }
- }
- }
- else
- {
- ws = 0;
- return 0;
- }
+ s = tmp._retn ();
+ return 1;
}
ACE_CATCHANY
{
@@ -1722,73 +1197,14 @@ CORBA_Any::operator>>= (CORBA::WChar *&ws) const
}
ACE_ENDTRY;
- ws = 0;
return 0;
}
-CORBA::Boolean
-CORBA_Any::operator>>= (const CORBA::WChar *&ws) const
+void
+CORBA::Any::_tao_any_tc_destructor (void *x)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- CORBA::Boolean result =
- this->type_->equivalent (CORBA::_tc_wstring,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- ws = *(CORBA::WChar **) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_);
- if (stream.read_wstring ((CORBA::WChar *&)ws))
- {
- ACE_const_cast (CORBA_Any *,
- this)->any_owns_data_ = 1;
-
- CORBA::WChar **tmp;
-
- ACE_NEW_RETURN (tmp,
- CORBA::WChar *,
- 0);
-
- *tmp = (CORBA::WChar *)ws;
-
- ACE_const_cast (CORBA_Any *,
- this)->value_ = tmp;
-
- return 1;
- }
- else
- {
- ws = 0;
- return 0;
- }
- }
- }
- else
- {
- ws = 0;
- return 0;
- }
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in unbounded wstring extraction\n")));
- }
- ACE_ENDTRY;
-
- ws = 0;
- return 0;
+ CORBA::TypeCode_ptr tmp = ACE_static_cast (CORBA::TypeCode_ptr,x);
+ CORBA::release (tmp);
}
CORBA::Boolean
@@ -1803,32 +1219,30 @@ CORBA_Any::operator>>= (CORBA::TypeCode_ptr &tc) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- tc = *(CORBA::TypeCode_ptr *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
- this->byte_order_);
- CORBA::TypeCode::traverse_status retval =
- stream.decode (CORBA::_tc_TypeCode,
- &tc,
- 0,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- return (CORBA::Boolean) ((retval == CORBA::TypeCode::TRAVERSE_CONTINUE)
- ? 1
- : 0);
- }
- }
- else
+ if (!result)
+ return 0;
+
+ if (this->any_owns_data_ && this->value_)
{
- return 0;
+ tc = ACE_static_cast (CORBA::TypeCode_ptr, this->value_);
+ return 1;
}
+
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
+ this->byte_order_);
+ CORBA::TypeCode_var tmp;
+
+ if (!(stream >> tmp.inout ()))
+ return 0;
+
+ ACE_const_cast(CORBA::Any*,
+ this)->_tao_replace (CORBA::_tc_TypeCode,
+ 1,
+ tmp.in (),
+ CORBA::Any::_tao_any_tc_destructor);
+
+ tc = tmp._retn ();
+ return 1;
}
ACE_CATCHANY
{
@@ -1854,24 +1268,12 @@ CORBA_Any::operator>>= (to_boolean b) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- b.ref_ = *(CORBA::Boolean *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
- this->byte_order_);
- return stream.read_boolean (b.ref_);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
+ this->byte_order_);
+ return stream.read_boolean (b.ref_);
}
ACE_CATCHANY
{
@@ -1895,24 +1297,12 @@ CORBA_Any::operator>>= (to_octet o) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- o.ref_ = *(CORBA::Octet *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
- this->byte_order_);
- return stream.read_octet (o.ref_);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
+ this->byte_order_);
+ return stream.read_octet (o.ref_);
}
ACE_CATCHANY
{
@@ -1936,24 +1326,12 @@ CORBA_Any::operator>>= (to_char c) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- c.ref_ = *(CORBA::Char *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
- this->byte_order_);
- return stream.read_char (c.ref_);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
+ this->byte_order_);
+ return stream.read_char (c.ref_);
}
ACE_CATCHANY
{
@@ -1977,24 +1355,12 @@ CORBA_Any::operator>>= (to_wchar wc) const
ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
- {
- if (this->any_owns_data_ && this->value_)
- {
- wc.ref_ = *(CORBA::WChar *) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
- this->byte_order_);
- return stream.read_wchar (wc.ref_);
- }
- }
- else
- {
- return 0;
- }
+ if (!result)
+ return 0;
+
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
+ this->byte_order_);
+ return stream.read_wchar (wc.ref_);
}
ACE_CATCHANY
{
@@ -2013,47 +1379,50 @@ CORBA_Any::operator>>= (to_string s) const
ACE_TRY
{
- CORBA::Boolean result =
- this->type_->equivalent (CORBA::_tc_string,
- ACE_TRY_ENV);
+ CORBA::ULong kind =
+ this->type_->kind (ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
+ CORBA::TypeCode_var tcvar =
+ CORBA::TypeCode::_duplicate (this->type_);
+
+ while (kind == CORBA::tk_alias)
{
- CORBA::ULong bound = this->type_->length (ACE_TRY_ENV);
+ tcvar = tcvar->content_type (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ kind = tcvar->kind (ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (s.bound_ == bound) // bounds are same
- {
- if (this->any_owns_data_ && this->value_)
- {
- s.val_ = *(char **) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
- this->byte_order_);
- if (stream.read_string (s.val_))
- {
- ACE_const_cast (CORBA_Any *,
- this)->any_owns_data_ = 1;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- }
- else
- {
- return 0;
- }
}
- else
+
+ if (kind != CORBA::tk_string)
+ return 0;
+
+ CORBA::ULong bound = tcvar->length (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+ if (s.bound_ != bound)
+ return 0;
+
+ if (this->any_owns_data_ && this->value_)
{
- return 0;
+ s.val_ = ACE_static_cast (char*,this->value_);
+ return 1;
}
+
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
+ this->byte_order_);
+ CORBA::String_var tmp;
+ if (!stream.read_string (tmp.out ()))
+ return 0;
+
+ ACE_const_cast(CORBA::Any*,
+ this)->_tao_replace (CORBA::_tc_string,
+ 1,
+ ACE_static_cast(char*,tmp),
+ CORBA::Any::_tao_any_string_destructor);
+
+ s.val_ = tmp._retn ();
+ return 1;
}
ACE_CATCHANY
{
@@ -2072,47 +1441,50 @@ CORBA_Any::operator>>= (to_wstring ws) const
ACE_TRY
{
- CORBA::Boolean result =
- this->type_->equivalent (CORBA::_tc_wstring,
- ACE_TRY_ENV);
+ CORBA::ULong kind =
+ this->type_->kind (ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
+ CORBA::TypeCode_var tcvar =
+ CORBA::TypeCode::_duplicate (this->type_);
+
+ while (kind == CORBA::tk_alias)
{
- CORBA::ULong bound = this->type_->length (ACE_TRY_ENV);
+ tcvar = tcvar->content_type (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ kind = tcvar->kind (ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (ws.bound_ == bound) // bounds are same
- {
- if (this->any_owns_data_ && this->value_)
- {
- ws.val_ = *(CORBA::WChar **) this->value_;
- return 1;
- }
- else
- {
- TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
- this->byte_order_);
- if (stream.read_wstring (ws.val_))
- {
- ACE_const_cast (CORBA_Any *,
- this)->any_owns_data_ = 1;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- }
- else
- {
- return 0;
- }
}
- else
+
+ if (kind != CORBA::tk_wstring)
+ return 0;
+
+ CORBA::ULong bound = tcvar->length (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+ if (ws.bound_ != bound)
+ return 0;
+
+ if (this->any_owns_data_ && this->value_)
{
- return 0;
+ ws.val_ = ACE_static_cast(CORBA::WChar *, this->value_);
+ return 1;
}
+
+ TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
+ this->byte_order_);
+ CORBA::WString_var tmp;
+ if (!stream.read_wstring (tmp.out ()))
+ return 0;
+
+ ACE_const_cast(CORBA::Any*,
+ this)->_tao_replace (CORBA::_tc_string,
+ 1,
+ ACE_static_cast(CORBA::WChar*,tmp),
+ CORBA::Any::_tao_any_wstring_destructor);
+
+ ws.val_ = tmp._retn ();
+ return 1;
}
ACE_CATCHANY
{
@@ -2131,38 +1503,53 @@ CORBA_Any::operator>>= (to_object obj) const
ACE_TRY
{
- // Any interface is allowed
- CORBA::Boolean result =
- (this->type_->kind (ACE_TRY_ENV) == CORBA::tk_objref);
+ CORBA::ULong kind =
+ this->type_->kind (ACE_TRY_ENV);
ACE_TRY_CHECK;
- if (result)
+ CORBA::TypeCode_var tcvar =
+ CORBA::TypeCode::_duplicate (this->type_);
+ while (kind == CORBA::tk_alias)
{
- if (this->any_owns_data_ && this->value_)
- {
- // CORBA 2.3 has changed the behavior of this operator. Caller
- // is now responsible for release.
- obj.ref_ =
- CORBA::Object::_duplicate (*(CORBA::Object_ptr *) this->value_);
-
- return 1;
- }
- else
- {
- // @@ This uses ORB_Core instance because we need one to
- // demarshal objects (to create the right profiles for that
- // object), but the Any does not belong to any ORB.
- TAO_InputCDR stream (this->cdr_,
- this->byte_order_,
- TAO_ORB_Core_instance ());
+ tcvar = tcvar->content_type (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
- return (stream >> obj.ref_);
- }
- }
- else
- {
- return 0;
+ kind = tcvar->kind (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
}
+
+ if (kind != CORBA::tk_objref)
+ return 0;
+
+ // It is hard to apply this optimization, because value_ points
+ // to a derived class from CORBA::Object, and with multiple
+ // virtual inheritance. One posibility is to use a helper
+ // function to upcast from void* to CORBA::Object_ptr, but this
+ // is only useful to implement the >>=(to_object) operator,
+ // which is very rarely used.
+ // It is better to just demarshal the object everytime,
+ // specially because the caller is owns the returned object.
+ //
+ // if (this->any_owns_data_ && this->value_)
+ // {
+ // // CORBA 2.3 has changed the behavior of this operator. Caller
+ // // is now responsible for release.
+ // obj.ref_ =
+ // CORBA::Object::_duplicate (
+ // (*this->upcast_) (this->value_)
+ // );
+ // return 1;
+ // }
+
+ // @@ This uses ORB_Core instance because we need one to
+ // demarshal objects (to create the right profiles for that
+ // object), but the Any does not belong to any ORB.
+ TAO_InputCDR stream (this->cdr_,
+ this->byte_order_,
+ TAO_ORB_Core_instance ());
+
+ if (stream >> obj.ref_)
+ return 1;
}
ACE_CATCHANY
{
@@ -2180,102 +1567,91 @@ CORBA_Any::operator>>= (to_object obj) const
void
CORBA_Any::operator<<= (const char* s)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- char **tmp;
-
- ACE_NEW (tmp,
- char * (CORBA::string_dup (s)));
-
- this->replace (CORBA::_tc_string,
- tmp,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in unbounded string insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << s;
+ this->_tao_replace (CORBA::_tc_string,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
// and the version for unbounded wide string
void
CORBA_Any::operator<<= (const CORBA::WChar* s)
{
- ACE_DECLARE_NEW_CORBA_ENV;
-
- ACE_TRY
- {
- CORBA::WChar **tmp;
-
- ACE_NEW (tmp,
- CORBA::WChar * (CORBA::wstring_dup (s)));
-
- this->replace (CORBA::_tc_wstring,
- tmp,
- 1,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- ACE_CATCHANY
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Exception in unbounded wstring insertion\n")));
- }
- ACE_ENDTRY;
- ACE_CHECK;
+ TAO_OutputCDR stream;
+ stream << s;
+ this->_tao_replace (CORBA::_tc_wstring,
+ TAO_ENCAP_BYTE_ORDER,
+ stream.begin ());
}
CORBA::Boolean
operator<< (TAO_OutputCDR& cdr,
const CORBA::Any &x)
{
- // @@ This function should *not* use the interpreter, there must be
- // a way to do this with just CDR operations!!!!
+ if (!(cdr << x.type ()))
+ return 0;
+
ACE_TRY_NEW_ENV
{
- CORBA::TypeCode::traverse_status status =
- TAO_MARSHAL_ANY::instance ()->encode (0,
- &x,
- 0,
- &cdr,
- ACE_TRY_ENV);
+ TAO_InputCDR input (x._tao_get_cdr (),
+ x._tao_byte_order ());
+ cdr.append (x.type (),
+ &input,
+ ACE_TRY_ENV);
ACE_TRY_CHECK;
-
- if (status== CORBA::TypeCode::TRAVERSE_CONTINUE)
- return 1;
- // else return 0 at the end of the function
}
ACE_CATCH (CORBA_Exception, ex)
{
return 0;
}
ACE_ENDTRY;
- return 0;
+ return 1;
}
CORBA::Boolean
operator>> (TAO_InputCDR &cdr,
CORBA::Any &x)
{
+ CORBA::TypeCode_var tc;
+ if (!(cdr >> tc.out ()))
+ return 0;
+
ACE_TRY_NEW_ENV
{
+ // @@ (JP) The following code depends on the fact that
+ // TAO_InputCDR does not contain chained message blocks,
+ // otherwise <begin> and <end> could be part of
+ // different buffers!
+
+ // This will be the start of a new message block.
+ char *begin = cdr.rd_ptr ();
+
+ // Skip over the next aregument.
CORBA::TypeCode::traverse_status status =
- TAO_MARSHAL_ANY::instance ()->decode (0,
- &x,
- 0,
- &cdr,
- ACE_TRY_ENV);
+ cdr.skip (tc.in (), ACE_TRY_ENV);
ACE_TRY_CHECK;
if (status != CORBA::TypeCode::TRAVERSE_CONTINUE)
- return 0;
+ {
+ return 0;
+ }
+
+ // This will be the end of the new message block.
+ char *end = cdr.rd_ptr ();
+
+ size_t size = end - begin;
+ ACE_Message_Block mb (size + ACE_CDR::MAX_ALIGNMENT);
+ ACE_CDR::mb_align (&mb);
+ ptr_arith_t offset = ptr_arith_t (begin) % ACE_CDR::MAX_ALIGNMENT;
+ mb.rd_ptr (offset);
+ mb.wr_ptr (offset + size);
+ ACE_OS::memcpy (mb.rd_ptr (), begin, size);
+
+ // Stick it into the Any. It gets duplicated there.
+ x._tao_replace (tc.in (),
+ cdr.byte_order (),
+ &mb);
}
ACE_CATCH (CORBA_Exception, ex)
{