/*
 *  MICO --- a free CORBA implementation
 *  Copyright (C) 1997-98 Kay Roemer & Arno Puder
 *
 *  This file was automatically generated. DO NOT EDIT!
 */

#include "unions.h"

//--------------------------------------------------------
//  Implementation of stubs
//--------------------------------------------------------
#ifdef HAVE_EXPLICIT_STRUCT_OPS
unions::Date::Date()
{
}

unions::Date::Date( const Date&_u )
{
  _discriminator = _u._discriminator;
  _m.stringFormat = ((Date&)_u)._m.stringFormat;
  _m.digitalFormat = ((Date&)_u)._m.digitalFormat;
  _m.structFormat = ((Date&)_u)._m.structFormat;
}

unions::Date::~Date()
{
}

unions::Date&
unions::Date::operator=( const Date&_u )
{
  _discriminator = _u._discriminator;
  _m.stringFormat = ((Date&)_u)._m.stringFormat;
  _m.digitalFormat = ((Date&)_u)._m.digitalFormat;
  _m.structFormat = ((Date&)_u)._m.structFormat;
  return *this;
}
#endif

void unions::Date::_d( CORBA::Short _p )
{
  _discriminator = _p;
}

CORBA::Short unions::Date::_d() const
{
  return _discriminator;
}

void unions::Date::stringFormat( char *_p )
{
  _discriminator = 1;
  _m.stringFormat = _p;
}

void unions::Date::stringFormat( const char *_p )
{
  _discriminator = 1;
  _m.stringFormat = _p;
}

void unions::Date::stringFormat( const CORBA::String_var &_p )
{
  _discriminator = 1;
  _m.stringFormat = _p;
}

const char *unions::Date::stringFormat() const
{
  return _m.stringFormat;
}

void unions::Date::digitalFormat( CORBA::Long _p )
{
  _discriminator = 2;
  _m.digitalFormat = _p;
}

CORBA::Long unions::Date::digitalFormat() const
{
  return _m.digitalFormat;
}

void unions::Date::structFormat( CORBA::Float _p )
{
  _discriminator = 0;
  _m.structFormat = _p;
}

CORBA::Float unions::Date::structFormat() const
{
  return _m.structFormat;
}

class _Marshaller_unions_Date : public CORBA::StaticTypeInfo {
    typedef unions::Date _T;
  public:
    StaticValueType create () const;
    void assign (StaticValueType dst, const StaticValueType src) const;
    void free (StaticValueType) const;
    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
    void marshal (CORBA::DataEncoder &, StaticValueType) const;
};


CORBA::StaticValueType _Marshaller_unions_Date::create() const
{
  return (StaticValueType) new _T;
}

void _Marshaller_unions_Date::assign( StaticValueType d, const StaticValueType s ) const
{
  *(_T*) d = *(_T*) s;
}

void _Marshaller_unions_Date::free( StaticValueType v ) const
{
  delete (_T*) v;
}

CORBA::Boolean _Marshaller_unions_Date::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
{
  if( !dc.union_begin() )
    return FALSE;
  if( !CORBA::_stc_short->demarshal( dc, &((_T *) v)->_discriminator ) )
    return FALSE;
  switch( ((_T *) v)->_discriminator ) {
    case 1:
      if( !CORBA::_stc_string->demarshal( dc, &((_T *) v)->_m.stringFormat.inout() ) )
        return FALSE;
      break;
    case 2:
      if( !CORBA::_stc_long->demarshal( dc, &((_T *) v)->_m.digitalFormat ) )
        return FALSE;
      break;
    default:
      if( !CORBA::_stc_float->demarshal( dc, &((_T *) v)->_m.structFormat ) )
        return FALSE;
      break;
  }
  return dc.union_end();
}

void _Marshaller_unions_Date::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
{
  ec.union_begin();
  CORBA::_stc_short->marshal( ec, &((_T *) v)->_discriminator );
  switch( ((_T *) v)->_discriminator ) {
    case 1:
      CORBA::_stc_string->marshal( ec, &((_T *) v)->_m.stringFormat.inout() );
      break;
    case 2:
      CORBA::_stc_long->marshal( ec, &((_T *) v)->_m.digitalFormat );
      break;
    default:
      CORBA::_stc_float->marshal( ec, &((_T *) v)->_m.structFormat );
      break;
  }
  ec.union_end();
}

CORBA::StaticTypeInfo *_marshaller_unions_Date;


// Stub interface unions
unions::~unions()
{
}

unions_ptr unions::_duplicate( unions_ptr _obj )
{
  if( !CORBA::is_nil( _obj ) )
    _obj->_ref();
  return _obj;
}

void *unions::_narrow_helper( const char *_repoid )
{
  if( strcmp( _repoid, "IDL:unions:1.0" ) == 0 )
    return (void *)this;
  return NULL;
}

bool unions::_narrow_helper2( CORBA::Object_ptr _obj )
{
  if( strcmp( _obj->_repoid(), "IDL:unions:1.0" ) == 0) {
    return true;
  }
  for( vector<CORBA::Narrow_proto>::size_type _i = 0;
       _narrow_helpers && _i < _narrow_helpers->size(); _i++ ) {
    bool _res = (*(*_narrow_helpers)[ _i ])( _obj );
    if( _res )
      return true;
  }
  return false;
}

unions_ptr unions::_narrow( CORBA::Object_ptr _obj )
{
  unions_ptr _o;
  if( !CORBA::is_nil( _obj ) ) {
    void *_p;
    if( (_p = _obj->_narrow_helper( "IDL:unions:1.0" )))
      return _duplicate( (unions_ptr) _p );
    if( _narrow_helper2( _obj ) ) {
      _o = new unions_stub;
      _o->MICO_SCOPE(CORBA,Object::operator=)( *_obj );
      return _o;
    }
  }
  return _nil();
}

unions_ptr unions::_nil()
{
  return NULL;
}

unions_stub::~unions_stub()
{
}

vector<CORBA::Narrow_proto> * unions::_narrow_helpers;

class _Marshaller_unions : public CORBA::StaticTypeInfo {
    typedef unions_ptr _T;
  public:
    StaticValueType create () const;
    void assign (StaticValueType dst, const StaticValueType src) const;
    void free (StaticValueType) const;
    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
    void marshal (CORBA::DataEncoder &, StaticValueType) const;
};


CORBA::StaticValueType _Marshaller_unions::create() const
{
  return (StaticValueType) new _T( 0 );
}

void _Marshaller_unions::assign( StaticValueType d, const StaticValueType s ) const
{
  *(_T*) d = ::unions::_duplicate( *(_T*) s );
}

void _Marshaller_unions::free( StaticValueType v ) const
{
  CORBA::release( *(_T *) v );
  delete (_T*) v;
}

CORBA::Boolean _Marshaller_unions::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
{
  CORBA::Object_ptr obj;
  if( !CORBA::_stc_Object->demarshal( dc, &obj ) )
    return FALSE;
  *(_T *) v = ::unions::_narrow( obj );
  CORBA::release( obj );
  return TRUE;
}

void _Marshaller_unions::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
{
  CORBA::Object_ptr obj = *(_T *) v;
  CORBA::_stc_Object->marshal( ec, &obj );
}

CORBA::StaticTypeInfo *_marshaller_unions;

struct __tc_init_UNIONS {
  __tc_init_UNIONS()
  {
    _marshaller_unions_Date = new _Marshaller_unions_Date;

    _marshaller_unions = new _Marshaller_unions;

  }
};

static __tc_init_UNIONS __init_UNIONS;

//--------------------------------------------------------
//  Implementation of skeletons
//--------------------------------------------------------

unions_skel::unions_skel( const CORBA::BOA::ReferenceData &_id )
{
  CORBA::ImplementationDef_var _impl =
    _find_impl( "IDL:unions:1.0", "unions" );
  assert( !CORBA::is_nil( _impl ) );
  _create_ref( _id,
    CORBA::InterfaceDef::_nil(),
    _impl,
    "IDL:unions:1.0" );
  register_dispatcher( new StaticInterfaceDispatcherWrapper<unions_skel>( this ) );
}

unions_skel::unions_skel( CORBA::Object_ptr _obj )
{
  CORBA::ImplementationDef_var _impl =
    _find_impl( "IDL:unions:1.0", "unions" );
  assert( !CORBA::is_nil( _impl ) );
  _restore_ref( _obj,
    CORBA::BOA::ReferenceData(),
    CORBA::InterfaceDef::_nil(),
    _impl );
  register_dispatcher( new StaticInterfaceDispatcherWrapper<unions_skel>( this ) );
}

unions_skel::~unions_skel()
{
}

bool unions_skel::dispatch( CORBA::StaticServerRequest_ptr /*_req*/, CORBA::Environment & /*_env*/ )
{
  return false;
}

unions_ptr unions_skel::_this()
{
  return unions::_duplicate( this );
}

