PSDL_OctetSeq.cpp

Go to the documentation of this file.
00001 // PSDL_OctetSeq.cpp,v 1.2 2005/01/28 15:56:33 jtc Exp
00002 
00003 #include "PSDL_OctetSeq.h"
00004 
00005 #include "ace/Malloc_Base.h"
00006 
00007 ACE_RCSID (PSS, PSDL_OctetSeq, "$Id")
00008 
00009 // Constructor
00010 TAO_PSDL_OctetSeq::TAO_PSDL_OctetSeq ()
00011   : allocator_ (0),
00012     buffer_ (0),
00013     length_ (0)
00014 {
00015 }
00016 
00017 // Constructor
00018 TAO_PSDL_OctetSeq::TAO_PSDL_OctetSeq (ACE_Allocator * persistent_allocator)
00019   : allocator_ (persistent_allocator),
00020     buffer_ (0),
00021     length_ (0)
00022 {
00023 }
00024 
00025 // Destructor.
00026 TAO_PSDL_OctetSeq::~TAO_PSDL_OctetSeq (void)
00027 {
00028   if (this->buffer_ != 0)
00029     this->allocator_->free (this->buffer_);
00030 }
00031 
00032 // Copy constructor.
00033 TAO_PSDL_OctetSeq::TAO_PSDL_OctetSeq (const TAO_PSDL_OctetSeq & rhs)
00034 {
00035   *this = rhs;
00036 }
00037 
00038 // Assignment operator.
00039 void
00040 TAO_PSDL_OctetSeq::operator= (const TAO_PSDL_OctetSeq & rhs)
00041 {
00042   if (this == &rhs)  // Prevent self assignment
00043     return;
00044 
00045   // Free the existing buffer before assigning a new
00046   // allocator and buffer.
00047   if (this->buffer_ != 0)
00048     this->allocator_->free (this->buffer_);
00049 
00050   this->allocator_ = rhs.allocator_;
00051   void * buf = this->allocator_->malloc (rhs.length_);
00052   this->buffer_ = static_cast<CORBA::Octet *> (buf);
00053   if (this->buffer_)
00054     {
00055       // Deep copy the buffer.
00056       ACE_OS::memcpy (this->buffer_, rhs.buffer_, rhs.length_);
00057 
00058       this->length_ = rhs.length_;
00059     }
00060   else
00061     this->length_ = 0;
00062 }
00063 
00064 void
00065 TAO_PSDL_OctetSeq::operator= (const CORBA::OctetSeq & rhs)
00066 {
00067   // Free the existing buffer before assigning octet
00068   // sequence.
00069   if (this->buffer_ != 0)
00070     this->allocator_->free (this->buffer_);
00071 
00072   const CORBA::ULong len = rhs.length ();
00073 
00074   void * buf = this->allocator_->malloc (len);
00075   this->buffer_ = static_cast<CORBA::Octet *> (buf);
00076   if (this->buffer_)
00077     {
00078       CORBA::Octet * dest = this->buffer_;
00079       const CORBA::Octet * src = rhs.get_buffer ();
00080 
00081       // Deep copy the buffer.
00082       ACE_OS::memcpy (dest, src, len);
00083 
00084       this->length_ = len;
00085     }
00086   else
00087     this->length_ = 0;
00088 }
00089 
00090 // Conversion operators (cast)
00091 // (caller owns storage of return values)
00092 TAO_PSDL_OctetSeq::operator CORBA::OctetSeq *() const
00093 {
00094   CORBA::OctetSeq * tmp;
00095   ACE_NEW_RETURN (tmp,
00096                   CORBA::OctetSeq (this->length_),
00097                   0);
00098   CORBA::OctetSeq_var seq = tmp;
00099 
00100   seq->length (this->length_);
00101 
00102   CORBA::Octet * dest = seq->get_buffer ();
00103   const CORBA::Octet * src = this->buffer_;
00104   ACE_OS::memcpy (dest, src, this->length_);
00105 
00106   return seq._retn ();
00107 }
00108 
00109 TAO_PSDL_OctetSeq::operator CORBA::OctetSeq *()
00110 {
00111   CORBA::OctetSeq * tmp;
00112   ACE_NEW_RETURN (tmp,
00113                   CORBA::OctetSeq (this->length_),
00114                   0);
00115   CORBA::OctetSeq_var seq = tmp;
00116 
00117   seq->length (this->length_);
00118 
00119   CORBA::Octet * dest = seq->get_buffer ();
00120   const CORBA::Octet * src = this->buffer_;
00121   ACE_OS::memcpy (dest, src, this->length_);
00122 
00123   return seq._retn ();
00124 }

Generated on Thu Nov 9 14:07:04 2006 for TAO_PSS by doxygen 1.3.6