Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Codeset_Registry.cpp
blob7ae55118d9e052498d24278a875bd0004d5a54a7
1 //=============================================================================
2 /**
3 * @file Codeset_Registry.cpp
5 * emulated codset regstry functions
7 * @author Phil Mesnier <mesnier_p@ociweb.com>
8 */
9 //=============================================================================
11 #include "ace/Codeset_Registry.h"
12 #include "ace/OS_Memory.h"
13 #include "ace/OS_NS_string.h"
15 #if !defined (__ACE_INLINE__)
16 #include "ace/Codeset_Registry.inl"
17 #endif /* __ACE_INLINE__ */
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
21 int
22 ACE_Codeset_Registry::locale_to_registry_i (const ACE_CString &locale,
23 ACE_CDR::ULong &codeset_id,
24 ACE_CDR::UShort *num_sets,
25 ACE_CDR::UShort **char_sets)
27 registry_entry const *element = 0;
28 for (size_t i = 0; element == 0 && i < num_registry_entries_; i++)
29 if (ACE_OS::strcmp (registry_db_[i].loc_name_, locale.c_str ()) == 0)
30 element = &registry_db_[i];
31 if (element == 0)
32 return 0;
33 codeset_id = element->codeset_id_;
34 if (num_sets != 0)
35 *num_sets = element->num_sets_;
36 if (char_sets != 0)
38 #if defined (ACE_HAS_ALLOC_HOOKS)
39 ACE_ALLOCATOR_RETURN (*char_sets,static_cast<ACE_CDR::UShort*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::UShort) * (element->num_sets_))),0);
40 #else
41 ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0);
42 #endif /* ACE_HAS_ALLOC_HOOKS */
43 ACE_OS::memcpy (*char_sets, element->char_sets_,
44 element->num_sets_ * sizeof (ACE_CDR::UShort));
46 return 1;
49 int
50 ACE_Codeset_Registry::registry_to_locale_i (ACE_CDR::ULong codeset_id,
51 ACE_CString &locale,
52 ACE_CDR::UShort *num_sets,
53 ACE_CDR::UShort **char_sets)
55 registry_entry const *element = 0;
56 for (size_t i = 0; element == 0 && i < num_registry_entries_; i++)
57 if (codeset_id == registry_db_[i].codeset_id_)
58 element = &registry_db_[i];
59 if (element == 0)
60 return 0;
61 locale.set (element->loc_name_);
62 if (num_sets != 0)
63 *num_sets = element->num_sets_;
64 if (char_sets != 0)
66 #if defined (ACE_HAS_ALLOC_HOOKS)
67 ACE_ALLOCATOR_RETURN (*char_sets,static_cast<ACE_CDR::UShort*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::UShort) * (element->num_sets_))),0);
68 #else
69 ACE_NEW_RETURN (*char_sets,ACE_CDR::UShort[element->num_sets_],0);
70 #endif /* ACE_HAS_ALLOC_HOOKS */
71 ACE_OS::memcpy (*char_sets, element->char_sets_,
72 element->num_sets_ * sizeof (ACE_CDR::UShort));
74 return 1;
77 int
78 ACE_Codeset_Registry::is_compatible_i (ACE_CDR::ULong codeset_id,
79 ACE_CDR::ULong other)
81 registry_entry const *lhs = 0;
82 registry_entry const *rhs = 0;
83 for (size_t i = 0; (lhs == 0 || rhs == 0) && i < num_registry_entries_; i++)
85 if (codeset_id == registry_db_[i].codeset_id_)
86 lhs = &registry_db_[i];
87 if (other == registry_db_[i].codeset_id_)
88 rhs = &registry_db_[i];
91 if (lhs == 0 || rhs == 0)
92 return 0;
94 for (ACE_CDR::UShort l = 0; l < lhs->num_sets_; l++)
95 for (ACE_CDR::UShort r = 0; r < rhs->num_sets_; r++)
96 if (rhs->char_sets_[r] == lhs->char_sets_[l])
97 return 1;
98 return 0;
101 ACE_CDR::Short
102 ACE_Codeset_Registry::get_max_bytes_i (ACE_CDR::ULong codeset_id)
104 for (size_t i = 0; i < num_registry_entries_; i++)
105 if (codeset_id == registry_db_[i].codeset_id_)
106 return registry_db_[i].max_bytes_;
107 return 0;
110 ACE_END_VERSIONED_NAMESPACE_DECL