⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdrmemorystream.cc

📁 编译工具
💻 CC
📖 第 1 页 / 共 2 页
字号:
// -*- Mode: C++; -*-//                            Package   : omniORB// cdrMemoryStream.cc         Created on: 13/1/99//                            Author    : Sai Lai Lo (sll)////    Copyright (C) 1999 AT&T Laboratories Cambridge////    This file is part of the omniORB library////    The omniORB library is free software; you can redistribute it and/or//    modify it under the terms of the GNU Library General Public//    License as published by the Free Software Foundation; either//    version 2 of the License, or (at your option) any later version.////    This library is distributed in the hope that it will be useful,//    but WITHOUT ANY WARRANTY; without even the implied warranty of//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU//    Library General Public License for more details.////    You should have received a copy of the GNU Library General Public//    License along with this library; if not, write to the Free//    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  //    02111-1307, USA////// Description://	*** PROPRIETORY INTERFACE ***//	/*  $Log: cdrMemoryStream.cc,v $  Revision 1.1.4.12  2005/10/11 13:17:01  dgrisby  Win64 support, thanks Peter Klotz. sizeof(long) < sizeof(void*) !!  Revision 1.1.4.11  2004/10/22 20:46:22  dgrisby  Fix theoretical attempt to free stack data.  Revision 1.1.4.10  2003/02/17 01:24:04  dgrisby  Grow cdrMemoryStreams exponentially rather than linearly.  Revision 1.1.4.9  2001/10/17 16:33:27  dpg1  New downcast mechanism for cdrStreams.  Revision 1.1.4.8  2001/08/22 13:29:48  dpg1  Re-entrant Any marshalling.  Revision 1.1.4.7  2001/08/17 17:12:34  sll  Modularise ORB configuration parameters.  Revision 1.1.4.6  2001/08/03 17:41:18  sll  System exception minor code overhaul. When a system exeception is raised,  a meaning minor code is provided.  Revision 1.1.4.5  2001/04/18 18:18:11  sll  Big checkin with the brand new internal APIs.  Revision 1.1.4.4  2000/11/15 17:18:20  sll  Added char, wchar codeset convertor support to cdrMemoryStream and  cdrEncapsulationStream.  Revision 1.1.4.3  2000/11/03 18:49:16  sll  Separate out the marshalling of byte, octet and char into 3 set of distinct  marshalling functions.  Renamed put_char_array and get_char_array to put_octet_array and  get_octet_array.  New string marshal member functions.  Revision 1.1.4.2  2000/10/10 10:14:27  sll  Extra ctor for cdrEncapsulationStream which initialise the buffer by  fetching data from the argument cdrStream.  Revision 1.1.4.1  2000/09/27 17:30:28  sll  *** empty log message ****/#include <omniORB4/CORBA.h>#include <orbParameters.h>OMNI_USING_NAMESPACE(omni)// We want to ensure that the stream always starts at 8 bytes aligned.// Call this function with bufp would yield the correctly aligned starting// point.static inline void* ensure_align_8(void*p) {  return (void*)omni::align_to((omni::ptr_arith_t)p,omni::ALIGN_8);}cdrMemoryStream::cdrMemoryStream(CORBA::ULong initialBufsize,				 CORBA::Boolean clearMemory){  pd_readonly_and_external_buffer = 0;  pd_clear_memory = clearMemory;  pd_bufp     = pd_inline_buffer;  pd_outb_end = (pd_inline_buffer + sizeof(pd_inline_buffer));  rewindPtrs();  if (initialBufsize > (CORBA::ULong)((omni::ptr_arith_t)pd_outb_end - 				      (omni::ptr_arith_t)pd_outb_mkr))    reserveOutputSpace(omni::ALIGN_8,initialBufsize);  if (pd_clear_memory) memset(pd_bufp,0,			      (omni::ptr_arith_t)pd_outb_end -			      (omni::ptr_arith_t)pd_bufp);  pd_tcs_c = orbParameters::anyCharCodeSet;  pd_tcs_w = orbParameters::anyWCharCodeSet;}cdrMemoryStream::~cdrMemoryStream(){  if (!pd_readonly_and_external_buffer && pd_bufp != pd_inline_buffer)    delete [] (char*)pd_bufp;}void*cdrMemoryStream::ptrToClass(int* cptr){  if (cptr == &cdrMemoryStream::_classid) return (cdrMemoryStream*)this;  if (cptr == &cdrStream      ::_classid) return (cdrStream*)      this;  return 0;}int cdrMemoryStream::_classid;voidcdrMemoryStream::put_octet_array(const CORBA::Octet* b, int size,				omni::alignment_t align){  (void) reserveOutputSpace(align,size);  omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)pd_outb_mkr,align);  memcpy((void*)p1,b,size);  pd_outb_mkr = (void*)(p1+size);}voidcdrMemoryStream::get_octet_array(CORBA::Octet* b,int size,				 omni::alignment_t align){  fetchInputData(align,size);  omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)pd_inb_mkr,align);  memcpy(b,(void*)p1,size);  pd_inb_mkr = (void*)(p1+size);}voidcdrMemoryStream::skipInput(_CORBA_ULong size){  fetchInputData(omni::ALIGN_1,size);  pd_inb_mkr = (void*)((omni::ptr_arith_t)pd_inb_mkr + size);}CORBA::BooleancdrMemoryStream::checkInputOverrun(CORBA::ULong itemSize, 				   CORBA::ULong nItems,				   omni::alignment_t align){  if (!pd_readonly_and_external_buffer) pd_inb_end = pd_outb_mkr;  omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)pd_inb_mkr,align);  p1 += itemSize*nItems;  return ((void*)p1 > pd_inb_end) ? 0 : 1;}CORBA::BooleancdrMemoryStream::checkOutputOverrun(CORBA::ULong,CORBA::ULong,				    omni::alignment_t){  return (pd_readonly_and_external_buffer) ? 0 : 1;}voidcdrMemoryStream::fetchInputData(omni::alignment_t align, size_t required){  if (!pd_readonly_and_external_buffer) pd_inb_end = pd_outb_mkr;  required += omni::align_to((omni::ptr_arith_t)pd_inb_mkr,align) -              (omni::ptr_arith_t)pd_inb_mkr;  size_t avail = (char*)pd_inb_end - (char*) pd_inb_mkr;  if (avail < required)    OMNIORB_THROW(MARSHAL,MARSHAL_PassEndOfMessage,		  (CORBA::CompletionStatus)completion());}CORBA::BooleancdrMemoryStream::reserveOutputSpaceForPrimitiveType(omni::alignment_t align,						    size_t required){  return reserveOutputSpace(align,required);}CORBA::BooleancdrMemoryStream::maybeReserveOutputSpace(omni::alignment_t align,					 size_t required){  return reserveOutputSpace(align,required);}CORBA::BooleancdrMemoryStream::reserveOutputSpace(omni::alignment_t align,size_t required){  if (pd_readonly_and_external_buffer)    OMNIORB_THROW(MARSHAL,MARSHAL_AttemptToWriteToReadOnlyBuf,		  (CORBA::CompletionStatus)completion());  required += omni::align_to((omni::ptr_arith_t)pd_outb_mkr,align) -              (omni::ptr_arith_t)pd_outb_mkr;  size_t newsize = (char*)pd_outb_end - (char*)pd_outb_mkr;  if (newsize > required)    return 1;  // Reach here only if we really need to expand the buffer  size_t datasize = bufSize();  newsize = datasize + required + (size_t) omni::ALIGN_8;  if( newsize < 1024 ) {    // Pick the closest 2^N bytes    size_t v = (1 << 9);  // start from 2 ^ 9 = 512    while (newsize < v) {      v = (v >> 1);    }    newsize = (v << 1);  }  else {    // Grow the buffer exponentially, but not too fast    newsize = newsize + datasize / 2;  }  void* oldbufp = pd_bufp;  pd_bufp = new char[newsize];  if (pd_clear_memory) memset(pd_bufp,0,newsize);  if (datasize)    memcpy(ensure_align_8(pd_bufp),ensure_align_8(oldbufp),datasize);  pd_outb_end = (void*)((omni::ptr_arith_t)pd_bufp + newsize);  pd_outb_mkr = (void*)((omni::ptr_arith_t)ensure_align_8(pd_bufp) +			((omni::ptr_arith_t)pd_outb_mkr -			 (omni::ptr_arith_t)ensure_align_8(oldbufp)));  pd_inb_mkr  = (void*)((omni::ptr_arith_t)ensure_align_8(pd_bufp) +			((omni::ptr_arith_t)pd_inb_mkr -			 (omni::ptr_arith_t)ensure_align_8(oldbufp)));  pd_inb_end  = (void*)((omni::ptr_arith_t)ensure_align_8(pd_bufp) +			((omni::ptr_arith_t)pd_inb_end -			 (omni::ptr_arith_t)ensure_align_8(oldbufp)));  if (oldbufp != pd_inline_buffer)    delete [] (char*) oldbufp;  return 1;}voidcdrMemoryStream::copy_to(cdrStream& s, int size, omni::alignment_t align) {  fetchInputData(align,size);  omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)pd_inb_mkr,align);  s.put_octet_array((const CORBA::Octet*)p1,size,align);  pd_inb_mkr = (void*)(p1+size);}voidcdrMemoryStream::rewindInputPtr(){  pd_inb_mkr = (pd_readonly_and_external_buffer) ?                    pd_bufp : ensure_align_8(pd_bufp);  pd_inb_end = (pd_readonly_and_external_buffer) ? pd_inb_end : pd_outb_mkr;}voidcdrMemoryStream::rewindPtrs(){  if (!pd_readonly_and_external_buffer) {    pd_outb_mkr = pd_inb_mkr = pd_inb_end = ensure_align_8(pd_bufp);  }  else {    pd_outb_mkr = pd_outb_end = 0;    pd_inb_mkr = pd_bufp;  }}  CORBA::ULong cdrMemoryStream::bufSize() const{  if (!pd_readonly_and_external_buffer) {    return (CORBA::ULong)((omni::ptr_arith_t)pd_outb_mkr - 			  (omni::ptr_arith_t)ensure_align_8(pd_bufp));  }  else {    return (CORBA::ULong)((omni::ptr_arith_t)pd_inb_end - 			  (omni::ptr_arith_t)pd_bufp);  }}void*cdrMemoryStream::bufPtr() const{  return (!pd_readonly_and_external_buffer) ? ensure_align_8(pd_bufp)                                            : pd_bufp;}voidcdrMemoryStream::setByteSwapFlag(CORBA::Boolean littleendian){  pd_marshal_byte_swap = pd_unmarshal_byte_swap = (littleendian == ((CORBA::Boolean)omni::myByteOrder)) ? 0 : 1; }

⌨️ 快捷键说明

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