Updated logging to include the class/method so that it is more obvious where these...
[ACE_TAO.git] / TAO / tao / Object_KeyC.cpp
blob6b147b6bb59b6e1703026bd09ffec74483e04d51
1 // -*- C++ -*-
2 // **** Code generated by the The ACE ORB (TAO) IDL Compiler ****
3 // TAO and the TAO IDL Compiler have been developed by:
4 // Center for Distributed Object Computing
5 // Washington University
6 // St. Louis, MO
7 // USA
8 // http://www.cs.wustl.edu/~schmidt/doc-center.html
9 // and
10 // Distributed Object Computing Laboratory
11 // University of California at Irvine
12 // Irvine, CA
13 // USA
14 // http://doc.ece.uci.edu/
15 // and
16 // Institute for Software Integrated Systems
17 // Vanderbilt University
18 // Nashville, TN
19 // USA
20 // http://www.isis.vanderbilt.edu/
22 // Information about TAO is available at:
23 // http://www.dre.vanderbilt.edu/~schmidt/TAO.html
25 // TAO_IDL - Generated from
26 // be\be_codegen.cpp:291
29 #include "tao/Object_KeyC.h"
30 #include "tao/CDR.h"
31 #include "tao/ORB_Core.h"
33 #include "ace/ACE.h"
34 #include "ace/Truncate.h"
35 #include "ace/OS_NS_string.h"
36 #include "ace/os_include/os_ctype.h"
37 #include <cstring>
39 // TAO_IDL - Generated from
40 // be\be_visitor_arg_traits.cpp:70
42 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
44 // Arg traits specializations.
45 namespace TAO
50 // TAO_IDL - Generated from
51 // be\be_visitor_sequence/sequence_cs.cpp:65
53 #if !defined (_TAO_OBJECTKEY_CS_)
54 #define _TAO_OBJECTKEY_CS_
56 TAO::ObjectKey::ObjectKey ()
59 TAO::ObjectKey::ObjectKey (
60 CORBA::ULong max
62 : TAO::unbounded_value_sequence<
63 CORBA::Octet
65 (max)
68 TAO::ObjectKey::ObjectKey (
69 CORBA::ULong max,
70 CORBA::ULong length,
71 CORBA::Octet * buffer,
72 CORBA::Boolean release
74 : TAO::unbounded_value_sequence<
75 CORBA::Octet
77 (max, length, buffer, release)
80 TAO::ObjectKey::~ObjectKey ()
83 // Hand crafted.
85 void
86 TAO::ObjectKey::encode_sequence_to_string (char* & str,
87 TAO::unbounded_value_sequence<CORBA::Octet> const & seq)
89 // We must allocate a buffer which is (gag) 3 times the length
90 // of the sequence, which is the length required in the worst-case
91 // scenario of all non-printable characters.
93 // There are two strategies here...we could allocate all that space here,
94 // fill it up, then copy-allocate new space of just the right length.
95 // OR, we could just return this space. The classic time-space tradeoff,
96 // and for now we'll let time win out, which means that we only do the
97 // allocation once.
98 CORBA::ULong const seq_len = seq.length ();
99 CORBA::ULong const len = 3 * seq_len; /* space for zero termination
100 not needed */
101 str = CORBA::string_alloc (len);
103 char * const eos = str + len;
104 char * cp = str;
106 for (CORBA::ULong i = 0;
107 cp < eos && i < seq_len;
108 ++i)
110 unsigned char bt = seq[i];
111 if (is_legal (bt))
113 *cp++ = static_cast<char> (bt);
114 continue;
117 *cp++ = '%';
118 *cp++ = static_cast<char> (ACE::nibble2hex ((bt >> 4) & 0x0f));
119 *cp++ = static_cast<char> (ACE::nibble2hex (bt & 0x0f));
121 // Zero terminate
122 *cp = '\0';
125 CORBA::Boolean
126 TAO::ObjectKey::is_legal (unsigned char c)
128 if (isalnum (c))
130 return true;
132 else
134 return ( c == ';' || c == '/' ||c == ':' || c == '?' ||
135 c == '@' || c == '&' ||c == '=' || c == '+' ||
136 c == '$' || c == ',' ||c == '_' || c == '.' ||
137 c == '!' || c == '~' ||c == '*' || c == '\'' ||
138 c == '-' || c == '(' || c == ')' );
142 void
143 TAO::ObjectKey::decode_string_to_sequence (
144 TAO::unbounded_value_sequence<CORBA::Octet> & seq,
145 char const * str)
147 if (str == nullptr)
149 seq.length (0);
150 return;
153 size_t const str_len = std::strlen (str);
155 // Ensure sequence length value does not exceed maximum value for
156 // sequence index type (CORBA::ULong). This is mostly an issue for
157 // 64-bit MS Windows builds.
158 CORBA::ULong const len =
159 ACE_Utils::truncate_cast<CORBA::ULong> (str_len);
161 char const * const eos = str + str_len;
162 char const * cp = str;
164 // Set the length of the sequence to be as long as we'll possibly
165 // need...we'll reset it to the actual length later.
166 seq.length (len);
168 CORBA::ULong i = 0;
169 for (;
170 cp < eos && i < len;
171 ++i)
173 if (*cp == '%' || *cp == '\\')
175 // This is an escaped non-printable,
176 // so we decode the hex values into
177 // the sequence's octet
178 seq[i] = static_cast<CORBA::Octet> (ACE::hex2byte (cp[1]) << 4);
179 seq[i] |= static_cast<CORBA::Octet> (ACE::hex2byte (cp[2]));
180 cp += 3;
182 else
183 // Copy it in
184 seq[i] = *cp++;
187 // Set the length appropriately
188 seq.length (i);
191 /*static*/ CORBA::Boolean
192 TAO::ObjectKey::demarshal_key (TAO::ObjectKey &key,
193 TAO_InputCDR &strm)
195 CORBA::ULong _tao_seq_len;
197 if (strm >> _tao_seq_len)
199 // Add a check to the length of the sequence
200 // to make sure it does not exceed the length
201 // of the stream. (See bug 58.)
202 if (_tao_seq_len > strm.length ())
204 return 0;
207 // Set the length of the sequence.
208 key.length (_tao_seq_len);
210 // If length is 0 we return true.
211 if (0 >= _tao_seq_len)
213 return 1;
216 // Retrieve all the elements.
217 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
218 if (ACE_BIT_DISABLED (strm.start ()->flags (),
219 ACE_Message_Block::DONT_DELETE))
221 key.replace (_tao_seq_len, strm.start ());
222 key.mb ()->wr_ptr (key.mb()->rd_ptr () + _tao_seq_len);
223 strm.skip_bytes (_tao_seq_len);
224 return 1;
226 return strm.read_octet_array (key.get_buffer (),
227 _tao_seq_len);
228 #else /* TAO_NO_COPY_OCTET_SEQUENCES == 0 */
229 return strm.read_octet_array (key.get_buffer (), key.length ());
230 #endif /* TAO_NO_COPY_OCTET_SEQUENCES == 0 */
233 return 0;
236 #endif /* end #if !defined */
238 // TAO_IDL - Generated from
239 // be\be_visitor_sequence/cdr_op_cs.cpp:96
241 #if !defined _TAO_CDR_OP_TAO_ObjectKey_CPP_
242 #define _TAO_CDR_OP_TAO_ObjectKey_CPP_
244 CORBA::Boolean operator<< (
245 TAO_OutputCDR &strm,
246 const TAO::ObjectKey &_tao_sequence
249 return TAO::marshal_sequence(strm, _tao_sequence);
252 CORBA::Boolean operator>> (
253 TAO_InputCDR &strm,
254 TAO::ObjectKey &_tao_sequence
257 return TAO::demarshal_sequence(strm, _tao_sequence);
260 #endif /* _TAO_CDR_OP_TAO_ObjectKey_CPP_ */
262 TAO_END_VERSIONED_NAMESPACE_DECL