Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

TAO_ETCL_Literal_Constraint Class Reference

#include <TAO_ETCL_Constraint.h>

Inheritance diagram for TAO_ETCL_Literal_Constraint:
Inheritance graph
[legend]
Collaboration diagram for TAO_ETCL_Literal_Constraint:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TAO_ETCL_Literal_Constraint (void)
 TAO_ETCL_Literal_Constraint (CORBA::ULong uinteger)
 TAO_ETCL_Literal_Constraint (CORBA::Long integer)
 TAO_ETCL_Literal_Constraint (CORBA::Boolean boolean)
 TAO_ETCL_Literal_Constraint (CORBA::Double doub)
 TAO_ETCL_Literal_Constraint (const char *str)
 TAO_ETCL_Literal_Constraint (CORBA::Any *any)
 TAO_ETCL_Literal_Constraint (const TAO_ETCL_Literal_Constraint &lit)
 Copy constructors.
 TAO_ETCL_Literal_Constraint (const ETCL_Literal_Constraint *lit)
virtual ~TAO_ETCL_Literal_Constraint (void)
 Destructor.
void operator= (const TAO_ETCL_Literal_Constraint &co)
 Assignment operator.
 operator ACE_CDR::Boolean (void) const
 operator ACE_CDR::ULong (void) const
 operator ACE_CDR::Long (void) const
 operator ACE_CDR::Double (void) const
 operator const char * (void) const
 operator TAO::Any_Impl * (void) const
TAO_ETCL_Literal_Constraint operator+ (const TAO_ETCL_Literal_Constraint &rhs)
TAO_ETCL_Literal_Constraint operator- (const TAO_ETCL_Literal_Constraint &rhs)
TAO_ETCL_Literal_Constraint operator* (const TAO_ETCL_Literal_Constraint &rhs)
TAO_ETCL_Literal_Constraint operator/ (const TAO_ETCL_Literal_Constraint &rhs)
TAO_ETCL_Literal_Constraint operator- (void)
virtual Literal_Type widest_type (const ETCL_Literal_Constraint &rhs)
 Ensure both operands are of the same simple numeric type.

Static Public Member Functions

static Literal_Type comparable_type (CORBA::TypeCode_ptr type)
 Determine the comparable Expression Type from the CORBA type.

Private Member Functions

void copy (const TAO_ETCL_Literal_Constraint &co)
 Private copy method.

Private Attributes

TAO::Any_Impl * any_
 Possible literal type not covered by the base class.

Detailed Description

Definition at line 41 of file TAO_ETCL_Constraint.h.


Constructor & Destructor Documentation

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( void   ) 

Definition at line 7 of file TAO_ETCL_Constraint.inl.

  : any_ (0)
{
}

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( CORBA::ULong  uinteger  )  [explicit]

Definition at line 20 of file TAO_ETCL_Constraint.inl.

  : ETCL_Literal_Constraint (uinteger),
    any_ (0)
{
}

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( CORBA::Long  integer  )  [explicit]

Definition at line 28 of file TAO_ETCL_Constraint.inl.

  : ETCL_Literal_Constraint (integer),
    any_ (0)
{
}

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( CORBA::Boolean  boolean  )  [explicit]

Definition at line 36 of file TAO_ETCL_Constraint.inl.

  : ETCL_Literal_Constraint (boolean),
    any_ (0)
{
}

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( CORBA::Double  doub  )  [explicit]

Definition at line 44 of file TAO_ETCL_Constraint.inl.

  : ETCL_Literal_Constraint (doub),
    any_ (0)
{
}

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( const char *  str  )  [explicit]

Definition at line 52 of file TAO_ETCL_Constraint.inl.

  : ETCL_Literal_Constraint (str),
    any_ (0)
{
}

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( CORBA::Any any  )  [explicit]

Definition at line 29 of file TAO_ETCL_Constraint.cpp.

  : any_ (0)
{
  CORBA::Any& any_ref = *any;
  CORBA::TypeCode_var type = any_ref.type ();
  CORBA::TCKind corba_type = CORBA::tk_null;

  try
    {
      corba_type = type->kind ();
    }
  catch (const CORBA::Exception&)
    {
      // @@ Seth: Don't know what else to do. Make sure we can tell
      // when this constructor fails.
      return;
    }

  this->type_ =
    TAO_ETCL_Literal_Constraint::comparable_type (type.in ());

  switch (this->type_)
    {
    case ACE_ETCL_SIGNED:
      this->op_.integer_ = 0;

      if (corba_type == CORBA::tk_short)
        {
          CORBA::Short sh;
          any_ref >>= sh;
          this->op_.integer_ = (CORBA::Long) sh;
        }
      else
        {
          any_ref >>= this->op_.integer_;
        }

      break;
    case ACE_ETCL_UNSIGNED:
      this->op_.uinteger_ = 0;

      if (corba_type == CORBA::tk_ushort)
        {
          CORBA::UShort sh;
          any_ref >>= sh;
          this->op_.uinteger_ = (CORBA::ULong) sh;
        }
      else if (corba_type == CORBA::tk_enum)
        {
          TAO::Any_Impl *impl = any->impl ();

          if (impl->encoded ())
            {
              TAO::Unknown_IDL_Type *unk =
                dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

              if (unk == 0)
                {
                  throw CORBA::INTERNAL ();
                }

              // We don't want unk's rd_ptr to move, in case we are shared by
              // another Any, so we use this to copy the state, not the buffer.
              TAO_InputCDR for_reading (unk->_tao_get_cdr ());
              for_reading.read_ulong (this->op_.uinteger_);
            }
          else
            {
              TAO_OutputCDR out;
              impl->marshal_value (out);
              TAO_InputCDR in (out);
              in.read_ulong (this->op_.uinteger_);
            }
        }
      else
        {
          any_ref >>= this->op_.uinteger_;
        }

      break;
    case ACE_ETCL_DOUBLE:
      if (corba_type == CORBA::tk_float)
        {
          CORBA::Float fl;
          (*any) >>= fl;
          this->op_.double_ = (CORBA::Double) fl;
        }
      else
        {
          (*any) >>= this->op_.double_;
        }

      break;
    case ACE_ETCL_BOOLEAN:
      {
        CORBA::Any::to_boolean tmp (this->op_.bool_);
        (*any) >>= tmp;
      }
      break;
    case ACE_ETCL_STRING:
      {
        const char* s;
        any_ref >>= s;
        this->op_.str_ = CORBA::string_dup (s);
      }
      break;
    case ACE_ETCL_COMPONENT:
      this->any_ = any->impl ();
      this->any_->_add_ref ();
      break;
    }
}

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( const TAO_ETCL_Literal_Constraint lit  ) 

Copy constructors.

Definition at line 21 of file TAO_ETCL_Constraint.cpp.

  : ETCL_Literal_Constraint (),
    any_ (0)
{
  this->copy (lit);
}

TAO_ETCL_Literal_Constraint::TAO_ETCL_Literal_Constraint ( const ETCL_Literal_Constraint lit  ) 

Definition at line 13 of file TAO_ETCL_Constraint.inl.

  : ETCL_Literal_Constraint (*lit),
    any_ (0)
{}

TAO_ETCL_Literal_Constraint::~TAO_ETCL_Literal_Constraint ( void   )  [virtual]

Destructor.

Definition at line 142 of file TAO_ETCL_Constraint.cpp.

{
  if (this->any_ != 0)
    {
      this->any_->_remove_ref ();
    }
}


Member Function Documentation

Literal_Type TAO_ETCL_Literal_Constraint::comparable_type ( CORBA::TypeCode_ptr  type  )  [static]

Determine the comparable Expression Type from the CORBA type.

Definition at line 239 of file TAO_ETCL_Constraint.cpp.

{
  // Convert a CORBA::TCKind into a Literal_Type
  Literal_Type return_value = ACE_ETCL_UNKNOWN;
  CORBA::TCKind kind = CORBA::tk_null;

  try
  {
    kind = type->kind ();
    CORBA::TypeCode_var tmp = CORBA::TypeCode::_duplicate (type);

    while (kind == CORBA::tk_alias)
      {
        tmp = tmp->content_type ();

        kind = tmp->kind ();
      }
  }
  catch (const CORBA::Exception&)
  {
    return return_value;
  }
  // Since this is a top level try block, no need to check again.

  switch (kind)
    {
    case CORBA::tk_ushort:
    case CORBA::tk_ulong:
    case CORBA::tk_enum:
    case CORBA::tk_ulonglong:
      return_value = ACE_ETCL_UNSIGNED;
      break;
    case CORBA::tk_short:
    case CORBA::tk_long:
    case CORBA::tk_longlong:
      return_value = ACE_ETCL_SIGNED;
      break;
    case CORBA::tk_boolean:
      return_value = ACE_ETCL_BOOLEAN;
      break;
    case CORBA::tk_float:
    case CORBA::tk_double:
      return_value = ACE_ETCL_DOUBLE;
      break;
    case CORBA::tk_string:
      return_value = ACE_ETCL_STRING;
      break;
    default:
      return_value = ACE_ETCL_COMPONENT;
      break;
    }

  return return_value;
}

void TAO_ETCL_Literal_Constraint::copy ( const TAO_ETCL_Literal_Constraint co  )  [private]

Private copy method.

Definition at line 452 of file TAO_ETCL_Constraint.cpp.

{
  if (this->type_ == ACE_ETCL_COMPONENT && this->any_ != 0)
    {
      this->any_->_remove_ref ();
      this->any_ = 0;
    }

  switch (lit.type_)
    {
    case ACE_ETCL_COMPONENT:
      this->type_ = ACE_ETCL_COMPONENT;
      this->any_ = lit.any_;
      this->any_->_add_ref ();
      break;
    default:
      this->ETCL_Literal_Constraint::copy (lit);
      break;
    }
}

TAO_ETCL_Literal_Constraint::operator ACE_CDR::Boolean ( void   )  const

Reimplemented from ETCL_Literal_Constraint.

TAO_ETCL_Literal_Constraint::operator ACE_CDR::Double ( void   )  const

Reimplemented from ETCL_Literal_Constraint.

TAO_ETCL_Literal_Constraint::operator ACE_CDR::Long ( void   )  const

Reimplemented from ETCL_Literal_Constraint.

TAO_ETCL_Literal_Constraint::operator ACE_CDR::ULong ( void   )  const

Reimplemented from ETCL_Literal_Constraint.

TAO_ETCL_Literal_Constraint::operator const char * ( void   )  const

Reimplemented from ETCL_Literal_Constraint.

Definition at line 215 of file TAO_ETCL_Constraint.cpp.

{
  switch (this->type_)
  {
    case ACE_ETCL_COMPONENT:
      {
        const char *retval = 0;
        CORBA::Any tmp;
        tmp.replace (this->any_);
        this->any_->_add_ref ();
        tmp >>= retval;
        return retval;
      }
    default:
      return this->ETCL_Literal_Constraint::operator const char * ();
  }
}

TAO_ETCL_Literal_Constraint::operator TAO::Any_Impl * ( void   )  const

Definition at line 233 of file TAO_ETCL_Constraint.cpp.

{
  return (this->type_ == ACE_ETCL_COMPONENT) ? this->any_ : 0;
}

TAO_ETCL_Literal_Constraint TAO_ETCL_Literal_Constraint::operator* ( const TAO_ETCL_Literal_Constraint rhs  ) 

Definition at line 351 of file TAO_ETCL_Constraint.cpp.

{
  Literal_Type widest_type = this->widest_type (rhs);

  switch (widest_type)
    {
    case ACE_ETCL_DOUBLE:
      {
        CORBA::Double result = (CORBA::Double) *this * (CORBA::Double) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::Double) result);
      }
    case ACE_ETCL_INTEGER:
    case ACE_ETCL_SIGNED:
      {
        CORBA::Long result = (CORBA::Long) *this * (CORBA::Long) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::Long) result);
      }
    case ACE_ETCL_UNSIGNED:
      {
        CORBA::ULong result = (CORBA::ULong) *this * (CORBA::ULong) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::ULong) result);
      }
    default:
      return TAO_ETCL_Literal_Constraint ((CORBA::Long) 0);
    }
}

TAO_ETCL_Literal_Constraint TAO_ETCL_Literal_Constraint::operator+ ( const TAO_ETCL_Literal_Constraint rhs  ) 

Definition at line 295 of file TAO_ETCL_Constraint.cpp.

{
  Literal_Type widest_type = this->widest_type (rhs);

  switch (widest_type)
    {
    case ACE_ETCL_DOUBLE:
      {
        CORBA::Double result = (CORBA::Double) *this + (CORBA::Double) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::Double) result);
      }
    case ACE_ETCL_INTEGER:
    case ACE_ETCL_SIGNED:
      {
        CORBA::Long result = (CORBA::Long) *this + (CORBA::Long) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::Long) result);
      }
    case ACE_ETCL_UNSIGNED:
      {
        CORBA::ULong result = (CORBA::ULong) *this + (CORBA::ULong) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::ULong) result);
      }
    default:
      return TAO_ETCL_Literal_Constraint ((CORBA::Long) 0);
    }
}

TAO_ETCL_Literal_Constraint TAO_ETCL_Literal_Constraint::operator- ( void   ) 

Reimplemented from ETCL_Literal_Constraint.

Definition at line 416 of file TAO_ETCL_Constraint.cpp.

{
  switch (this->type_)
  {
    case ACE_ETCL_DOUBLE:
      return TAO_ETCL_Literal_Constraint (- this->op_.double_);
    case ACE_ETCL_INTEGER:
    case ACE_ETCL_SIGNED:
      return TAO_ETCL_Literal_Constraint (- this->op_.integer_);
    case ACE_ETCL_UNSIGNED:
      return TAO_ETCL_Literal_Constraint (- (CORBA::Long) this->op_.uinteger_);
    default:
      return TAO_ETCL_Literal_Constraint ((CORBA::Long) 0);
  }
}

TAO_ETCL_Literal_Constraint TAO_ETCL_Literal_Constraint::operator- ( const TAO_ETCL_Literal_Constraint rhs  ) 

Definition at line 323 of file TAO_ETCL_Constraint.cpp.

{
  Literal_Type widest_type = this->widest_type (rhs);

  switch (widest_type)
    {
    case ACE_ETCL_DOUBLE:
      {
        CORBA::Double result = (CORBA::Double) *this - (CORBA::Double) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::Double) result);
      }
    case ACE_ETCL_INTEGER:
    case ACE_ETCL_SIGNED:
      {
        CORBA::Long result = (CORBA::Long) *this - (CORBA::Long) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::Long) result);
      }
    case ACE_ETCL_UNSIGNED:
      {
        CORBA::ULong result = (CORBA::ULong) *this - (CORBA::ULong) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::ULong) result);
      }
    default:
      return TAO_ETCL_Literal_Constraint ((CORBA::Long) 0);
    }
}

TAO_ETCL_Literal_Constraint TAO_ETCL_Literal_Constraint::operator/ ( const TAO_ETCL_Literal_Constraint rhs  ) 

Definition at line 379 of file TAO_ETCL_Constraint.cpp.

{
  Literal_Type widest_type = this->widest_type (rhs);

  switch (widest_type)
    {
    case ACE_ETCL_DOUBLE:
      {
        if ((ACE_CDR::Double) rhs == 0.0)
          return TAO_ETCL_Literal_Constraint ((ACE_CDR::Double) 0.0);
        
        CORBA::Double result = (CORBA::Double) *this / (CORBA::Double) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::Double) result);
      }
    case ACE_ETCL_INTEGER:
    case ACE_ETCL_SIGNED:
      {
        if ((ACE_CDR::Long) rhs == 0)
          return TAO_ETCL_Literal_Constraint ((ACE_CDR::Long) 0);
        
        CORBA::Long result = (CORBA::Long) *this / (CORBA::Long) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::Long) result);
      }
    case ACE_ETCL_UNSIGNED:
      {
        if ((ACE_CDR::ULong) rhs == 0)
          return TAO_ETCL_Literal_Constraint ((ACE_CDR::ULong) 0);

        CORBA::ULong result = (CORBA::ULong) *this / (CORBA::ULong) rhs;
        return TAO_ETCL_Literal_Constraint ((CORBA::ULong) result);
      }
    default:
      return TAO_ETCL_Literal_Constraint ((CORBA::Long) 0);
    }
}

void TAO_ETCL_Literal_Constraint::operator= ( const TAO_ETCL_Literal_Constraint co  ) 

Assignment operator.

Definition at line 151 of file TAO_ETCL_Constraint.cpp.

{
  this->copy (co);
}

Literal_Type TAO_ETCL_Literal_Constraint::widest_type ( const ETCL_Literal_Constraint rhs  )  [virtual]

Ensure both operands are of the same simple numeric type.

Reimplemented from ETCL_Literal_Constraint.

Definition at line 433 of file TAO_ETCL_Constraint.cpp.

{
  Literal_Type rhs_type = rhs.expr_type ();
  Literal_Type return_value = rhs_type;

  if (rhs_type == ACE_ETCL_COMPONENT)
    {
      const TAO_ETCL_Literal_Constraint& actual =
        dynamic_cast<const TAO_ETCL_Literal_Constraint&> (rhs);   
      CORBA::TypeCode_var tc = actual.any_->type ();
      rhs_type = TAO_ETCL_Literal_Constraint::comparable_type (tc.in ());
      return return_value;
    }
    
  return this->ETCL_Literal_Constraint::widest_type (rhs);
}


Member Data Documentation

TAO::Any_Impl* TAO_ETCL_Literal_Constraint::any_ [private]

Possible literal type not covered by the base class.

Definition at line 107 of file TAO_ETCL_Constraint.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines