Codeset_Registry.cpp

Go to the documentation of this file.
00001 //=============================================================================
00002 /**
00003  *  @file   Codeset_Registry.cpp
00004  *
00005  *  Codeset_Registry.cpp,v 1.5 2005/10/26 19:34:31 ossama Exp
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 // Codeset_Registry.cpp,v 1.5 2005/10/26 19:34:31 ossama Exp
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            "Codeset_Registry.cpp,v 1.5 2005/10/26 19:34:31 ossama Exp")
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,
00049                       element->char_sets_,
00050                       element->num_sets_ * sizeof (ACE_CDR::UShort));
00051     }
00052   return 1;
00053 }
00054 
00055 int
00056 ACE_Codeset_Registry::registry_to_locale_i (ACE_CDR::ULong codeset_id,
00057                                             ACE_CString &locale,
00058                                             ACE_CDR::UShort *num_sets,
00059                                             ACE_CDR::UShort **char_sets)
00060 {
00061   registry_entry const * element = 0;
00062   for (size_t i = 0; element == 0 && i < num_registry_entries_; i++)
00063     if (codeset_id == registry_db_[i].codeset_id_)
00064       element = &registry_db_[i];
00065   if (element == 0)
00066     return 0;
00067   locale.set(element->loc_name_);
00068   if (num_sets != 0)
00069     *num_sets = element->num_sets_;
00070   if (char_sets != 0)
00071     {
00072       ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0);
00073       ACE_OS::memcpy (*char_sets,
00074                       element->char_sets_,
00075                       element->num_sets_ * sizeof (ACE_CDR::UShort));
00076     }
00077   return 1;
00078 }
00079 
00080 int
00081 ACE_Codeset_Registry::is_compatible_i (ACE_CDR::ULong codeset_id,
00082                                        ACE_CDR::ULong other)
00083 {
00084   registry_entry const * lhs = 0;
00085   registry_entry const * rhs = 0;
00086   for (size_t i = 0; (lhs == 0 || rhs == 0) && i < num_registry_entries_; i++)
00087     {
00088       if (codeset_id == registry_db_[i].codeset_id_)
00089         lhs = &registry_db_[i];
00090       if (other == registry_db_[i].codeset_id_)
00091         rhs = &registry_db_[i];
00092     }
00093 
00094   if (lhs == 0 || rhs == 0)
00095     return 0;
00096 
00097   for (ACE_CDR::UShort l = 0; l < lhs->num_sets_; l++)
00098     for (ACE_CDR::UShort r = 0; r < rhs->num_sets_; r++)
00099       if (rhs->char_sets_[r] == lhs->char_sets_[l])
00100         return 1;
00101   return 0;
00102 }
00103 
00104 ACE_CDR::Short
00105 ACE_Codeset_Registry::get_max_bytes_i (ACE_CDR::ULong codeset_id)
00106 {
00107   for (size_t i = 0; i < num_registry_entries_; i++)
00108     if (codeset_id == registry_db_[i].codeset_id_)
00109       return registry_db_[i].max_bytes_;
00110   return 0;
00111 }
00112 
00113 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:48 2006 for ACE by doxygen 1.3.6