summaryrefslogtreecommitdiff
path: root/TAO/tao
diff options
context:
space:
mode:
authorgokhale <asgokhale@users.noreply.github.com>1998-02-18 18:39:15 +0000
committergokhale <asgokhale@users.noreply.github.com>1998-02-18 18:39:15 +0000
commit09a12a76353ef3d3cf00ed28ee8ad651c689c3f2 (patch)
treef6a7ca9a7e38c1a43982c3f7aab725601d507c86 /TAO/tao
parent182cad8ee1627aab578f30e9e24fa8123b6fe73d (diff)
downloadATCD-09a12a76353ef3d3cf00ed28ee8ad651c689c3f2.tar.gz
*** empty log message ***
Diffstat (limited to 'TAO/tao')
-rw-r--r--TAO/tao/any.cpp292
-rw-r--r--TAO/tao/any.h30
-rw-r--r--TAO/tao/any.i68
3 files changed, 296 insertions, 94 deletions
diff --git a/TAO/tao/any.cpp b/TAO/tao/any.cpp
index 5edd7348d6a..22dea0350d8 100644
--- a/TAO/tao/any.cpp
+++ b/TAO/tao/any.cpp
@@ -300,59 +300,49 @@ CORBA_Any::CORBA_Any (const CORBA_Any &src)
CORBA::Environment env;
size_t size;
- type_->AddRef ();
+ this->type_->AddRef ();
- size = type_->size (env); // XXX check error status
- value_ = (char *) calloc (1, size);
+ size = this->type_->size (env); // XXX check error status
+ this->value_ = (char *) calloc (1, size);
#if 0
- (void) type_->traverse (src.value_,
- value_,
- (CORBA::TypeCode::VisitRoutine) deep_copy,
- 0,
- env);
+ (void) this->type_->traverse (src.value_,
+ value_,
+ (CORBA::TypeCode::VisitRoutine) deep_copy,
+ 0,
+ env);
#endif /* replaced by our optimizations */
- (void) DEEP_COPY (type_, src.value_, value_, env);
+ (void) DEEP_COPY (this->type_, src.value_, this->value_, env);
}
//a&a : Added on 14 feb 1998
CORBA_Any &
CORBA_Any::operator= (const CORBA_Any &src)
-{
+{
if (this == &src)
{
this->AddRef ();
return *this;
}
+ this->Release (); // release any value + typecode we may have
- this->Release ();
-
- type_ = src.type_ != 0 ? src.type_ : CORBA::_tc_null;
-
- orb_owns_data_ = CORBA::B_TRUE;
+ // now copy the contents of the source to ourselves
+ this->type_ = (src.type_) != 0 ? src.type_ : CORBA::_tc_null;
- refcount_ = 1;
+ this->orb_owns_data_ = CORBA::B_TRUE;
+ this->refcount_ = 1;
CORBA::Environment env;
size_t size;
- type_->AddRef ();
-
- size = type_->size (env); // XXX check error status
- value_ = (char *) calloc (1, size);
-
-#if 0
- (void) type_->traverse (src.value_,
- value_,
- (CORBA::TypeCode::VisitRoutine) deep_copy,
- 0,
- env);
-#endif /* replaced by our optimizations */
+ this->type_->AddRef ();
- (void) DEEP_COPY (type_, src.value_, value_, env);
+ size = this->type_->size (env); // XXX check error status
+ this->value_ = (char *) calloc (1, size);
+ (void) DEEP_COPY (this->type_, src.value_, this->value_, env);
return *this;
}
@@ -501,7 +491,7 @@ CORBA_Any::~CORBA_Any (void)
{
CORBA::Environment env;
- // assert (refcount_ == 0);
+ // assert (this->refcount_ == 0);
if (this->orb_owns_data_)
{
@@ -524,23 +514,249 @@ CORBA_Any::replace (CORBA::TypeCode_ptr tc,
CORBA::Boolean orb_owns_data,
CORBA::Environment &env)
{
- if (orb_owns_data_)
+ if (this->orb_owns_data_)
{
// (void) deep_free (type_, value_, 0, 0, env);
if (value_)
- DEEP_FREE (type_, value_, 0, env);
- delete value_;
+ DEEP_FREE (this->type_, this->value_, 0, env);
+ delete this->value_;
}
- if (type_ != 0)
- type_->Release ();
+ if (this->type_ != 0)
+ this->type_->Release ();
env.clear ();
- type_ = tc;
+ this->type_ = tc;
tc->AddRef ();
- value_ = (void *) v;
- orb_owns_data_ = orb_owns_data;
+ this->value_ = (void *) v;
+ this->orb_owns_data_ = orb_owns_data;
+}
+
+// insertion of from_string
+void
+CORBA_Any::operator<<= (from_string s)
+{
+ // 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
+ };
+
+ CORBA::TypeCode_ptr tc;
+ if (s.bound_ > 0)
+ {
+ // bounded string
+ _oc_string [1] = s.bound_;
+ CORBA::TypeCode_ptr tc = new CORBA::TypeCode (CORBA::tk_string,
+ sizeof _oc_string,
+ (u_char *) &_oc_string,
+ CORBA::B_TRUE);
+ }
+ else
+ tc = CORBA::_tc_string; // unbounded
+
+ if (s.nocopy_)
+ this->replace (tc, new char* (s.val_), CORBA::B_TRUE);
+ else // copying
+ this->replace (tc, new char* (CORBA::string_dup (s.val_)),
+ CORBA::B_TRUE);
+}
+
+// extraction: these are safe and hence we have to check that the typecode of
+// the Any is equal to the one we are trying to extract into
+
+CORBA::Boolean
+CORBA_Any::operator>>= (CORBA::Short &s) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_short, env))
+ {
+ s = *(CORBA::Short *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (CORBA::UShort &s) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_ushort, env))
+ {
+ s = *(CORBA::UShort *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (CORBA::Long &l) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_long, env))
+ {
+ l = *(CORBA::Long *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (CORBA::ULong &l) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_ulong, env))
+ {
+ l = *(CORBA::ULong *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (CORBA::Float &f) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_float, env))
+ {
+ f = *(CORBA::Float *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (CORBA::Double &d) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_double, env))
+ {
+ d = *(CORBA::Double *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (CORBA::Any &a) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_any, env))
+ {
+ a = *(CORBA::Any *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (char *&s) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_string, env))
+ {
+ s = *(char **) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+// = extraction into the special types
+
+CORBA::Boolean
+CORBA_Any::operator>>= (to_boolean b) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_boolean, env))
+ {
+ b.ref_ = *(CORBA::Boolean *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (to_octet o) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_octet, env))
+ {
+ o.ref_ = *(CORBA::Octet *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (to_char c) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_char, env))
+ {
+ c.ref_ = *(CORBA::Char *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (to_string s) const
+{
+ CORBA::Environment env;
+
+ // the typecode must be equal. Since we do not readily have access to the
+ // typecode of the string into which we want to retrieve, we emulate the
+ // behavior of "equal"
+ if (this->type_->kind (env) == CORBA::tk_string)
+ {
+ CORBA::ULong bound = this->type_->length (env);
+ if (s.bound_ == bound) // bounds are same
+ {
+ s.val_ = *(char **) this->value_;
+ return CORBA::B_TRUE;
+ }
+ }
+
+ // otherwise
+ return CORBA::B_FALSE;
+}
+
+CORBA::Boolean
+CORBA_Any::operator>>= (to_object obj) const
+{
+ CORBA::Environment env;
+
+ if (this->type_->equal (CORBA::_tc_Object, env))
+ {
+ obj.ref_ = *(CORBA::Object_ptr *) this->value_;
+ return CORBA::B_TRUE;
+ }
+ else
+ return CORBA::B_FALSE;
}
// For COM -- IUnKnown operations
diff --git a/TAO/tao/any.h b/TAO/tao/any.h
index eb253c1084b..af86ad345c5 100644
--- a/TAO/tao/any.h
+++ b/TAO/tao/any.h
@@ -4,7 +4,7 @@
//
// = LIBRARY
// TAO
-//
+//
// = FILENAME
// any.h
//
@@ -15,7 +15,7 @@
// Copyright 1994-1995 by Sun Microsystems, Inc.
//
// Remaining CORBA compliant functions added by Aniruddha Gokhale
-//
+//
// ============================================================================
#if !defined (TAO_ANY_H)
@@ -32,7 +32,7 @@ class TAO_Export CORBA_Any : public TAO_IUnknown
{
public:
// = Minor codes for exceptional returns
- enum
+ enum
{
UNINITIALIZED_type = 0xf000,
VALUE_WITHOUT_TYPE,
@@ -58,7 +58,7 @@ public:
// assignment operator
// = NOTE: 94-9-14 has assignment operator plus many insertion, as specified
- // below
+ // below
// =type safe insertion
@@ -153,7 +153,8 @@ public:
void operator<<= (from_string);
// insert a bounded string
- // special types for extracting octets, chars, booleans, and bounded strings
+ // special types for extracting octets, chars, booleans, bounded strings, and
+ // object references
struct to_boolean
{
@@ -176,15 +177,22 @@ public:
struct to_string
{
to_string (char *&s, CORBA::ULong b);
- char *&ref_;
+ char *&val_;
CORBA::ULong bound_;
};
+ struct to_object
+ {
+ to_object (CORBA::Object_ptr &obj);
+ CORBA::Object_ptr &ref_;
+ };
+
// extraction of the special types
CORBA::Boolean operator>>= (to_boolean) const;
CORBA::Boolean operator>>= (to_octet) const;
CORBA::Boolean operator>>= (to_char) const;
CORBA::Boolean operator>>= (to_string) const;
+ CORBA::Boolean operator>>= (to_object) const;
// = ALLOCATION
void *operator new (size_t, const void *p);
@@ -201,7 +209,7 @@ public:
// replace the current typecode and data with the specified one - unsafe
CORBA::TypeCode_ptr type (void) const;
- // Return <type> of <Any>.
+ // Return TypeCode of the element stored in the Any
const void *value (void) const;
// Return <value> of <Any>.
@@ -213,7 +221,7 @@ public:
TAO_HRESULT QueryInterface (REFIID riid,
void **ppv);
- // = Conversion to/from COM Variant types:
+ // = Conversion to/from COM Variant types:
CORBA_Any (const TAO_VARIANT &src);
// copy constructor,
@@ -251,7 +259,7 @@ private:
class TAO_Export CORBA_Any_var
// = TITLE
- // Provide for automatic storage deallocation on going out of scope.
+ // Provide for automatic storage deallocation on going out of scope.
{
public:
CORBA_Any_var (void);
@@ -327,7 +335,7 @@ public:
CORBA_Any *& ptr (void);
// return underlying instance
-
+
private:
CORBA_Any *&ptr_;
// instance
@@ -337,5 +345,3 @@ private:
};
#endif /* TAO_ANY_H */
-
-
diff --git a/TAO/tao/any.i b/TAO/tao/any.i
index 7a3d679dbca..39bee9ceacf 100644
--- a/TAO/tao/any.i
+++ b/TAO/tao/any.i
@@ -36,49 +36,51 @@ CORBA_Any::replace (CORBA::TypeCode_ptr type,
ACE_INLINE void
CORBA_Any::operator<<= (CORBA::Short s)
{
- replace (CORBA::_tc_short, new CORBA::Short (s), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_short, new CORBA::Short (s), CORBA::B_TRUE);
}
ACE_INLINE void
CORBA_Any::operator<<= (CORBA::UShort s)
{
- replace (CORBA::_tc_ushort, new CORBA::UShort (s), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_ushort, new CORBA::UShort (s), CORBA::B_TRUE);
}
ACE_INLINE void
CORBA_Any::operator<<= (CORBA::Long l)
{
- replace (CORBA::_tc_long, new CORBA::Long (l), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_long, new CORBA::Long (l), CORBA::B_TRUE);
}
ACE_INLINE void
CORBA_Any::operator<<= (CORBA::ULong l)
{
- replace (CORBA::_tc_ulong, new CORBA::ULong (l), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_ulong, new CORBA::ULong (l), CORBA::B_TRUE);
}
ACE_INLINE void
CORBA_Any::operator<<= (CORBA::Float f)
{
- replace (CORBA::_tc_float, new CORBA::Float (f), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_float, new CORBA::Float (f), CORBA::B_TRUE);
}
ACE_INLINE void
CORBA_Any::operator<<= (CORBA::Double d)
{
- replace (CORBA::_tc_double, new CORBA::Double (d), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_double, new CORBA::Double (d), CORBA::B_TRUE);
}
ACE_INLINE void
CORBA_Any::operator<<= (const CORBA_Any& a)
{
- replace (CORBA::_tc_any, new CORBA_Any (a), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_any, new CORBA_Any (a), CORBA::B_TRUE);
}
+// this is a copying version for unbounded strings
ACE_INLINE void
CORBA_Any::operator<<= (const char* s)
{
- replace (CORBA::_tc_string, CORBA::string_dup (s), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_string, new char* (CORBA::string_dup (s)),
+ CORBA::B_TRUE);
}
// implementing the special types
@@ -128,67 +130,46 @@ CORBA_Any::from_string::from_string (char *s, CORBA::ULong b, CORBA::Boolean noc
ACE_INLINE
CORBA_Any::to_string::to_string (char *&s, CORBA::ULong b)
- : ref_ (s),
+ : val_ (s),
bound_ (b)
{
}
-ACE_INLINE void
-CORBA_Any::operator<<= (from_boolean b)
+ACE_INLINE
+CORBA_Any::to_object::to_object (CORBA::Object_ptr &obj)
+ : ref_ (obj)
{
- replace (CORBA::_tc_boolean, new CORBA::Boolean (b.val_), CORBA::B_TRUE);
}
ACE_INLINE void
-CORBA_Any::operator<<= (from_octet o)
+CORBA_Any::operator<<= (from_boolean b)
{
- replace (CORBA::_tc_octet, new CORBA::Octet (o.val_), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_boolean, new CORBA::Boolean (b.val_), CORBA::B_TRUE);
}
ACE_INLINE void
-CORBA_Any::operator<<= (from_char c)
+CORBA_Any::operator<<= (from_octet o)
{
- replace (CORBA::_tc_char, new CORBA::Char (c.val_), CORBA::B_TRUE);
+ this->replace (CORBA::_tc_octet, new CORBA::Octet (o.val_), CORBA::B_TRUE);
}
ACE_INLINE void
-CORBA_Any::operator<<= (from_string s)
-{
- if (s.nocopy_)
- replace (CORBA::_tc_string, s.val_, CORBA::B_TRUE);
- else
- replace (CORBA::_tc_string, CORBA::string_dup (s.val_), CORBA::B_TRUE);
-}
-
-// extraction: these are safe and hence we have to check that the typecode of
-// the Any is equal to the one we are trying to extract into
-
-ACE_INLINE CORBA::Boolean
-CORBA_Any::operator>>= (CORBA::Short &s) const
+CORBA_Any::operator<<= (from_char c)
{
- CORBA::Environment env;
-
- if (type_->equal (CORBA::_tc_short, env))
- {
- s = *(CORBA::Short *) value_;
- return CORBA::B_TRUE;
- }
- else
- return CORBA::B_FALSE;
+ this->replace (CORBA::_tc_char, new CORBA::Char (c.val_), CORBA::B_TRUE);
}
-
// ----------------------------------------------------------------------
// CORBA_Any_var type
// ----------------------------------------------------------------------
-ACE_INLINE
+ACE_INLINE
CORBA_Any_var::CORBA_Any_var (void)
: ptr_ (0)
{
}
-ACE_INLINE
+ACE_INLINE
CORBA_Any_var::CORBA_Any_var (CORBA_Any *p)
: ptr_ (p)
{
@@ -200,7 +181,7 @@ CORBA_Any_var::CORBA_Any_var (const CORBA_Any_var& r)
{
}
-ACE_INLINE
+ACE_INLINE
CORBA_Any_var::~CORBA_Any_var (void)
{
delete this->ptr_;
@@ -265,7 +246,7 @@ CORBA_Any_out::CORBA_Any_out (CORBA_Any *&s)
ACE_INLINE
CORBA_Any_out::CORBA_Any_out (CORBA_Any_var &s)
- : ptr_ (s.out ())
+ : ptr_ (s.out ())
{
}
@@ -307,4 +288,3 @@ CORBA_Any_out::ptr (void)
{
return this->ptr_;
}
-