Object_KeyC.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: Object_KeyC.cpp 79002 2007-07-23 19:38:05Z zhangw $
00004 
00005 // ****  Code generated by the The ACE ORB (TAO) IDL Compiler ****
00006 // TAO and the TAO IDL Compiler have been developed by:
00007 //       Center for Distributed Object Computing
00008 //       Washington University
00009 //       St. Louis, MO
00010 //       USA
00011 //       http://www.cs.wustl.edu/~schmidt/doc-center.html
00012 // and
00013 //       Distributed Object Computing Laboratory
00014 //       University of California at Irvine
00015 //       Irvine, CA
00016 //       USA
00017 //       http://doc.ece.uci.edu/
00018 // and
00019 //       Institute for Software Integrated Systems
00020 //       Vanderbilt University
00021 //       Nashville, TN
00022 //       USA
00023 //       http://www.isis.vanderbilt.edu/
00024 //
00025 // Information about TAO is available at:
00026 //     http://www.cs.wustl.edu/~schmidt/TAO.html
00027 
00028 // TAO_IDL - Generated from
00029 // be\be_codegen.cpp:291
00030 
00031 
00032 #include "tao/Object_KeyC.h"
00033 #include "tao/CDR.h"
00034 #include "tao/ORB_Core.h"
00035 
00036 #if defined (__BORLANDC__)
00037 #pragma option -w-rvl -w-rch -w-ccc -w-aus -w-sig
00038 #endif /* __BORLANDC__ */
00039 
00040 #include "ace/ACE.h"
00041 #include "ace/Truncate.h"
00042 #include "ace/OS_NS_string.h"
00043 #include "ace/os_include/os_ctype.h"
00044 
00045 // TAO_IDL - Generated from
00046 // be\be_visitor_arg_traits.cpp:70
00047 
00048 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00049 
00050 // Arg traits specializations.
00051 namespace TAO
00052 {
00053 }
00054 
00055 
00056 // TAO_IDL - Generated from
00057 // be\be_visitor_sequence/sequence_cs.cpp:65
00058 
00059 #if !defined (_TAO_OBJECTKEY_CS_)
00060 #define _TAO_OBJECTKEY_CS_
00061 
00062 TAO::ObjectKey::ObjectKey (void)
00063 {}
00064 
00065 TAO::ObjectKey::ObjectKey (
00066     CORBA::ULong max
00067   )
00068   : TAO::unbounded_value_sequence<
00069         CORBA::Octet
00070       >
00071     (max)
00072 {}
00073 
00074 TAO::ObjectKey::ObjectKey (
00075     CORBA::ULong max,
00076     CORBA::ULong length,
00077     CORBA::Octet * buffer,
00078     CORBA::Boolean release
00079   )
00080   : TAO::unbounded_value_sequence<
00081         CORBA::Octet
00082       >
00083     (max, length, buffer, release)
00084 {}
00085 
00086 TAO::ObjectKey::ObjectKey (
00087     const ObjectKey &seq
00088   )
00089   : TAO::unbounded_value_sequence<
00090         CORBA::Octet
00091       >
00092     (seq)
00093 {}
00094 
00095 TAO::ObjectKey::~ObjectKey (void)
00096 {}
00097 
00098 // Hand crafted.
00099 
00100 void
00101 TAO::ObjectKey::encode_sequence_to_string (char* & str,
00102                                            TAO::unbounded_value_sequence<CORBA::Octet> const & seq)
00103 {
00104   // We must allocate a buffer which is (gag) 3 times the length
00105   // of the sequence, which is the length required in the worst-case
00106   // scenario of all non-printable characters.
00107   //
00108   // There are two strategies here...we could allocate all that space here,
00109   // fill it up, then copy-allocate new space of just the right length.
00110   // OR, we could just return this space.  The classic time-space tradeoff,
00111   // and for now we'll let time win out, which means that we only do the
00112   // allocation once.
00113   CORBA::ULong const seq_len = seq.length ();
00114   CORBA::ULong const len = 3 * seq_len; /* space for zero termination
00115                                            not needed */
00116   str = CORBA::string_alloc (len);
00117 
00118   char * const eos = str + len;
00119   char *       cp  = str;
00120 
00121   for (CORBA::ULong i = 0;
00122        cp < eos && i < seq_len;
00123        ++i)
00124     {
00125       unsigned char bt = seq[i];
00126       if (is_legal (bt))
00127         {
00128           *cp++ = static_cast<char> (bt);
00129           continue;
00130         }
00131 
00132       *cp++ = '%';
00133       *cp++ = static_cast<char> (ACE::nibble2hex ((bt >> 4) & 0x0f));
00134       *cp++ = static_cast<char> (ACE::nibble2hex (bt & 0x0f));
00135     }
00136   // Zero terminate
00137   *cp = '\0';
00138 }
00139 
00140 CORBA::Boolean
00141 TAO::ObjectKey::is_legal (unsigned char c)
00142 {
00143   if (isalnum (c))
00144   {
00145     return true;
00146   }
00147   else
00148   {
00149     return ( c == ';' || c == '/' ||c == ':' || c == '?' ||
00150              c == '@' || c == '&' ||c == '=' || c == '+' ||
00151              c == '$' || c == ',' ||c == '_' || c == '.' ||
00152              c == '!' || c == '~' ||c == '*' || c == '\'' ||
00153              c == '-' || c == '(' || c == ')' );
00154   }
00155 }
00156 
00157 void
00158 TAO::ObjectKey::decode_string_to_sequence (
00159   TAO::unbounded_value_sequence<CORBA::Octet> & seq,
00160   char const * str)
00161 {
00162   if (str == 0)
00163     {
00164       seq.length (0);
00165       return;
00166     }
00167 
00168   size_t const str_len = ACE_OS::strlen (str);
00169 
00170   // Ensure sequence length value does not exceed maximum value for
00171   // sequence index type (CORBA::ULong).  This is mostly an issue for
00172   // 64-bit MS Windows builds.
00173   CORBA::ULong const len =
00174     ACE_Utils::truncate_cast<CORBA::ULong> (str_len);
00175   
00176   char const * const eos = str + str_len;
00177   char const *       cp  = str;
00178 
00179   // Set the length of the sequence to be as long as we'll possibly
00180   // need...we'll reset it to the actual length later.
00181   seq.length (len);
00182 
00183   CORBA::ULong i = 0;
00184   for (;
00185        cp < eos && i < len;
00186        ++i)
00187     {
00188       if (*cp == '%' || *cp == '\\')
00189         {
00190           // This is an escaped non-printable,
00191           // so we decode the hex values into
00192           // the sequence's octet
00193           seq[i]  = static_cast<CORBA::Octet> (ACE::hex2byte (cp[1]) << 4);
00194           seq[i] |= static_cast<CORBA::Octet> (ACE::hex2byte (cp[2]));
00195           cp += 3;
00196         }
00197       else
00198         // Copy it in
00199         seq[i] = *cp++;
00200     }
00201 
00202   // Set the length appropriately
00203   seq.length (i);
00204 }
00205 
00206 /*static*/ CORBA::Boolean
00207 TAO::ObjectKey::demarshal_key (TAO::ObjectKey &key,
00208                                TAO_InputCDR &strm)
00209 {
00210   CORBA::ULong _tao_seq_len;
00211 
00212   if (strm >> _tao_seq_len)
00213     {
00214       // Add a check to the length of the sequence
00215       // to make sure it does not exceed the length
00216       // of the stream. (See bug 58.)
00217       if (_tao_seq_len > strm.length ())
00218         {
00219           return 0;
00220         }
00221 
00222       // Set the length of the sequence.
00223       key.length (_tao_seq_len);
00224 
00225       // If length is 0 we return true.
00226       if (0 >= _tao_seq_len)
00227         {
00228           return 1;
00229         }
00230 
00231       // Retrieve all the elements.
00232 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
00233       if (ACE_BIT_DISABLED (strm.start ()->flags (),
00234       ACE_Message_Block::DONT_DELETE))
00235       {
00236         key.replace (_tao_seq_len, strm.start ());
00237         key.mb ()->wr_ptr (key.mb()->rd_ptr () + _tao_seq_len);
00238         strm.skip_bytes (_tao_seq_len);
00239         return 1;
00240       }
00241       return strm.read_octet_array (key.get_buffer (),
00242                                     _tao_seq_len);
00243 #else /* TAO_NO_COPY_OCTET_SEQUENCES == 0 */
00244       return strm.read_octet_array (key.get_buffer (), key.length ());
00245 #endif /* TAO_NO_COPY_OCTET_SEQUENCES == 0 */
00246 
00247     }
00248   return 0;
00249 }
00250 
00251 #endif /* end #if !defined */
00252 
00253 // TAO_IDL - Generated from
00254 // be\be_visitor_sequence/cdr_op_cs.cpp:96
00255 
00256 #if !defined _TAO_CDR_OP_TAO_ObjectKey_CPP_
00257 #define _TAO_CDR_OP_TAO_ObjectKey_CPP_
00258 
00259 CORBA::Boolean operator<< (
00260     TAO_OutputCDR &strm,
00261     const TAO::ObjectKey &_tao_sequence
00262   )
00263 {
00264   return TAO::marshal_sequence(strm, _tao_sequence);
00265 }
00266 
00267 CORBA::Boolean operator>> (
00268     TAO_InputCDR &strm,
00269     TAO::ObjectKey &_tao_sequence
00270   )
00271 {
00272   return TAO::demarshal_sequence(strm, _tao_sequence);
00273 }
00274 
00275 #endif /* _TAO_CDR_OP_TAO_ObjectKey_CPP_ */
00276 
00277 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:07:34 2008 for TAO by doxygen 1.3.6