Object_KeyC.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Object_KeyC.cpp,v 1.44 2006/04/19 08:40:55 jwillemsen Exp
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/OS_NS_string.h"
00042 #include "ace/os_include/os_ctype.h"
00043 
00044 // TAO_IDL - Generated from
00045 // be\be_visitor_arg_traits.cpp:70
00046 
00047 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00048 
00049 // Arg traits specializations.
00050 namespace TAO
00051 {
00052 }
00053 
00054 
00055 // TAO_IDL - Generated from
00056 // be\be_visitor_sequence/sequence_cs.cpp:65
00057 
00058 #if !defined (_TAO_OBJECTKEY_CS_)
00059 #define _TAO_OBJECTKEY_CS_
00060 
00061 TAO::ObjectKey::ObjectKey (void)
00062 {}
00063 
00064 TAO::ObjectKey::ObjectKey (
00065     CORBA::ULong max
00066   )
00067   : TAO::unbounded_value_sequence<
00068         CORBA::Octet
00069       >
00070     (max)
00071 {}
00072 
00073 TAO::ObjectKey::ObjectKey (
00074     CORBA::ULong max,
00075     CORBA::ULong length,
00076     CORBA::Octet * buffer,
00077     CORBA::Boolean release
00078   )
00079   : TAO::unbounded_value_sequence<
00080         CORBA::Octet
00081       >
00082     (max, length, buffer, release)
00083 {}
00084 
00085 TAO::ObjectKey::ObjectKey (
00086     const ObjectKey &seq
00087   )
00088   : TAO::unbounded_value_sequence<
00089         CORBA::Octet
00090       >
00091     (seq)
00092 {}
00093 
00094 TAO::ObjectKey::~ObjectKey (void)
00095 {}
00096 
00097 // Hand crafted.
00098 
00099 void
00100 TAO::ObjectKey::encode_sequence_to_string (char * &str,
00101                                            const TAO::unbounded_value_sequence<CORBA::Octet> &seq)
00102 {
00103   // We must allocate a buffer which is (gag) 3 times the length
00104   // of the sequence, which is the length required in the worst-case
00105   // scenario of all non-printable characters.
00106   //
00107   // There are two strategies here...we could allocate all that space here,
00108   // fill it up, then copy-allocate new space of just the right length.
00109   // OR, we could just return this space.  The classic time-space tradeoff,
00110   // and for now we'll let time win out, which means that we only do the
00111   // allocation once.
00112   u_int len = 3 * seq.length (); /* space for zero termination not needed */;
00113   str = CORBA::string_alloc (len);
00114 
00115   char *cp = str;
00116 
00117   for (u_int i = 0;
00118        cp < (str + len) && i < seq.length();
00119        ++i)
00120     {
00121       u_char bt = seq[i];
00122       if (is_legal (bt))
00123         {
00124           *cp++ = (char) bt;
00125           continue;
00126         }
00127 
00128       *cp++ = '%';
00129       *cp++ = ACE::nibble2hex ((bt >> 4) & 0x0f);
00130       *cp++ = ACE::nibble2hex (bt & 0x0f);
00131     }
00132   // Zero terminate
00133   *cp = '\0';
00134 }
00135 
00136 int TAO::ObjectKey::is_legal (u_char & c)
00137 {
00138   if (isalnum(c))
00139   {
00140     return 1;
00141   }
00142   else
00143   {
00144     return ( c == ';' || c == '/' ||c == ':' || c == '?' ||
00145              c == '@' || c == '&' ||c == '=' || c == '+' ||
00146              c == '$' || c == ',' ||c == '_' || c == '.' ||
00147              c == '!' || c == '~' ||c == '*' || c == '\'' ||
00148              c == '-' || c == '(' || c == ')' );
00149   }
00150 }
00151 
00152 void
00153 TAO::ObjectKey::decode_string_to_sequence (TAO::unbounded_value_sequence<CORBA::Octet> &seq,
00154                                            const char *str)
00155 {
00156   if (str == 0)
00157     {
00158       seq.length (0);
00159       return;
00160     }
00161 
00162   size_t length = ACE_OS::strlen (str);
00163   const char *eos = str + length;
00164   const char *cp = str;
00165 
00166   // Set the length of the sequence to be as long as
00167   // we'll possibly need...we'll reset it to the actual
00168   // length later.
00169   seq.length (length);
00170 
00171   u_int i = 0;
00172   for (;
00173        cp < eos && i < seq.length ();
00174        ++i)
00175     {
00176       if (*cp == '%' || *cp == '\\')
00177         {
00178           // This is an escaped non-printable,
00179           // so we decode the hex values into
00180           // the sequence's octet
00181           seq[i] = (u_char) (ACE::hex2byte (cp[1]) << 4);
00182           seq[i] |= (u_char) ACE::hex2byte (cp[2]);
00183           cp += 3;
00184         }
00185       else
00186         // Copy it in
00187         seq[i] = *cp++;
00188     }
00189 
00190   // Set the length appropriately
00191   seq.length (i);
00192 }
00193 
00194 /*static*/ CORBA::Boolean
00195 TAO::ObjectKey::demarshal_key (TAO::ObjectKey &key,
00196                                TAO_InputCDR &strm)
00197 {
00198   CORBA::ULong _tao_seq_len;
00199 
00200   if (strm >> _tao_seq_len)
00201     {
00202       // Add a check to the length of the sequence
00203       // to make sure it does not exceed the length
00204       // of the stream. (See bug 58.)
00205       if (_tao_seq_len > strm.length ())
00206         {
00207           return 0;
00208         }
00209 
00210       // Set the length of the sequence.
00211       key.length (_tao_seq_len);
00212 
00213       // If length is 0 we return true.
00214       if (0 >= _tao_seq_len)
00215         {
00216           return 1;
00217         }
00218 
00219       // Retrieve all the elements.
00220 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
00221       if (ACE_BIT_DISABLED (strm.start ()->flags (),
00222       ACE_Message_Block::DONT_DELETE))
00223       {
00224         key.replace (_tao_seq_len, strm.start ());
00225         key.mb ()->wr_ptr (key.mb()->rd_ptr () + _tao_seq_len);
00226         strm.skip_bytes (_tao_seq_len);
00227         return 1;
00228       }
00229       return strm.read_octet_array (key.get_buffer (),
00230                                     _tao_seq_len);
00231 #else /* TAO_NO_COPY_OCTET_SEQUENCES == 0 */
00232       return strm.read_octet_array (key.get_buffer (), key.length ());
00233 #endif /* TAO_NO_COPY_OCTET_SEQUENCES == 0 */
00234 
00235     }
00236   return 0;
00237 }
00238 
00239 #endif /* end #if !defined */
00240 
00241 // TAO_IDL - Generated from
00242 // be\be_visitor_sequence/cdr_op_cs.cpp:96
00243 
00244 #if !defined _TAO_CDR_OP_TAO_ObjectKey_CPP_
00245 #define _TAO_CDR_OP_TAO_ObjectKey_CPP_
00246 
00247 CORBA::Boolean operator<< (
00248     TAO_OutputCDR &strm,
00249     const TAO::ObjectKey &_tao_sequence
00250   )
00251 {
00252   return TAO::marshal_sequence(strm, _tao_sequence);
00253 }
00254 
00255 CORBA::Boolean operator>> (
00256     TAO_InputCDR &strm,
00257     TAO::ObjectKey &_tao_sequence
00258   )
00259 {
00260   return TAO::demarshal_sequence(strm, _tao_sequence);
00261 }
00262 
00263 #endif /* _TAO_CDR_OP_TAO_ObjectKey_CPP_ */
00264 
00265 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:16 2006 for TAO by doxygen 1.3.6