diff options
author | Phil Mesnier <mesnier_p@ociweb.com> | 2003-03-04 22:51:36 +0000 |
---|---|---|
committer | Phil Mesnier <mesnier_p@ociweb.com> | 2003-03-04 22:51:36 +0000 |
commit | 309fde57df95fde3644e8e4257464e92ab34c032 (patch) | |
tree | ab7b0e8ae2d638651e66fdd1d01da64b27bd2e40 | |
parent | b31cf7c1f6093acbf7a4bc53a2269a644bc9650b (diff) | |
download | ATCD-309fde57df95fde3644e8e4257464e92ab34c032.tar.gz |
ChangeLog tag: Tue Mar 4 13:54:52 2003 Phil Mesnier <mesnier_p@ociweb.com>
-rw-r--r-- | ace/Codeset_Registry.cpp | 106 | ||||
-rw-r--r-- | ace/Codeset_Registry.h | 101 | ||||
-rw-r--r-- | ace/Codeset_Registry.inl | 98 | ||||
-rw-r--r-- | ace/Codeset_Registry_db.cpp | 23 |
4 files changed, 328 insertions, 0 deletions
diff --git a/ace/Codeset_Registry.cpp b/ace/Codeset_Registry.cpp new file mode 100644 index 00000000000..780f388d6e7 --- /dev/null +++ b/ace/Codeset_Registry.cpp @@ -0,0 +1,106 @@ +//============================================================================= +/** + * @file Codeset_Registry.cpp + * + * $Id$ + * + * emulated codset regstry functions + * + * + * @author Phil Mesnier <mesnier_p@ociweb.com> + */ +//============================================================================= + +#include "ace/Codeset_Registry.h" + +// $Id$ + +#if !defined (__ACE_INLINE__) +#include "ace/Codeset_Registry.inl" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(ace, Codeset_Registry, "$Id$"); + + +ACE_CDR::Boolean +ACE_Codeset_Registry::locale_to_registry_i (const ACE_CString &locale, + ACE_CDR::ULong &codeset_id, + ACE_CDR::UShort *num_sets, + ACE_CDR::UShort **char_sets) +{ + registry_entry* element = 0; + for (size_t i = 0; element == 0 && i < num_registry_entries_; i++) + if (ACE_OS::strcmp(registry_db_[i].loc_name_,locale.c_str()) == 0) + element = ®istry_db_[i]; + if (element == 0) + return 0; + codeset_id = element->codeset_id_; + if (num_sets != 0) + *num_sets = element->num_sets_; + if (char_sets != 0) + { + ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0); + ACE_OS::memcpy (element->char_sets_, + *char_sets, + element->num_sets_ * sizeof (ACE_CDR::UShort)); + } + return 1; +} + +ACE_CDR::Boolean +ACE_Codeset_Registry::registry_to_locale_i (ACE_CDR::ULong codeset_id, + ACE_CString &locale, + ACE_CDR::UShort *num_sets, + ACE_CDR::UShort **char_sets) +{ + registry_entry* element = 0; + for (size_t i = 0; element == 0 && i < num_registry_entries_; i++) + if (codeset_id == registry_db_[i].codeset_id_) + element = ®istry_db_[i]; + if (element == 0) + return 0; + locale.set(element->loc_name_); + if (num_sets != 0) + *num_sets = element->num_sets_; + if (char_sets != 0) + { + ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0); + ACE_OS::memcpy (element->char_sets_, + *char_sets, + element->num_sets_ * sizeof (ACE_CDR::UShort)); + } + return 1; +} + +ACE_CDR::Boolean +ACE_Codeset_Registry::is_compatible_i (ACE_CDR::ULong codeset_id, + ACE_CDR::ULong other) +{ + registry_entry* lhs = 0; + registry_entry* rhs = 0; + for (size_t i = 0; (lhs == 0 || rhs == 0) && i < num_registry_entries_; i++) + { + if (codeset_id == registry_db_[i].codeset_id_) + lhs = ®istry_db_[i]; + if (other == registry_db_[i].codeset_id_) + rhs = ®istry_db_[i]; + } + + if (lhs == 0 || rhs == 0) + return 0; + + for (ACE_CDR::UShort l = 0; l < lhs->num_sets_; l++) + for (ACE_CDR::UShort r = 0; r < rhs->num_sets_; r++) + if (rhs->char_sets_[r] == lhs->char_sets_[l]) + return 1; + return 0; +} + +ACE_CDR::Short +ACE_Codeset_Registry::get_max_bytes_i (ACE_CDR::ULong codeset_id) +{ + for (size_t i = 0; i < num_registry_entries_; i++) + if (codeset_id == registry_db_[i].codeset_id_) + return registry_db_[i].max_bytes_; + return 0; +} diff --git a/ace/Codeset_Registry.h b/ace/Codeset_Registry.h new file mode 100644 index 00000000000..a54104d8af0 --- /dev/null +++ b/ace/Codeset_Registry.h @@ -0,0 +1,101 @@ +// -*- C++ -*- +//============================================================================= +/** + * @file Codeset_Registry.h + * + * $Id$ + * + * ACE wrapper around access functions for the OSF's DCE codeset registry + * access functions + * + * For environments that intrinsicly support the DCE defined access functions, + * the methods in this class are simply wrappers. On other platforms, emulation + * is provided. The motivation for this class is to support interoperability + * via translators and the CDR streams, primarily in TAO, but this capability + * is not restricted to CORBA. + * + * The emulated functionalty supports Open Group RFC #40, currently RFC 40.2, + * www.opengroup.org/tech/rfc/rfc40.2.html + * + * @author Phil Mesnier <mesnier_p@ociweb.com> + */ +//============================================================================= + +#ifndef ACE_CODESET_REGISTRY_H +#define ACE_CODESET_REGISTRY_H + +#include "ace/pre.h" +#include "ace/SString.h" +#include "ace/CDR_Base.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#if defined (ACE_HAS_DCE_CODESET_REGISTRY) +#include /**/ <dce/rpc.h> +#endif /* ACE_HAS_DCE_CODESET_REGISTRY */ + +class ACE_Export ACE_Codeset_Registry +{ +public: + + // based on a locale string, find the registry value and optional codeset + // collection. This wraps the dce_cs_loc_to_rgy function, or emulates it. + static ACE_CDR::Boolean locale_to_registry (const ACE_CString &locale, + ACE_CDR::ULong &codeset_id, + ACE_CDR::UShort * = 0, + ACE_CDR::UShort ** = 0); + + // based on a registry value, find the locale string and optional codeset + // collection. This wraps the dce_cs_rgy_to_loc function, or emulates it. + static ACE_CDR::Boolean registry_to_locale (ACE_CDR::ULong codeset_id, + ACE_CString &locale, + ACE_CDR::UShort * = 0, + ACE_CDR::UShort ** = 0); + + // tell if two codesets are compatible. This wraps the + //rpc_cs_char_set_compat_check function. + static ACE_CDR::Boolean is_compatible (ACE_CDR::ULong codeset_id, + ACE_CDR::ULong other); + + // return the max number of bytes required to represent a single character. + // This wraps the rpc_rgy_get_max_bytes function. + static ACE_CDR::Short get_max_bytes (ACE_CDR::ULong codeset_id); + + enum {max_charsets_ = 5}; +protected: + typedef struct { + const char * desc_; + const char * loc_name_; + ACE_CDR::ULong codeset_id_; + ACE_CDR::UShort num_sets_; + ACE_CDR::UShort char_sets_[max_charsets_]; + ACE_CDR::UShort max_bytes_; + } registry_entry; + +private: + static size_t num_registry_entries_; + static registry_entry registry_db_[]; + + static ACE_CDR::Boolean locale_to_registry_i (const ACE_CString &locale, + ACE_CDR::ULong &codeset_id, + ACE_CDR::UShort * = 0, + ACE_CDR::UShort ** = 0); + static ACE_CDR::Boolean registry_to_locale_i (ACE_CDR::ULong codeset_id, + ACE_CString &locale, + ACE_CDR::UShort * = 0, + ACE_CDR::UShort ** = 0); + static ACE_CDR::Boolean is_compatible_i (ACE_CDR::ULong codeset_id, + ACE_CDR::ULong other); + static ACE_CDR::Short get_max_bytes_i (ACE_CDR::ULong codeset_id); +}; + +#if defined (__ACE_INLINE__) +#include "ace/Codeset_Registry.inl" +#endif /* __ACE_INLINE__ */ + +#include "ace/post.h" +#endif /* ACE_CODESET_REGISTRY_H */ + + diff --git a/ace/Codeset_Registry.inl b/ace/Codeset_Registry.inl new file mode 100644 index 00000000000..dec0b97a08d --- /dev/null +++ b/ace/Codeset_Registry.inl @@ -0,0 +1,98 @@ +// -*- C++ -*- +//============================================================================= +/** + * @file Codeset_Registry.inl + * + * $Id$ + * + * ACE wrapper around access functions for the OSF's DCE codeset registry + * access functions - the inline functions either call the system supplied + * DCE based codeset regsitry function, or calls the emulation + * + * + * @author Phil Mesnier <mesnier_p@ociweb.com> + */ +//============================================================================= + +ACE_INLINE +ACE_CDR::Boolean +ACE_Codeset_Registry::locale_to_registry(const ACE_CString &locale, + ACE_CDR::ULong &codeset_id, + ACE_CDR::UShort *num_sets, + ACE_CDR::UShort **char_sets) +{ +#if defined (ACE_HAS_DCE_CODESET_REGISTRY) + error_status_t result; + dce_cs_loc_to_rgy (locale.c_str(), + &codeset_id, + num_sets, + char_sets, + &result); + return (result == dce_cs_c_ok) ? OK : UNKNOWN; +#else + return ACE_Codeset_Registry::locale_to_registry_i (locale, + codeset_id, + num_sets, + char_sets); +#endif /* ACE_HAS_DCE_CODESET_REGISTRY */ +} + +// based on a registry value, find the locale string and optional codeset +// collection. This wraps the dce_cs_rgy_to_loc function, or emulates it. +ACE_INLINE +ACE_CDR::Boolean +ACE_Codeset_Registry::registry_to_locale(ACE_CDR::ULong codeset_id, + ACE_CString &locale, + ACE_CDR::UShort *num_sets, + ACE_CDR::UShort **char_sets) +{ +#if defined (ACE_HAS_DCE_CODESET_REGISTRY) + error_status_t result; + char *buffer; + dce_cs_rgy_to_loc (codeset_id, + &buffer, + num_sets, + char_sets, + &result); + locale.set(buffer); // does a copy :-( + free (buffer); + return (result == dce_cs_c_ok) ? 1 : 0; +#else + return ACE_Codeset_Registry::registry_to_locale_i (codeset_id, + locale, + num_sets, + char_sets); +#endif /* ACE_HAS_DCE_CODESET_REGISTRY */ +} + +// tell if two codesets are compatible. This wraps the +//rpc_cs_char_set_compat_check function. +ACE_INLINE +ACE_CDR::Boolean +ACE_Codeset_Registry::is_compatible (ACE_CDR::ULong codeset_id, + ACE_CDR::ULong other) +{ +#if defined (ACE_HAS_DCE_CODESET_REGISTRY) + error_status_t result; + rpc_cs_char_set_compat_check(codeset_id,other,&result); + return (result == rpc_s_ok) ? 1 : 0; +#else + return ACE_Codeset_Registry::is_compatible_i (codeset_id,other); +#endif /* ACE_HAS_DCE_CODESET_REGISTRY */ +} + +// return the max number of bytes required to represent a single character. +// This wraps the rpc_rgy_get_max_bytes function. +ACE_INLINE +ACE_CDR::Short +ACE_Codeset_Registry::get_max_bytes (ACE_CDR::ULong codeset_id) +{ +#if defined (ACE_HAS_DCE_CODESET_REGISTRY) + error_status_t result; + short max_bytes; + rpc_rgy_get_max_bytes(codeset_id,&max_bytes,&result); + return (result == rpc_s_ok) ? (short)max_bytes : 0; +#else + return ACE_Codeset_Registry::get_max_bytes_i (codeset_id); +#endif /* ACE_HAS_DCE_CODESET_REGISTRY */ +} diff --git a/ace/Codeset_Registry_db.cpp b/ace/Codeset_Registry_db.cpp new file mode 100644 index 00000000000..239e7f1c792 --- /dev/null +++ b/ace/Codeset_Registry_db.cpp @@ -0,0 +1,23 @@ +/* $Id$ + * Codeset registry DB, generated Fri Feb 28 21:01:30 2003 + * source: code_set_registry1.2g.txt + * + * To populate the registry_db, construct a codeset registry text file based + * on the OSF's Character and Code Set Registry. See DCE RFC 40.1 for details + * on obtaining the full text for the current registry. Once you have composed + * a text file containing all the desired codeset information, build and run + * mkcsregdb. The source is in $ACE_ROOT/apps/mkcsregdb. It will generate a new + * copy of this file, with the registry_db_ array properly initialized. + */ + +#include "ace/Codeset_Registry.h" + +ACE_Codeset_Registry::registry_entry +ACE_Codeset_Registry::registry_db_[] = +{ + {"ISO 8859-1:1987; Latin Alphabet No. 1","ASCII",0x00010001,1,{0x0011},1}, + {"IBM-1047 (CCSID 01047); Latin-1 Open System","EBCDIC",0x10020417,1,{0x0011},1} +}; + +size_t ACE_Codeset_Registry::num_registry_entries_ = 2; + |