Codeset_Registry.cpp

Go to the documentation of this file.
00001 //=============================================================================
00002 /**
00003  *  @file   Codeset_Registry.cpp
00004  *
00005  *  $Id: Codeset_Registry.cpp 80826 2008-03-04 14:51:23Z wotte $
00006  *
00007  *  emulated codset regstry functions
00008  *
00009  *
00010  *  @author Phil Mesnier <mesnier_p@ociweb.com>
00011  */
00012 //=============================================================================
00013 
00014 #include "ace/Codeset_Registry.h"
00015 #include "ace/OS_Memory.h"
00016 #include "ace/OS_NS_string.h"
00017 
00018 // $Id: Codeset_Registry.cpp 80826 2008-03-04 14:51:23Z wotte $
00019 
00020 #if !defined (__ACE_INLINE__)
00021 #include "ace/Codeset_Registry.inl"
00022 #endif /* __ACE_INLINE__ */
00023 
00024 ACE_RCSID (ace,
00025            Codeset_Registry,
00026            "$Id: Codeset_Registry.cpp 80826 2008-03-04 14:51:23Z wotte $")
00027 
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029 
00030 int
00031 ACE_Codeset_Registry::locale_to_registry_i (const ACE_CString &locale,
00032                                             ACE_CDR::ULong &codeset_id,
00033                                             ACE_CDR::UShort *num_sets,
00034                                             ACE_CDR::UShort **char_sets)
00035 {
00036   registry_entry const *element = 0;
00037   for (size_t i = 0; element == 0 && i < num_registry_entries_; i++)
00038     if (ACE_OS::strcmp (registry_db_[i].loc_name_, locale.c_str ()) == 0)
00039       element = &registry_db_[i];
00040   if (element == 0)
00041     return 0;
00042   codeset_id = element->codeset_id_;
00043   if (num_sets != 0)
00044     *num_sets = element->num_sets_;
00045   if (char_sets != 0)
00046     {
00047       ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0);
00048       ACE_OS::memcpy (*char_sets, element->char_sets_,
00049                       element->num_sets_ * sizeof (ACE_CDR::UShort));
00050     }
00051   return 1;
00052 }
00053 
00054 int
00055 ACE_Codeset_Registry::registry_to_locale_i (ACE_CDR::ULong codeset_id,
00056                                             ACE_CString &locale,
00057                                             ACE_CDR::UShort *num_sets,
00058                                             ACE_CDR::UShort **char_sets)
00059 {
00060   registry_entry const *element = 0;
00061   for (size_t i = 0; element == 0 && i < num_registry_entries_; i++)
00062     if (codeset_id == registry_db_[i].codeset_id_)
00063       element = &registry_db_[i];
00064   if (element == 0)
00065     return 0;
00066   locale.set (element->loc_name_);
00067   if (num_sets != 0)
00068     *num_sets = element->num_sets_;
00069   if (char_sets != 0)
00070     {
00071       ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0);
00072       ACE_OS::memcpy (*char_sets, element->char_sets_,
00073                       element->num_sets_ * sizeof (ACE_CDR::UShort));
00074     }
00075   return 1;
00076 }
00077 
00078 int
00079 ACE_Codeset_Registry::is_compatible_i (ACE_CDR::ULong codeset_id,
00080                                        ACE_CDR::ULong other)
00081 {
00082   registry_entry const *lhs = 0;
00083   registry_entry const *rhs = 0;
00084   for (size_t i = 0; (lhs == 0 || rhs == 0) && i < num_registry_entries_; i++)
00085     {
00086       if (codeset_id == registry_db_[i].codeset_id_)
00087         lhs = &registry_db_[i];
00088       if (other == registry_db_[i].codeset_id_)
00089         rhs = &registry_db_[i];
00090     }
00091 
00092   if (lhs == 0 || rhs == 0)
00093     return 0;
00094 
00095   for (ACE_CDR::UShort l = 0; l < lhs->num_sets_; l++)
00096     for (ACE_CDR::UShort r = 0; r < rhs->num_sets_; r++)
00097       if (rhs->char_sets_[r] == lhs->char_sets_[l])
00098         return 1;
00099   return 0;
00100 }
00101 
00102 ACE_CDR::Short
00103 ACE_Codeset_Registry::get_max_bytes_i (ACE_CDR::ULong codeset_id)
00104 {
00105   for (size_t i = 0; i < num_registry_entries_; i++)
00106     if (codeset_id == registry_db_[i].codeset_id_)
00107       return registry_db_[i].max_bytes_;
00108   return 0;
00109 }
00110 
00111 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:38 2010 for ACE by  doxygen 1.4.7