tcparser.cc

来自「编译工具」· CC 代码 · 共 1,382 行 · 第 1/3 页

CC
1,382
字号
	{	  tcDescriptor desc;	  CORBA::ULong contiguous = 0;	  // Get a descriptor for the sequence element.	  if( !tcdata.p_sequence.getElementDesc(&tcdata.p_sequence, i,						desc, contiguous) )	    OMNIORB_ASSERT(0);	  if (contiguous <= 1) {	    appendItem(tctmp, desc, buf);	  } else {	    const TypeCode_alignTable& alignTable = tctmp->alignmentTable();	    	    // Elements are in a contiguous block - fast copy them	    // This assumes:	    // - Element type is simple & has simple alignment	    // - Element type preserves its own alignment	    // - Byteorder matches between RAM and MemBuff	    // - Pointer to initial element is stored in same	    //   place as p_streamdata by the compiler (see tcDescriptor)	    // IF ANY OF THESE AREN'T TRUE, THIS FAILS!!!	    buf.put_octet_array((CORBA::Char*)desc.p_streamdata,				    contiguous * (alignTable[0].simple.size),				    alignTable[0].simple.alignment);	    i += contiguous;	  }	}      break;    }  case CORBA::tk_array:    {      CORBA::ULong max = tc->NP_length();      TypeCode_base* tctmp = tc->NP_content_type();      tctmp = TypeCode_indirect::strip(tctmp);      for (CORBA::ULong i=0; i < max; i++)	{	  tcDescriptor desc;	  CORBA::ULong contiguous = 0;	  // Get a descriptor for the array element.	  if( !tcdata.p_array.getElementDesc(&tcdata.p_array, i,					     desc, contiguous) )	    OMNIORB_ASSERT(0);	  // Append the element to the mbuf.	  if (contiguous <= 1) {	    appendItem(tctmp, desc, buf);	  } else {	    const TypeCode_alignTable& alignTable = tctmp->alignmentTable();	    	    // Elements are in a contiguous block - fast copy them	    // This assumes:	    // - Element type is simple & has simple alignment	    // - Element type preserves its own alignment	    // - Byteorder matches between RAM and MemBuff	    // - Pointer to initial element is stored in same	    //   place as p_streamdata by the compiler (see tcDescriptor)	    // IF ANY OF THESE AREN'T TRUE, THIS FAILS!!!	    buf.get_octet_array((CORBA::Char*)desc.p_streamdata,				   contiguous * (alignTable[0].simple.size),				   alignTable[0].simple.alignment);	    i += contiguous;	  }	}      break;    }  case CORBA::tk_alias:    appendItem(tc->NP_content_type(), tcdata, buf);    break;  default:    OMNIORB_ASSERT(0);  }  // switch (tc->NP_kind()) {}void fetchSimpleItem(CORBA::TCKind tck, cdrStream &src, tcDescriptor &tcdata){  switch (tck)    {      // SIMPLE TYPES    case CORBA::tk_short:      *tcdata.p_short   <<= src;      break;    case CORBA::tk_ushort:      *tcdata.p_ushort  <<= src;      break;    case CORBA::tk_long:      *tcdata.p_long    <<= src;      break;    case CORBA::tk_ulong:      *tcdata.p_ulong   <<= src;      break;    case CORBA::tk_float:      *tcdata.p_float   <<= src;      break;    case CORBA::tk_double:      *tcdata.p_double  <<= src;      break;    case CORBA::tk_boolean:      *tcdata.p_boolean = src.unmarshalBoolean();       break;    case CORBA::tk_char:      *tcdata.p_char = src.unmarshalChar();      break;    case CORBA::tk_wchar:      *tcdata.p_wchar = src.unmarshalWChar();      break;    case CORBA::tk_octet:      *tcdata.p_octet = src.unmarshalOctet();      break;    case CORBA::tk_enum:      {	CORBA::ULong tmp;	tmp <<= src ;	setEnumData(tcdata, tmp);      };      break;#ifdef HAS_LongLong    case CORBA::tk_longlong:      *tcdata.p_longlong    <<= src;      break;    case CORBA::tk_ulonglong:      *tcdata.p_ulonglong   <<= src;      break;#endif#ifdef HAS_LongDouble    case CORBA::tk_longdouble:      *tcdata.p_longdouble  <<= src;      break;#endif      // OTHER TYPES    default:      OMNIORB_ASSERT(0);    }}void fetchItem(const TypeCode_base* tc, cdrStream& src, tcDescriptor& tcdata){  tc = TypeCode_indirect::strip(tc);  // How to unmarshal the data depends entirely on the TypeCode  switch( tc->NP_kind() ) {    // TYPES WITH NO DATA TO MARSHAL  case CORBA::tk_null:  case CORBA::tk_void:    break;    // SIMPLE TYPES  case CORBA::tk_short:  case CORBA::tk_ushort:  case CORBA::tk_long:  case CORBA::tk_ulong:  case CORBA::tk_float:  case CORBA::tk_double:  case CORBA::tk_boolean:  case CORBA::tk_char:  case CORBA::tk_wchar:  case CORBA::tk_octet:  case CORBA::tk_enum:#ifdef HAS_LongLong  case CORBA::tk_longlong:  case CORBA::tk_ulonglong:#endif#ifdef HAS_LongDouble  case CORBA::tk_longdouble:#endif    fetchSimpleItem(tc->NP_kind(), src, tcdata);    break;  case CORBA::tk_any:    // Fetch the any.  Note that the caller must have allocated    // the Any for, already.    *tcdata.p_any <<= src;    break;    // COMPLEX TYPES  case CORBA::tk_Principal:    // For the Principal type, we just fill in the supplied    // CORBA::PrincipalId.    tcdata.p_Principal = new CORBA::PrincipalID;    *tcdata.p_Principal <<= src;    break;  case CORBA::tk_objref:    // Call the user-defined callback to set the object reference with    // appropriate narrowing.    tcdata.p_objref.setObjectPtr(&tcdata.p_objref,		    CORBA::Object_Helper::unmarshalObjRef(src));    break;  case CORBA::tk_TypeCode:    // Overwrite the TypeCode_ptr to point to the new typecode object    *tcdata.p_TypeCode = CORBA::TypeCode::unmarshalTypeCode(src);    break;  case CORBA::tk_string:    {      if(tcdata.p_string.release )	_CORBA_String_helper::free(*tcdata.p_string.ptr);      *tcdata.p_string.ptr = src.unmarshalString();      break;    }  case CORBA::tk_wstring:    {      if(tcdata.p_wstring.release )	_CORBA_WString_helper::free(*tcdata.p_wstring.ptr);      *tcdata.p_wstring.ptr = src.unmarshalWString();      break;    }  case CORBA::tk_fixed:    {      CORBA::Fixed f;      f.PR_setLimits(tc->fixed_digits(), tc->fixed_scale());      f <<= src;      *tcdata.p_fixed = f;      break;    }    // CONSTRUCTED TYPES  case CORBA::tk_union:    {      // Allocate some space to load the discriminator into.      tcUnionDiscriminatorType disc_val;      tcDescriptor             disc_desc;      CORBA::TCKind            disc_kind = tc->NP_discriminator_type()->kind();      disc_desc.p_enum.data = (void*) &disc_val;      disc_desc.p_enum.size = sizeof(disc_val);      fetchSimpleItem(disc_kind, src, disc_desc);      // Determine the discriminator value.      CORBA::PR_unionDiscriminator discrim = 0;      switch( disc_kind ) {      case CORBA::tk_char:	discrim = (CORBA::PR_unionDiscriminator) *disc_desc.p_char;	break;      case CORBA::tk_boolean:	discrim = (CORBA::PR_unionDiscriminator) *disc_desc.p_boolean;	break;      case CORBA::tk_short:	discrim = (CORBA::PR_unionDiscriminator) *disc_desc.p_short;	break;      case CORBA::tk_ushort:	discrim = (CORBA::PR_unionDiscriminator) *disc_desc.p_ushort;	break;      case CORBA::tk_long:	discrim = (CORBA::PR_unionDiscriminator) *disc_desc.p_long;	break;      case CORBA::tk_ulong:	discrim = (CORBA::PR_unionDiscriminator) *disc_desc.p_ulong;	break;      case CORBA::tk_enum:	discrim = (CORBA::PR_unionDiscriminator) getEnumData(disc_desc);	break;#ifdef HAS_LongLong      case CORBA::tk_longlong:	discrim = (CORBA::PR_unionDiscriminator) *disc_desc.p_longlong;	break;      case CORBA::tk_ulonglong:	discrim = (CORBA::PR_unionDiscriminator) *disc_desc.p_ulonglong;	break;#endif      // case CORBA::tk_wchar:      default:	OMNIORB_ASSERT(0);      }      // Determine the index of the selected member.      CORBA::Long index =	((TypeCode_union*)tc)->NP_index_from_discriminator(discrim);      // Tell the union the new discriminator value.      tcdata.p_union.setDiscriminator(&tcdata.p_union, discrim,				      index == tc->NP_default_index());      if( index < 0 )	// Implicit default - so no member to fetch	break;      // Unmarshal the union data.      tcDescriptor data_desc;      if( !tcdata.p_union.getValueDesc(&tcdata.p_union, data_desc) )	OMNIORB_ASSERT(0);      fetchItem(tc->NP_member_type(index), src, data_desc);      break;    }  case CORBA::tk_struct:    {      CORBA::ULong nmembers = tc->NP_member_count();      // Load the individual elements.      for (CORBA::ULong i=0; i < nmembers; i++)	{	  tcDescriptor desc;	    	  // Get a descriptor for the struct element.	  if( !tcdata.p_struct.getMemberDesc(&tcdata.p_struct, i, desc) )	    OMNIORB_ASSERT(0);	  fetchItem(tc->NP_member_type(i), src, desc);	}      break;    }  case CORBA::tk_except:    {      // Exceptions are passed on the wire as repo id followed      // by members - but for contents of Any we are only interested      // in members. Therefore we copy the members only here, and      // the stubs/GIOP_S code deals with the repo id.      CORBA::ULong nmembers = tc->NP_member_count();      // Load the individual elements.      for (CORBA::ULong i=0; i < nmembers; i++)	{	  tcDescriptor desc;	  if( !tcdata.p_except.getMemberDesc(&tcdata.p_except, i, desc) )	    OMNIORB_ASSERT(0);	  fetchItem(tc->NP_member_type(i), src, desc);	}      break;    }  case CORBA::tk_sequence:    {      TypeCode_base* tctmp = tc->NP_content_type();      tctmp = TypeCode_indirect::strip(tctmp);      // Get the sequence length      CORBA::ULong nelem;      nelem <<= src;      // Allocate space for it      tcdata.p_sequence.setElementCount(&tcdata.p_sequence, nelem);      // Load the sequence data      for (CORBA::ULong i=0; i < nelem; i++)	{	  tcDescriptor desc;	  CORBA::ULong contiguous = 0;	  if(!tcdata.p_sequence.getElementDesc(&tcdata.p_sequence, i,						desc, contiguous) )	    OMNIORB_ASSERT(0);	  if (contiguous <= 1) {	    fetchItem(tctmp, src, desc);	  } else {	    const TypeCode_alignTable& alignTable = tctmp->alignmentTable();	   	    // Elements are in a contiguous block - fast copy them	    // This assumes:	    // - Element type is simple & has simple alignment	    // - Element type preserves its own alignment	    // - Byteorder matches between RAM and MemBuff	    // - Pointer to initial element is stored in same	    //   place as p_streamdata by the compiler (see tcDescriptor)	    // - Contiguous buffer is large enough & suitably aligned	    // IF ANY OF THESE AREN'T TRUE, THIS FAILS!!!	    src.get_octet_array((CORBA::Char*)desc.p_streamdata,				    contiguous * (alignTable[0].simple.size),				    alignTable[0].simple.alignment);	    i += contiguous;	  }	}      break;    }  case CORBA::tk_array:    {      CORBA::ULong length = tc->NP_length();      TypeCode_base* tctmp = tc->NP_content_type();      tctmp = TypeCode_indirect::strip(tctmp);      for (CORBA::ULong i=0; i < length; i++)	{	  tcDescriptor desc;	  CORBA::ULong contiguous = 0;	    	  if( !tcdata.p_array.getElementDesc(&tcdata.p_array, i,					     desc, contiguous) )	    OMNIORB_ASSERT(0);	  if (contiguous <= 1) {	    fetchItem(tctmp, src, desc);	  } else {	    const TypeCode_alignTable& alignTable = tctmp->alignmentTable();	   	    // Elements are in a contiguous block - fast copy them	    // This assumes:	    // - Element type is simple & has simple alignment	    // - Element type preserves its own alignment	    // - Byteorder matches between RAM and MemBuff	    // - Pointer to initial element is stored in same	    //   place as p_streamdata by the compiler (see tcDescriptor)	    // - Contiguous buffer is large enough & suitably aligned	    // IF ANY OF THESE AREN'T TRUE, THIS FAILS!!!	    src.get_octet_array((CORBA::Char*)desc.p_streamdata,				    contiguous * (alignTable[0].simple.size),				    alignTable[0].simple.alignment);	    i += contiguous;	  }	}      break;    }  case CORBA::tk_alias:    fetchItem(tc->NP_content_type(), src, tcdata);    break;  default:    // Unexpected kind    OMNIORB_ASSERT(0);  }}//////////////////////////////////////////////////////////////////////////////////////////// Data Descriptor Functions ///////////////////////////////////////////////////////////////////////////////////////////void_0RL_tcParser_objref_setObjectPtr(const tcObjrefDesc* desc,				  CORBA::Object_ptr ptr){  CORBA::Object_ptr* pp = (CORBA::Object_ptr*)desc->opq_objref;  if (desc->opq_release && !CORBA::is_nil(*pp)) {    CORBA::release(*pp);  }  *pp = ptr;}CORBA::Object_ptr_0RL_tcParser_objref_getObjectPtr(const tcObjrefDesc* desc){  return *((CORBA::Object_ptr*)desc->opq_objref);}OMNI_NAMESPACE_END(omni)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?