Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / Codeset_IBM1047.cpp
blob04938ad744346fe61c967443a80bfebdb3538746
2 //=============================================================================
3 /**
4 * @file Codeset_IBM1047.cpp
6 * Defines the arrays required to convert between ISO8859 (aka
7 * Latin/1) and IBM1047 (aka EBCDIC).
9 * @author Jim Rogers (jrogers@viasoft.com)
11 //=============================================================================
14 #include "ace/Codeset_IBM1047.h"
16 #if defined (ACE_HAS_EBCDIC)
18 #include "ace/OS_Memory.h"
19 #include "ace/OS_NS_string.h"
21 namespace
23 char const to_IBM1047[] =
25 "\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x25\x0B\x0C\x0D\x0E\x0F" // 00-0F
26 "\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x22\x1D\x35\x1F" // 10-1F
27 "\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61" // 20-2F
28 "\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F" // 30-3F
29 "\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6" // 40-4F
30 "\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xAD\xE0\xBD\x5F\x6D" // 50-5F
31 "\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96" // 60-6F
32 "\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07" // 70-7F
33 "\x43\x20\x21\x1C\x23\xEB\x24\x9B\x71\x28\x38\x49\x90\xBA\xEC\xDF" // 80-8F
34 "\x45\x29\x2A\x9D\x72\x2B\x8A\x9A\x67\x56\x64\x4A\x53\x68\x59\x46" // 90-9F
35 "\xEA\xDA\x2C\xDE\x8B\x55\x41\xFE\x58\x51\x52\x48\x69\xDB\x8E\x8D" // A0-AF
36 "\x73\x74\x75\xFA\x15\xB0\xB1\xB3\xB4\xB5\x6A\xB7\xB8\xB9\xCC\xBC" // B0-BF
37 "\xAB\x3E\x3B\x0A\xBF\x8F\x3A\x14\xA0\x17\xCB\xCA\x1A\x1B\x9C\x04" // C0-CF
38 "\x34\xEF\x1E\x06\x08\x09\x77\x70\xBE\xBB\xAC\x54\x63\x65\x66\x62" // D0-DF
39 "\x30\x42\x47\x57\xEE\x33\xB6\xE1\xCD\xED\x36\x44\xCE\xCF\x31\xAA" // E0-EF
40 "\xFC\x9E\xAE\x8C\xDD\xDC\x39\xFB\x80\xAF\xFD\x78\x76\xB2\x9F\xFF" // F0-FF
43 char const from_IBM1047[] =
45 "\x00\x01\x02\x03\xCF\x09\xD3\x7F\xD4\xD5\xC3\x0B\x0C\x0D\x0E\x0F" // 00-0F
46 "\x10\x11\x12\x13\xC7\xB4\x08\xC9\x18\x19\xCC\xCD\x83\x1D\xD2\x1F" // 10-1F
47 "\x81\x82\x1C\x84\x86\x0A\x17\x1B\x89\x91\x92\x95\xA2\x05\x06\x07" // 20-2F
48 "\x20\xEE\x16\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\xC1\x1A" // 30-3F
49 "\x20\xA6\xE1\x80\xEB\x90\x9F\xE2\xAB\x8B\x9B\x2E\x3C\x28\x2B\x7C" // 40-4F
50 "\x26\xA9\xAA\x9C\xDB\xA5\x99\xE3\xA8\x9E\x21\x24\x2A\x29\x3B\x5E" // 50-5F
51 "\x2D\x2F\xDF\xDC\x9A\xDD\xDE\x98\x9D\xAC\xBA\x2C\x25\x5F\x3E\x3F" // 60-6F
52 "\xD7\x88\x94\xB0\xB1\xB2\xFC\xD6\xFB\x60\x3A\x23\x40\x27\x3D\x22" // 70-7F
53 "\xF8\x61\x62\x63\x64\x65\x66\x67\x68\x69\x96\xA4\xF3\xAF\xAE\xC5" // 80-8F
54 "\x8C\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x97\x87\xCE\x93\xF1\xFE" // 90-9F
55 "\xC8\x7E\x73\x74\x75\x76\x77\x78\x79\x7A\xEF\xC0\xDA\x5B\xF2\xF9" // A0-AF
56 "\xB5\xB6\xFD\xB7\xB8\xB9\xE6\xBB\xBC\xBD\x8D\xD9\xBF\x5D\xD8\xC4" // B0-BF
57 "\x7B\x41\x42\x43\x44\x45\x46\x47\x48\x49\xCB\xCA\xBE\xE8\xEC\xED" // C0-CF
58 "\x7D\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\xA1\xAD\xF5\xF4\xA3\x8F" // D0-DF
59 "\x5C\xE7\x53\x54\x55\x56\x57\x58\x59\x5A\xA0\x85\x8E\xE9\xE4\xD1" // E0-EF
60 "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\xB3\xF7\xF0\xFA\xA7\xFF" // F0-FF
64 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
66 ACE_IBM1047_ISO8859::ACE_IBM1047_ISO8859 ()
70 ACE_IBM1047_ISO8859::~ACE_IBM1047_ISO8859 ()
74 ACE_CDR::ULong
75 ACE_IBM1047_ISO8859::ncs ()
77 return 0x10020417;
80 ACE_CDR::ULong
81 ACE_IBM1047_ISO8859::tcs ()
83 return 0x00010001;
86 ACE_CDR::Boolean
87 ACE_IBM1047_ISO8859::read_char (ACE_InputCDR &in,
88 ACE_CDR::Char &x)
90 if (this->read_1 (in, reinterpret_cast<ACE_CDR::Octet*> (&x)))
92 x = to_IBM1047[x];
93 return 1;
95 return 0;
98 ACE_CDR::Boolean
99 ACE_IBM1047_ISO8859::read_string (ACE_InputCDR& in,
100 ACE_CDR::Char *& x)
102 ACE_CDR::ULong len;
104 in.read_ulong (len);
106 if (len > 0)
108 ACE_NEW_RETURN (x,
109 ACE_CDR::Char[len],
112 if (this->read_char_array (in, x, len))
113 return 1;
115 delete [] x;
118 x = 0;
119 return 0;
122 ACE_CDR::Boolean
123 ACE_IBM1047_ISO8859::read_string (ACE_InputCDR& in,
124 std::string & x)
126 ACE_CDR::ULong len;
128 in.read_ulong (len);
130 if (len > 0)
134 x.resize (len);
136 catch (const std::bad_alloc&)
138 return false;
141 if (this->read_char_array (in, &x[0], len))
143 x.resize (len-1); // drop terminating '\0' read from stream
144 return true;
147 delete [] x;
150 x.clear ();
151 return false;
154 ACE_CDR::Boolean
155 ACE_IBM1047_ISO8859::read_char_array (ACE_InputCDR& in,
156 ACE_CDR::Char* x,
157 ACE_CDR::ULong len)
159 if (this->read_array (in,
161 ACE_CDR::OCTET_SIZE,
162 ACE_CDR::OCTET_ALIGN,
163 len))
165 for (ACE_CDR::ULong i = 0; i != len; ++i)
166 x[i] = to_IBM1047[x[i]];
168 return 1;
171 return 0;
174 ACE_CDR::Boolean
175 ACE_IBM1047_ISO8859::write_char (ACE_OutputCDR& out,
176 ACE_CDR::Char x)
178 return
179 this->write_1 (out,
180 reinterpret_cast<const ACE_CDR::Octet*> (&from_IBM1047[x]));
183 ACE_CDR::Boolean
184 ACE_IBM1047_ISO8859::write_string (ACE_OutputCDR& out,
185 ACE_CDR::ULong len,
186 const ACE_CDR::Char* x)
188 if (out.write_ulong (len + 1))
189 return this->write_char_array (out, x, len + 1);
190 return 0;
193 ACE_CDR::Boolean
194 ACE_IBM1047_ISO8859::write_char_array (ACE_OutputCDR& out,
195 const ACE_CDR::Char* x,
196 ACE_CDR::ULong len)
198 char *buf = 0;
199 if (this->adjust (out, len, 1, buf) == 0)
201 ACE_OS::memcpy (buf, x, len);
203 for (ACE_CDR::ULong i = 0; i != len; ++i)
204 buf[i] = from_IBM1047[buf[i]];
206 return 1;
209 this->good_bit(out, 0);
210 return 0;
213 // ****************************************************************
215 ACE_ISO8859_IBM1047::ACE_ISO8859_IBM1047 ()
219 ACE_ISO8859_IBM1047::~ACE_ISO8859_IBM1047 ()
223 ACE_CDR::ULong
224 ACE_ISO8859_IBM1047::ncs ()
226 return 0x00010001;
229 ACE_CDR::ULong
230 ACE_ISO8859_IBM1047::tcs ()
232 return 0x10020417;
235 ACE_CDR::Boolean
236 ACE_ISO8859_IBM1047::read_char (ACE_InputCDR& in,
237 ACE_CDR::Char& x)
239 if (this->read_1 (in, reinterpret_cast<ACE_CDR::Octet*> (&x)))
241 x = from_IBM1047[x];
242 return 1;
244 return 0;
247 ACE_CDR::Boolean
248 ACE_ISO8859_IBM1047::read_string (ACE_InputCDR &in,
249 ACE_CDR::Char *&x)
251 ACE_CDR::ULong len;
253 in.read_ulong (len);
255 if (len > 0)
257 ACE_NEW_RETURN (x,
258 ACE_CDR::Char[len],
261 if (this->read_char_array (in, x, len))
262 return 1;
264 delete [] x;
267 x = 0;
268 return 0;
271 ACE_CDR::Boolean
272 ACE_ISO8859_IBM1047::read_string (ACE_InputCDR& in,
273 std::string & x)
275 ACE_CDR::ULong len;
277 in.read_ulong (len);
279 if (len > 0)
283 x.resize (len);
285 catch (const std::bad_alloc&)
287 return false;
290 if (this->read_char_array (in, &x[0], len))
292 x.resize (len-1); // drop terminating '\0' read from stream
293 return true;
296 delete [] x;
299 x.clear ();
300 return false;
303 ACE_CDR::Boolean
304 ACE_ISO8859_IBM1047::read_char_array (ACE_InputCDR &in,
305 ACE_CDR::Char *x,
306 ACE_CDR::ULong len)
308 if (this->read_array (in,
310 ACE_CDR::OCTET_SIZE,
311 ACE_CDR::OCTET_ALIGN,
312 len))
314 for (ACE_CDR::ULong i = 0; i != len; ++i)
315 x[i] = from_IBM1047[x[i]];
317 return 1;
320 return 0;
323 ACE_CDR::Boolean
324 ACE_ISO8859_IBM1047::write_char (ACE_OutputCDR &out,
325 ACE_CDR::Char x)
327 return
328 this->write_1 (out,
329 reinterpret_cast<const ACE_CDR::Octet *> (&to_IBM1047[x]));
332 ACE_CDR::Boolean
333 ACE_ISO8859_IBM1047::write_string (ACE_OutputCDR& out,
334 ACE_CDR::ULong len,
335 const ACE_CDR::Char* x)
337 if (out.write_ulong (len + 1))
338 return this->write_char_array (out, x, len + 1);
339 else
340 return 0;
343 ACE_CDR::Boolean
344 ACE_ISO8859_IBM1047::write_char_array (ACE_OutputCDR &out,
345 const ACE_CDR::Char *x,
346 ACE_CDR::ULong len)
348 char *buf = 0;
350 if (this->adjust (out, len, 1, buf) == 0)
352 ACE_OS::memcpy (buf, x, len);
354 for (ACE_CDR::ULong i = 0; i != len; ++i)
355 buf[i] = to_IBM1047[buf[i]];
357 return 1;
360 this->good_bit (out, 0);
361 return 0;
364 ACE_END_VERSIONED_NAMESPACE_DECL
366 #endif /* ACE_HAS_EBCDIC */